powerful-hairdresser-78108
08/21/2025, 11:06 AMUsing Assistant for verified customer
{"message": "Error in _tts_inference_task\nTraceback (most recent call last):\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/agents/tts/tts.py\", line 517, in __anext__\n val = await self._event_aiter.__anext__()\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nStopAsyncIteration\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/agents/utils/log.py\", line 16, in async_fn_logs\n return await fn(*args, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/opentelemetry/util/_decorator.py\", line 71, in async_wrapper\n return await func(*args, **kwargs) # type: ignore\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/agents/voice/generation.py\", line 212, in _tts_inference_task\n async for audio_frame in tts_node:\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/agents/voice/agent.py\", line 409, in tts_node\n async for ev in stream:\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/agents/tts/tts.py\", line 520, in __anext__\n raise exc # noqa: B904\n ^^^^^^^^^\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/opentelemetry/util/_decorator.py\", line 71, in async_wrapper\n return await func(*args, **kwargs) # type: ignore\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/agents/tts/tts.py\", line 348, in _main_task\n await self._run(output_emitter)\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/plugins/google/tts.py\", line 332, in _run\n await asyncio.gather(*tasks)\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/plugins/google/tts.py\", line 325, in _run_segments\n await self._run_stream(input_stream, output_emitter, streaming_config)\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/plugins/google/tts.py\", line 375, in _run_stream\n await input_gen.aclose()\nRuntimeError: aclose(): asynchronous generator is already running", "level": "ERROR", "name": "livekit.agents", "pid": 199023, "job_id": "AJ_EaxihJZmwuaR", "timestamp": "2025-08-21T11:01:23.081917+00:00"}
{"message": "_SegmentSynchronizerImpl text marked as ended in capture text, rotating segment", "level": "WARNING", "name": "livekit.agents", "pid": 199023, "job_id": "AJ_EaxihJZmwuaR", "timestamp": "2025-08-21T11:01:43.682406+00:00"}
{"message": "Error in _tts_inference_task\nTraceback (most recent call last):\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/agents/tts/tts.py\", line 517, in __anext__\n val = await self._event_aiter.__anext__()\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nStopAsyncIteration\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/agents/utils/log.py\", line 16, in async_fn_logs\n return await fn(*args, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/opentelemetry/util/_decorator.py\", line 71, in async_wrapper\n return await func(*args, **kwargs) # type: ignore\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/agents/voice/generation.py\", line 212, in _tts_inference_task\n async for audio_frame in tts_node:\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/agents/voice/agent.py\", line 409, in tts_node\n async for ev in stream:\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/agents/tts/tts.py\", line 520, in __anext__\n raise exc # noqa: B904\n ^^^^^^^^^\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/opentelemetry/util/_decorator.py\", line 71, in async_wrapper\n return await func(*args, **kwargs) # type: ignore\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/agents/tts/tts.py\", line 348, in _main_task\n await self._run(output_emitter)\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/plugins/google/tts.py\", line 332, in _run\n await asyncio.gather(*tasks)\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/plugins/google/tts.py\", line 325, in _run_segments\n await self._run_stream(input_stream, output_emitter, streaming_config)\n File \"/mnt/d/Sowiz/voice_agents/voice-utilities/myenv/lib/python3.12/site-packages/livekit/plugins/google/tts.py\", line 375, in _run_stream\n await input_gen.aclose()\nRuntimeError: aclose(): asynchronous generator is already running", "level": "ERROR", "name": "livekit.agents", "pid": 199023, "job_id": "AJ_EaxihJZmwuaR", "timestamp": "2025-08-21T11:01:43.916216+00:00"}
{"message": "closing agent session due to participant disconnect (disable via `RoomInputOptions.close_on_disconnect=False`)", "level": "INFO", "name": "livekit.agents", "participant": "sip_07038413203", "reason": "CLIENT_INITIATED", "pid": 199023, "job_id": "AJ_EaxihJZmwuaR", "timestamp": "2025-08-21T11:02:19.086345+00:00"}
{"message": "process exiting", "level": "INFO", "name": "livekit.agents", "reason": "room disconnected", "pid": 199023, "job_id": "AJ_EaxihJZmwuaR", "timestamp": "2025-08-21T11:02:40.899496+00:00"}
I am facing this issue while using Google TTStall-airline-16756
08/21/2025, 11:06 AMpowerful-hairdresser-78108
08/21/2025, 11:06 AMtall-airline-16756
08/21/2025, 11:07 AMRuntimeError: aclose(): asynchronous generator is already running in LiveKit Google TTS usually pops up when there’s a clash between an async generator that’s already running and an attempt to close it. Don’t worry, here are some friendly tips to help you fix and avoid this issue:
1. Proper Stream Lifecycle Management: It’s super helpful to use context managers to handle the TTS stream lifecycle. Like this:
async with tts.stream() as stream:
stream.push_text("Hello world")
stream.flush()
stream.end_input()
async for audio in stream:
# Process audio
pass
# Stream is automatically closed here
1. Avoid Concurrent Operations: Make sure you’re not trying to close or change a stream while it’s still being used.
2. Use Proper Task Cancellation: If you need to stop operations, try using tools like utils.aio.cancel_and_wait to clean things up nicely.
3. Check for Multiple Stream References: Try not to keep multiple references to the same stream or use it in different places at the same time.
4. TTS Instance Cleanup: Always remember to properly close the TTS instance with await tts.aclose() so everything shuts down smoothly.
Following these steps should keep things running smoothly and help you avoid that pesky error. If you want a hand with anything else, just give me a shout—I’m here to help!
Sources: livekit-agents/livekit/agents/tts/stream_adapter.py