fix(sse): iterate async TTS generator from sync context without async io.run; return proper SSE chunks#35
Open
DanTulovsky wants to merge 5 commits into
Open
Conversation
…io.run; return proper SSE chunks
…-edge-tts) on 2025-08-12
…allow multiple pushes per day
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a fix for: #34
Full disclosure, fix provided by GPT5. It does seem to fix the error though. It said:
❯ curl -X POST http://localhost:5050/v1/audio/speech
-H "Content-Type: application/json"
-H "Authorization: Bearer your_api_key_here"
-d '{
"model": "tts-1",
"input": "This will stream as Server-Sent Events with JSON data containing base64-encoded audio chunks.",
"voice": "alloy",
"stream_format": "sse"
}'
data: {"type": "error", "error": "a coroutine was expected, got <async_generator object _generate_audio_stream at 0x2aaaae3a7450>"}
❯ curl -X POST http://localhost:5050/v1/audio/speech
-H "Content-Type: application/json"
-H "Authorization: Bearer your_api_key_here"
-d '{
"model": "tts-1",
"input": "This will stream as Server-Sent Events with JSON data containing base64-encoded audio chunks.",
"voice": "alloy",
"stream_format": "sse"
}'
data: {"type": "speech.audio.delta", "audio": "//NkxAAAAANIAAAAAExBTUVVVVUJUpHz0MCZbJZCAIWIDA8LoAIg6d3phCbs8RRfXd4Bi+xNCSwAL3N4hV3PrvEU65EHFuaRHOIUQnRETriz8OBmUT3fiImiITz6l/SgZvu7nER+I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