Skip to content

Use a PyAV resampler per participant for input audio - #21

Open
dangusev wants to merge 2 commits into
mainfrom
fix/use-pyav-resampler
Open

dangusev wants to merge 2 commits into
mainfrom
fix/use-pyav-resampler

Conversation

@dangusev

Copy link
Copy Markdown
Collaborator
  • pipecat's soxr VHQ stream resampler held 10-76 ms of audio, which is too long.

  • Replaced it with av.AudioResampler. It holds 1 ms of audio and gives output for every packet.

  • UserAudioRawFrame.pts is the pts of the first sample in the frame.

  • Each participant now gets a separate resampler, so audio and pts of different participants do not mix.

  • The resampler of a participant is removed when their audio track is unsubscribed, because a new track restarts its pts.

- pipecat's soxr VHQ stream resampler held 10-76 ms of audio, which is too long.

- Replaced it with av.AudioResampler. It holds 1 ms of audio and gives output for every packet.
- UserAudioRawFrame.pts is the pts of the first sample in the frame.
- Each participant now gets a separate resampler, so audio and pts of different participants do not mix.
- The resampler of a participant is removed when their audio track is unsubscribed, because a new track restarts its pts.
- Resamplers are keyed by (user_id, session_id). A rejoined participant gets a new resampler, also when old audio arrives after the leave event. Two sessions of one user do not mix.
- Resamplers are removed when the participant leaves, not when an audio track is unsubscribed. Mute and the end of a screen share do not lose audio.
- getstream's FrameResampler skips empty chunks and rebuilds the resampler when the input format changes. Before, both stopped the audio input task.
- UserAudioRawFrame.pts is calculated exactly, without float truncation.
- Tests read an exact number of frames and do not wait for timeouts.
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.

1 participant