From 3f4814cf84cdc108752cfae45a0ad92c81e5fc3a Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Mon, 30 Mar 2026 14:15:06 -0400 Subject: [PATCH 1/2] Fix UTF-8 decode error in Inworld TTS streaming response Buffer raw bytes and only decode after splitting on newline boundaries, preventing multi-byte UTF-8 characters from being split at chunk edges. Fixes #3538 --- src/pipecat/services/inworld/tts.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pipecat/services/inworld/tts.py b/src/pipecat/services/inworld/tts.py index 157130442..215c0f747 100644 --- a/src/pipecat/services/inworld/tts.py +++ b/src/pipecat/services/inworld/tts.py @@ -387,16 +387,16 @@ class InworldHttpTTSService(TTSService): Yields: An asynchronous generator of frames. """ - buffer = "" + buffer = b"" # Track the duration of this utterance based on the last word's end time utterance_duration = 0.0 - async for chunk in response.content.iter_chunked(1024): - buffer += chunk.decode("utf-8") + async for chunk in response.content.iter_any(): + buffer += chunk - while "\n" in buffer: - line, buffer = buffer.split("\n", 1) - line_str = line.strip() + while b"\n" in buffer: + line, buffer = buffer.split(b"\n", 1) + line_str = line.decode("utf-8").strip() if not line_str: continue From 465b9bcbc6bd1cb7ac7f22b9efe29d8fe3b27948 Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Mon, 30 Mar 2026 14:16:21 -0400 Subject: [PATCH 2/2] Add changelog for #4202 --- changelog/4202.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/4202.fixed.md diff --git a/changelog/4202.fixed.md b/changelog/4202.fixed.md new file mode 100644 index 000000000..7540f453f --- /dev/null +++ b/changelog/4202.fixed.md @@ -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.