audio_context_manager
Audio contexts a TTS service plays one after another.
- class pipecat.utils.context.audio_context_manager.AudioContextFrame(context_id: str)[source]
Bases:
FrameMarks where an audio context plays among the queued frames.
- Parameters:
context_id – The audio context to play.
- class pipecat.utils.context.audio_context_manager.AudioContextManager[source]
Bases:
objectAudio contexts and frames, played in the order they are queued.
Each audio context has its own queue of items (audio, other frames, word timestamps), so a context’s audio can arrive while an earlier one is still playing.
next_for_playback()returns the next context or frame to play, andget()returns a context’s items until the context ends.playing_context_idis the contextnext_for_playback()returned last. The caller sets it back toNonewhen that context stops playing.- available(context_id: str) bool[source]
Whether an audio context exists and hasn’t finished playing.
- Parameters:
context_id – The audio context to check.
- async create(context_id: str, *, interruptible: bool = True)[source]
Create an audio context and queue it to play after what’s already queued.
- Parameters:
context_id – The audio context to create.
interruptible – Whether
reset()drops the context while it waits to play.
- async append(context_id: str, item: Any)[source]
Append an item to an audio context.
Noneends the context.Audio is trimmed to whole samples, and a split sample is carried to the context’s next audio frame. Providers may cut their PCM stream at any byte, but consumers read audio frame by frame.
- Parameters:
context_id – The audio context to append to. It must exist.
item – The item to append, or
Noneto end the context.
- keepalive(context_id: str)[source]
Restart the wait of
get()for an audio context, if it exists.- Parameters:
context_id – The audio context still in use.
- async put_frame(frame: Frame)[source]
Queue a frame to play after what’s already queued.
- Parameters:
frame – The frame to queue.
- async next_for_playback() Frame | None[source]
Wait for the next audio context or frame to play.
Contexts removed before they play are skipped.
- Returns:
An
AudioContextFrame, whose context becomes the playing one, another queued frame, orNonewhen playback ends.
- async get(context_id: str, timeout: float) Any[source]
Return an audio context’s next item, waiting up to
timeoutfor it.A keepalive restarts the wait and is not returned.
- Parameters:
context_id – The audio context to read.
timeout – Seconds to wait for an item.
- Returns:
The next item, or
Nonewhen the context ends.- Raises:
TimeoutError – If no item arrives in time.