Merge pull request #4202 from pipecat-ai/mb/fix-inworld-tts-streaming-utf8
Fix UTF-8 decode error in Inworld TTS streaming response
This commit is contained in:
1
changelog/4202.fixed.md
Normal file
1
changelog/4202.fixed.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
- Fixed `InworldHttpTTSService` streaming responses crashing with `UnicodeDecodeError` when multi-byte UTF-8 characters were split across chunk boundaries. This caused TTS audio to cut off mid-sentence intermittently.
|
||||||
@@ -387,16 +387,16 @@ class InworldHttpTTSService(TTSService):
|
|||||||
Yields:
|
Yields:
|
||||||
An asynchronous generator of frames.
|
An asynchronous generator of frames.
|
||||||
"""
|
"""
|
||||||
buffer = ""
|
buffer = b""
|
||||||
# Track the duration of this utterance based on the last word's end time
|
# Track the duration of this utterance based on the last word's end time
|
||||||
utterance_duration = 0.0
|
utterance_duration = 0.0
|
||||||
|
|
||||||
async for chunk in response.content.iter_chunked(1024):
|
async for chunk in response.content.iter_any():
|
||||||
buffer += chunk.decode("utf-8")
|
buffer += chunk
|
||||||
|
|
||||||
while "\n" in buffer:
|
while b"\n" in buffer:
|
||||||
line, buffer = buffer.split("\n", 1)
|
line, buffer = buffer.split(b"\n", 1)
|
||||||
line_str = line.strip()
|
line_str = line.decode("utf-8").strip()
|
||||||
|
|
||||||
if not line_str:
|
if not line_str:
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user