Environment
-
LiveKit Agents SDK version: 「Python Agents v1.5.0」
-
LiveKit Server version: 「v1.0.25」
-
Operating System: NVIDIA Jetson Orin / JetPack 6.1
Problem
When the microphone cable becomes loose or experiences physical instability (e.g., poor contact) during a LiveKit client session, the client stops receiving audio. The microphone hardware itself continues to function normally (system audio meters show signal), but the LiveKit client does not receive any audio frames. The client does not crash or freeze – logs continue to print, the network connection remains active, and other features (like receiving remote audio) still work. Restarting the client fully resolves the issue. The server side shows no errors.
This issue has been observed when using rtc.MediaDevices to capture microphone input in a LiveKit Agent (Python SDK). The problem is silent: no exceptions are raised, and no obvious error logs appear.
Reproduction steps:
-
Set up a LiveKit Python agent that uses
rtc.MediaDevicesto open a microphone and publish a local audio track. -
Start the agent and join a room. Verify that audio is being sent (e.g., by listening on another client).
-
While the agent is running, physically wiggle or partially unplug the microphone cable (USB or 3.5mm) to simulate a loose connection. You may need to do this several times to trigger the issue.
-
Observe that after some point, the agent stops sending audio, even though the system audio settings show microphone input is still active (e.g., volume meter moves).
-
Notice that the agent’s logs continue to print normally, no exceptions are raised, and the agent remains connected to the room.
-
Restart the agent – audio works again.
Minimal code example:
python
import asyncio
from livekit import rtc, api
async def main():
room = rtc.Room()
await room.connect(URL, token)
devices = rtc.MediaDevices()
mic = devices.open_input(enable_aec=True, noise_suppression=True)
audio_track = rtc.LocalAudioTrack.create_audio_track("mic", mic.source)
await room.local_participant.publish_track(audio_track)
await asyncio.Event().wait() # keep running
What I’ve already checked
-
The microphone hardware is working – system audio meters show signal after the cable is reconnected. -
The LiveKit client does not crash, and network connection remains active. -
No exceptions or error logs are printed on either client or server side. -
Restarting the client fully restores audio capture.
The underlying cause might be related to how MediaDevices.open_input() (which uses sounddevice/PortAudio) handles temporary device disruptions. Once the audio callback stops being invoked (or APM silently discards frames), the audio track stops sending data, and there is no built-in recovery mechanism.
Questions
Could you help identify how to make the LiveKit client resilient to temporary microphone connection instability? Specifically:
-
Is there a way to automatically recover audio capture without restarting the client when the microphone device becomes temporarily unavailable but then works again?
-
Can the client detect this condition (e.g., “audio source stalled”) and emit a clear error or event, so that the application can restart the audio track or reinitialize the microphone gracefully?
-
Are there any configuration options or workarounds (e.g., reopening the device on disconnect, or using a different audio backend) that would prevent the audio pipeline from entering a dead state?
Thank you so much for your help!