is their the support for the tts streaming for the...
# ask-ai
r
is their the support for the tts streaming for the google in livekit google pulgin?
t
Thanks for reaching out, John. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
r
sure
t
Yes, the LiveKit Google plugin supports TTS streaming for Google. This feature is enabled by default and can be controlled using the
use_streaming
parameter during TTS initialization. If you need help with implementation or configuration, let me know! Sources: livekit-plugins/livekit-plugins-google/README.md | Google Cloud TTS integration guide | LiveKit Docs
The LiveKit Google plugin supports TTS streaming for Google. This feature is enabled by default and can be controlled using the
use_streaming
parameter during TTS initialization. If you need help with implementation or configuration, let me know!
r
i think i tried to use it using the use_streaming=True but it gives some error livekit.agents - Error in _tts_inference_task {"room": "fake_room"} Traceback (most recent call last): File "/live_kit/voice-bot/agent-env/lib/python3.10/site-packages/livekit/agents/tts/tts.py", line 529, in anext val = await self._event_aiter.__anext__() StopAsyncIteration During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/live_kit/voice-bot/agent-env/lib/python3.10/site-packages/livekit/agents/utils/log.py", line 16, in async_fn_logs return await fn(*args, **kwargs) File "/live_kit/voice-bot/agent-env/lib/python3.10/site-packages/opentelemetry/util/_decorator.py", line 71, in async_wrapper return await func(*args, **kwargs) # type: ignore File "live_kit/voice-bot/agent-env/lib/python3.10/site-packages/livekit/agents/voice/generation.py", line 212, in _tts_inference_task async for audio_frame in tts_node: File "ive_kit/voice-bot/agent-env/lib/python3.10/site-packages/livekit/agents/voice/agent.py", line 408, in tts_node async for ev in stream: File "ive_kit/voice-bot/agent-env/lib/python3.10/site-packages/livekit/agents/tts/tts.py", line 532, in anext raise exc # noqa: B904 File "ive_kit/voice-bot/agent-env/lib/python3.10/site-packages/opentelemetry/util/_decorator.py", line 71, in async_wrapper return await func(*args, **kwargs) # type: ignore File "live_kit/voice-bot/agent-env/lib/python3.10/site-packages/livekit/agents/tts/tts.py", line 357, in _main_task await self._run(output_emitter) File "ive_kit/voice-bot/agent-env/lib/python3.10/site-packages/livekit/plugins/google/tts.py", line 332, in _run await asyncio.gather(*tasks) File "live_kit/voice-bot/agent-env/lib/python3.10/site-packages/livekit/plugins/google/tts.py", line 325, in _run_segments await self._run_stream(input_stream, output_emitter, streaming_config) File "live_kit/voice-bot/agent-env/lib/python3.10/site-packages/livekit/plugins/google/tts.py", line 375, in _run_stream await input_gen.aclose() RuntimeError: aclose(): asynchronous generator is already running
i am getting above error
t
Hey there! That pesky error
RuntimeError: aclose(): asynchronous generator is already running
pops up when an asynchronous generator tries to close more than once. If you're using
use_streaming=True
with the LiveKit Google TTS plugin, the key is to make sure each stream is closed just once and handled carefully. Here’s a simple way to fix it: 1. Update the
aclose()
method in both the
TTS
and
SynthesizeStream
classes to check if a stream is already closed before calling
aclose()
. 2. Make sure streams get removed from the
WeakSet
after closing so they don’t get closed again by mistake. Here’s some example code to guide you:
Copy code
async def aclose(self):
    for stream in list(self._streams):
        if not stream.closed:
            await stream.aclose()
    self._streams.clear()

async def aclose(self):
    if self.closed:
        return
    self.closed = True
    if not self.input.closed:
        await self.input.aclose()
    if not self.output.closed:
        await self.output.aclose()
    self._tts._streams.discard(self)
This way, everything cleans up nicely and avoids that error. If you get stuck or want to chat more about it, just let me know—I’m here to help!
r
ie the issue in the pulgin implementation right
t
Hey! It looks like the issue is coming from how the plugin is set up. The error happens because the Google TTS plugin isn’t handling asynchronous generators quite right when cleaning up streams with
use_streaming=True
. To fix this, the plugin’s code needs a little tweak to make sure streams are closed just once and that the async generators are managed properly. If you’d like, I’m here to help walk you through those changes—just let me know!
r
after fixing this do i should add the pr for this?
t
Absolutely! If you’ve found a fix for this issue, submitting a pull request (PR) is a fantastic way to contribute to the LiveKit project. It helps the maintainers check out your changes and possibly add them to the official plugin, which can really help out other users too. Just be sure to include a clear description of the problem, how you fixed it, and any relevant test cases or updates to the documentation in your PR. And hey, if you need a hand with the process, just let me know—I’m here to help!