Skip to content

fix(smallwebrtc): respect audio_out_10ms_chunks parameter in RawAudioTrack#3645

Closed
jamsea wants to merge 6 commits intomainfrom
fix/smallwebrtc-audio-chunk-size
Closed

fix(smallwebrtc): respect audio_out_10ms_chunks parameter in RawAudioTrack#3645
jamsea wants to merge 6 commits intomainfrom
fix/smallwebrtc-audio-chunk-size

Conversation

@jamsea
Copy link
Copy Markdown
Contributor

@jamsea jamsea commented Feb 5, 2026

Summary

Fixed an issue where SmallWebRTCTransport was not respecting the audio_out_10ms_chunks parameter from TransportParams. The RawAudioTrack class was hardcoded to always produce 10ms audio frames, causing firmware clients to receive incorrect chunk sizes (e.g., receiving 20ms chunks when 40ms was configured).

Problem

When using SmallWebRTCTransport on Pipecat Cloud with audio_out_10ms_chunks=4 (40ms), firmware clients were still receiving 20ms audio chunks. This happened because:

  1. The base transport correctly chunked audio into 40ms pieces based on audio_out_10ms_chunks
  2. However, RawAudioTrack in SmallWebRTC was re-chunking the audio back to 10ms for WebRTC transmission
  3. The recv() method always produced 10ms frames regardless of configuration

Solution

Updated RawAudioTrack to accept and respect a configurable chunk size:

  • Added num_10ms_chunks parameter to RawAudioTrack constructor (default 1 for backward compatibility)
  • Updated add_audio_bytes() to validate and chunk audio using the configured chunk size
  • Updated recv() to produce audio frames of the configured size and advance timestamps correctly
  • Modified _handle_client_connected() to pass audio_out_10ms_chunks from TransportParams when creating the track

Testing

  • Verified that setting audio_out_10ms_chunks=4 now correctly produces 40ms audio frames over WebRTC
  • Backward compatible: default behavior (10ms chunks) remains unchanged when parameter is not specified

…Track

The RawAudioTrack class was hardcoded to always produce 10ms audio frames
regardless of the audio_out_10ms_chunks transport parameter. This caused
firmware clients to receive 20ms chunks even when 40ms was configured.

Changes:
- Add num_10ms_chunks parameter to RawAudioTrack constructor
- Update add_audio_bytes to chunk audio based on configured size
- Update recv() to produce frames of the configured size
- Pass audio_out_10ms_chunks from TransportParams when creating track
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 5, 2026

Codecov Report

❌ Patch coverage is 0% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pipecat/transports/smallwebrtc/transport.py 0.00% 14 Missing ⚠️
Files with missing lines Coverage Δ
src/pipecat/transports/smallwebrtc/transport.py 3.43% <0.00%> (+3.43%) ⬆️

... and 1 file with indirect coverage changes

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where SmallWebRTCTransport was ignoring the audio_out_10ms_chunks parameter from TransportParams, always producing 10ms audio frames instead of respecting the configured chunk size (e.g., 40ms for audio_out_10ms_chunks=4).

Changes:

  • Added num_10ms_chunks parameter to RawAudioTrack class with proper calculation of chunk sizes
  • Updated validation and frame generation logic to respect configurable chunk sizes
  • Modified track instantiation to pass through the configured parameter from TransportParams

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/pipecat/transports/smallwebrtc/transport.py Modified RawAudioTrack to accept and respect num_10ms_chunks parameter, updating initialization, validation, and frame generation logic to support configurable audio chunk sizes
changelog/3645.fixed.md Added changelog entry documenting the fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Ensure num_10ms_chunks is a positive integer to prevent division by zero
or invalid audio chunk sizes. Raises ValueError if value is less than 1.
@markbackman markbackman requested a review from filipi87 February 5, 2026 02:24
@markbackman
Copy link
Copy Markdown
Contributor

Requesting that @filipi87 take a look at this one when he has a moment.

… guard)

Migrate from pytest-style to unittest.IsolatedAsyncioTestCase to match the
pattern used by other transport tests (e.g. test_livekit_transport.py). Guard
the aiortc/av import with try/except and skipUnless so tests gracefully skip
when webrtc dependencies aren't installed. Add pyright suppressions for false
positives inherent to testing internals of optional-dependency classes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jamsea
Copy link
Copy Markdown
Contributor Author

jamsea commented Feb 5, 2026

@filipi87 I went through line by line and this all looks right to me, however my SmallWebRTC Vibe isn't strong enough to 100% confirm 🙏

Copy link
Copy Markdown
Contributor

@filipi87 filipi87 left a comment

Choose a reason for hiding this comment

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

The audio_out_10ms_chunks is used inside BaseOutputTransport to chunk the audio we receive from the TTS, store it in a queue, and optionally mix it with other audio, and then send it to the appropriate transport (Daily, SmallWebRTC, WebSocket ....).

As far as I remember, creating 40 ms chunks improved CPU usage inside Pipecat. But I am not sure that when we implemented this, we intended for transports to preserve that chunk size when actually sending audio to WebRTC. I don’t think that was the original intention.

For example, in Daily we always send 10 ms of audio, regardless of what is passed to DailyTransport.

And the reason is, WebRTC works best when sending 10–20 ms audio frames to keep latency low:

  • 10 ms: ultra low latency
  • 20 ms: low latency

This is why we implemented the same logic in SmallWebRTC.

My final concern is that if we send 40 ms frames to WebRTC, this will impact latency. So, If we want to support that behavior, we should introduce a new property to explicitly control it.

cc: @aconchillo for thoughts on this, who implemented similar logic inside Daily.

@filipi87 filipi87 requested a review from aconchillo February 6, 2026 13:40
@jamsea jamsea closed this Feb 13, 2026
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.

4 participants