melodic-vegetable-78787
08/19/2025, 8:45 AMtall-airline-16756
08/19/2025, 8:45 AMtall-airline-16756
08/19/2025, 8:46 AMBackgroundAudioPlayer._play_task
method when it tries to close an asynchronous generator that’s still running. It usually happens when a task is cancelled while audio is playing.
Here’s how you can fix it:
1. Make sure to handle task cancellation properly by updating the finally
block in _play_task
to check if the task was cancelled before calling aclose()
.
2. Change the cleanup order in the BackgroundAudioPlayer.aclose()
method so it stops play handles before cancelling tasks.
3. If you can’t change the LiveKit code, you can catch and ignore the specific RuntimeError
in your app when calling aclose()
.
If you want, I’m here to help with more details or code examples—just let me know!
Sources: livekit-agents/livekit/agents/voice/agent_session.py