rapid-van-16677
10/30/2025, 2:50 PMtall-airline-16756
10/30/2025, 2:50 PMtall-airline-16756
10/30/2025, 2:51 PMrapid-van-16677
10/30/2025, 2:51 PMtall-airline-16756
10/30/2025, 2:53 PMAudioEmitter class, which is part of LiveKit's TTS (Text-to-Speech) pipeline. Here’s a simple example to guide you through:
Basic Implementation:
from livekit.agents import tts
from livekit.agents.utils import aio
# Create a channel for receiving synthesized audio
rx_channel = aio.Chan[tts.SynthesizedAudio]()
# Initialize AudioEmitter
emitter = tts.AudioEmitter(label="example", dst_ch=rx_channel)
emitter.initialize(
request_id="req-1",
sample_rate=1000,
num_channels=1,
mime_type="audio/pcm",
frame_size_ms=100,
stream=True, # Enable streaming mode
)
# Start a segment and push audio data
emitter.start_segment(segment_id="seg1")
emitter.push(pcm_chunk)
emitter.flush() # Creates non-final frame
emitter.push(pcm_chunk)
emitter.end_segment() # Creates final frame
Key Notes:
• When using streaming mode (stream=True), flush() helps create non-final frames to support real-time processing.
• Remember to always use start_segment() and end_segment() to properly manage your audio segments.
• If you call flush() multiple times without pushing new data in between, it won’t generate additional frames.
If anything is unclear or if you'd like me to walk you through more examples, just let me know—I’m here to help!
Sources: livekit-agents/livekit/agents/tts/fallback_adapter.py | Pipeline nodes and hooks | LiveKit Docs