#!/usr/bin/env python3 import sys, json, base64 def main(): """ Read SSE from stdin, extract base64 PCM16 frames, write raw bytes to stdout. Use with curl, then pipe to ffplay: curl -G --data-urlencode 'text=Hello' 'http://localhost:8000/v1/tts.sse' \\ | python3 clients/py_play_ffplay.py \\ | ffplay -nodisp -autoexit -f s16le -ar 24000 -ac 1 - """ for line in sys.stdin: line = line.rstrip("\n") if line.startswith("data: "): try: obj = json.loads(line[6:]) b = base64.b64decode(obj["pcm16"]) sys.stdout.buffer.write(b) sys.stdout.flush() except Exception: pass if __name__ == "__main__": main()