const { enabled: isMicOn, toggle: ...
# ask-ai
b
const { enabled: isMicOn, toggle: toggleMic, pending: isMicToggling, } = useTrackToggle({ source: Track.Source.Microphone, initialState: false }); Why does calling toggle while the agent is speaking cause the audio to stop?
t
Thanks for reaching out, RikuKomiya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I completely understand how important it is for your audio to play smoothly. When you call the
toggle
method while the agent is speaking, the audio stops because LiveKit's framework interprets this action as a signal that you might want to interrupt or change the ongoing interaction. By default, this causes the agent's current speech to pause to avoid overlapping sounds. If you'd prefer the playback to continue without interruptions, you can easily adjust this by setting options like
allow_interruptions=False
or by handling audio state changes thoughtfully within your application. I'm here to help if you'd like guidance on making these adjustments! Sources: Text and transcriptions | LiveKit Docs | Agent speech and audio | LiveKit Docs
b
By carefully handling changes in audio state within the application How do you do that?
t
Thanks for reaching out! Could you help me understand a bit more about what you'd like to happen when the audio state changes? For instance, are you hoping to avoid interruptions altogether, or would you prefer to manage toggling so it causes as little disruption as possible during active speech? I'm here to help you find the best solution!
b
toggleをagentが喋ってる間に切り替えると、音質が変わってかつmicが効かなくなる
t
I understand how frustrating it can be when the audio quality changes or microphone issues happen during agent speech. This usually occurs because LiveKit’s microphone management stops and restarts the audio input stream completely. When this happens, it interrupts important audio processes like echo cancellation, noise suppression, and auto gain control, which then need to be reset—leading to those unwanted delays and artifacts. To help smooth things out, a great approach is to use software-based muting by simply setting the audio volume to zero instead of toggling the microphone on and off. This way, the audio stream stays active, and the processing pipeline remains stable, which can really reduce those disruptions. Sources: VoiceAgent/App/AppViewModel.swift | components/livekit/agent-control-bar/hooks/use-agent-control-bar.ts | livekit-agents/livekit/agents/voice/chat_cli.py | stream_audio.py
b
agentからの音声が三回に一回くらい聞こえてこないが、speaking stateになっている問題について教えて
t
Sometimes, you might notice that the agent’s audio doesn’t play even though it shows as being in the "speaking" state. This can happen for a few reasons, and I’m here to help you understand them: • Interruptions: If interruptions are turned on, any user input during playback might stop the audio unexpectedly. • Audio Output Misconfiguration: If the audio output isn’t set up correctly or isn’t connected, the agent might seem like it’s speaking but you won’t hear anything. • Missing TTS or Realtime Audio: When there’s no audio source available, the agent switches to "speaking" but no sound actually plays. • Track Publishing Issues: If there are problems with publishing or subscribing to the audio track, the sound might not come through. • Silent or Zero-Volume Audio: Sometimes audio technically plays but isn’t audible due to volume settings or silent content. To help you troubleshoot this, here are some steps you can try: 1. Listen for the
playback_finished
event to spot any interruptions or playback issues. 2. Double-check that your audio output is properly configured and connected before starting speech. 3. Use the
current_speech
property to programmatically confirm when playback is complete. 4. Keep an eye on
agent_state_changed
events to catch any early state changes. 5. Turn on debug logging to catch any warnings or errors related to audio output. 6. Try testing the audio output separately with a known audio file to see if the issue might be with the audio pipeline. I hope these suggestions help you find and fix the problem. If you’d like, I’m here to guide you through any of these steps or answer any questions you have along the way. Sources: Getting Help | livekit/livekit_composite | DeepWiki | Agent speech and audio | LiveKit Docs | agents/src/voice/agent_activity.ts | livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/...