Skip to content

Add a pcm_to_wav helper and use it across core - #5326

Merged
markbackman merged 4 commits into
mainfrom
mb/pcm-to-wav
Aug 14, 2026
Merged

markbackman merged 4 commits into
mainfrom
mb/pcm-to-wav

Conversation

@markbackman

@markbackman markbackman commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds pcm_to_wav() to pipecat.audio.utils, which wraps raw 16-bit PCM in a WAV container and returns the file as bytes.
  • It accepts bytes, bytearray, or memoryview, because audio reaches it as a bytearray in practice — SegmentedSTTService accumulates one, and AudioBufferProcessor hands one to its turn-audio events.
  • It drops trailing bytes that don't complete a frame. wave writes those into the data chunk without counting them in the header, which leaves readers disagreeing about the length and swaps channels on a stereo stream truncated mid-frame.
  • Replaces the hand-rolled wave boilerplate in the three websocket transports, SegmentedSTTService, LLMContext.create_audio_message(), and the two eval helpers. That removes ~55 lines and drops the io/wave imports from five modules.

Two WAV-writing spots stay as they are: local_smart_turn_v3.py (debug-only path, writes from a numpy array) and audio/dtmf/utils.py (a WAV read, not a write).

The conversions have no user-visible effect — the helper emits the same bytes as the code it replaces. The helper commit is cherry-picked from #5285.

Testing

  • uv run pytest tests/test_audio_utils.py covers mono, stereo, empty, bytearray input, and a partial trailing frame.
  • Byte-identical output confirmed against the replaced inline code across mono, stereo, empty, and unaligned-length inputs.
  • Full suite: 4228 passing. The four test_krisp_viva_* failures are order-dependent and fail at the branch point too.

jamsea and others added 4 commits August 14, 2026 09:00
Every example that persists or uploads audio from AudioBufferProcessor
hand-rolls the same wave.open block, including the pipecat init template.
Give it a home next to the other PCM helpers.
Buffers reach the helper as bytearray (segmented STT, AudioBufferProcessor turn
audio), and a caller that truncates PCM can leave a trailing partial frame,
which wave would write into the data chunk without counting in the header.
The websocket transports, segmented STT, audio context messages, and the eval
recorder each hand-rolled the same wave boilerplate.
@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.33333% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pipecat/evals/transport.py 33.33% 2 Missing ⚠️
src/pipecat/processors/aggregators/llm_context.py 33.33% 2 Missing ⚠️
src/pipecat/transports/websocket/client.py 0.00% 2 Missing ⚠️
src/pipecat/transports/websocket/fastapi.py 50.00% 1 Missing ⚠️
src/pipecat/transports/websocket/server.py 50.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/pipecat/audio/utils.py 77.57% <100.00%> (+3.37%) ⬆️
src/pipecat/evals/speech.py 75.37% <100.00%> (-0.72%) ⬇️
src/pipecat/services/stt_service.py 65.84% <100.00%> (-0.82%) ⬇️
src/pipecat/transports/websocket/fastapi.py 53.78% <50.00%> (+1.21%) ⬆️
src/pipecat/transports/websocket/server.py 82.32% <50.00%> (+2.17%) ⬆️
src/pipecat/evals/transport.py 55.35% <33.33%> (+1.59%) ⬆️
src/pipecat/processors/aggregators/llm_context.py 78.94% <33.33%> (+2.99%) ⬆️
src/pipecat/transports/websocket/client.py 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jamsea jamsea 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.

🎉

@filipi87 filipi87 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.

Nice clean up. 🚀

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.

3 participants