Spaces:
Sleeping
Sleeping
Create clients/py_play_ffplay.py
Browse files- clients/py_play_ffplay.py +24 -0
clients/py_play_ffplay.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import sys, json, base64
|
3 |
+
|
4 |
+
def main():
|
5 |
+
"""
|
6 |
+
Read SSE from stdin, extract base64 PCM16 frames, write raw bytes to stdout.
|
7 |
+
Use with curl, then pipe to ffplay:
|
8 |
+
curl -G --data-urlencode 'text=Hello' 'http://localhost:8000/v1/tts.sse' \\
|
9 |
+
| python3 clients/py_play_ffplay.py \\
|
10 |
+
| ffplay -nodisp -autoexit -f s16le -ar 24000 -ac 1 -
|
11 |
+
"""
|
12 |
+
for line in sys.stdin:
|
13 |
+
line = line.rstrip("\n")
|
14 |
+
if line.startswith("data: "):
|
15 |
+
try:
|
16 |
+
obj = json.loads(line[6:])
|
17 |
+
b = base64.b64decode(obj["pcm16"])
|
18 |
+
sys.stdout.buffer.write(b)
|
19 |
+
sys.stdout.flush()
|
20 |
+
except Exception:
|
21 |
+
pass
|
22 |
+
|
23 |
+
if __name__ == "__main__":
|
24 |
+
main()
|