[Audio] default [-66.00 dBFS] [##-----------------...
# ask-ai
r
[Audio] default [-66.00 dBFS] [##----------------------------]2025-10-30 201636 - DEBUG - flush audio emitter due to slow audio generation 2025-10-30 201636,749 - DEBUG livekit.agents - flush audio emitter due to slow audio generation [Audio] default [-57.05 dBFS] [######------------------------]2025-10-30 201637 - DEBUG - flush audio emitter due to slow audio generation 2025-10-30 201637,146 - DEBUG livekit.agents - flush audio emitter due to slow audio generation [Audio] default [-57.85 dBFS] [#####-------------------------]2025-10-30 201638 - INFO - Collection opening initiated 2025-10-30 201638,845 - INFO root - Collection opening initiated [Audio] default [-53.08 dBFS] [#######-----------------------]2025-10-30 201732 - DEBUG - flush audio emitter due to slow audio generation 2025-10-30 201732,685 - DEBUG livekit.agents - flush audio emitter due to slow audio generation [Audio] default [-50.74 dBFS] [########----------------------]2025-10-30 201845 - DEBUG - flush audio emitter due to slow audio generation 2025-10-30 201845,651 - DEBUG livekit.agents - flush audio emitter due to slow audio generation [Audio] default [-39.75 dBFS] [#############-----------------] what is the this debug means?
t
Thanks for reaching out, Rahul. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thank you for reaching out with your question! The debug message "flush audio emitter due to slow audio generation" is a helpful indicator that the system noticed audio was being generated a bit slower than expected in real-time. To keep everything running smoothly and in sync, the system automatically flushes the audio buffer. This usually happens when there's a slight delay—just over 0.02 seconds—between the expected playback time and the actual audio generation. By flushing the audio emitter, the system prevents any lag in audio output, which is especially important for real-time communication or streaming text-to-speech scenarios. I hope this helps clarify things for you! If you have any more questions, feel free to ask—we’re here to help. Sources: livekit-agents/livekit/agents/voice/agent_session.py
r
how do I implement it give me example
t
To help you implement the audio emitter flush mechanism in LiveKit, you can use the
AudioEmitter
class, which is part of LiveKit's TTS (Text-to-Speech) pipeline. Here’s a simple example to guide you through: Basic Implementation:
Copy code
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