Skip to content

Emit whole 16-bit samples from DeepgramHttpTTSService - #5989

Merged
markbackman merged 2 commits into
pipecat-ai:mainfrom
antonsoo:fix/deepgram-http-sample-alignment
Oct 1, 2026
Merged

markbackman merged 2 commits into
pipecat-ai:mainfrom
antonsoo:fix/deepgram-http-sample-alignment

Conversation

@antonsoo

Copy link
Copy Markdown
Contributor

Summary

DeepgramHttpTTSService turned each chunk read from the HTTP response straight into a TTSAudioRawFrame, but chunk boundaries don't have to fall between 16-bit samples, so a frame can end mid-sample (#3109 reported this: buffer size must be a multiple of element size). With metrics enabled, the TTFA scan reads the buffered audio as int16 and raises on the odd length inside _audio_context_task_handler. The task dies and the service produces no audio for that utterance or any later one.

Same issue as #5090 (xAI HTTP) and #4952 (Rime WebSocket).

Fix

Stream the response through TTSService._stream_audio_frames_from_iterator, as XAIHttpTTSService, RimeHttpTTSService and Piper already do. It holds back a dangling byte, so every emitted frame contains whole samples.

Testing

  • tests/test_deepgram_tts.py: a local server splits the PCM mid-sample. With metrics enabled, the test asserts that the frames are even-length and reassemble into the original PCM. On main it gets no audio frames at all.
  • A local server writing 1001-byte pieces, two utterances, metrics on. On main, neither utterance produces audio and the handler logs buffer size must be a multiple of element size. With this change, both arrive intact and TTFA is reported.

HTTP chunk boundaries can fall mid-sample. Stream the response through
_stream_audio_frames_from_iterator so every TTSAudioRawFrame holds whole
samples; a frame ending mid-sample made the TTFA scan raise and stopped
the service's audio for the rest of the session.

@markbackman markbackman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks! I'll look into a centralized fix for this problem, but this is safe, so approving.

@markbackman
markbackman merged commit 6396f97 into pipecat-ai:main Oct 1, 2026
5 checks passed
@codecov

codecov Bot commented Oct 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/pipecat/services/deepgram/tts.py 51.65% <100.00%> (+8.14%) ⬆️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants