3:52:09 livekit.1 | 2025-07-30 13:52:09,534 - DEBU...
# ask-ai
r
135209 livekit.1 | 2025-07-30 135209,534 - DEBUG asyncio - Using selector: KqueueSelector {“pid”: 12627} 135211 livekit.1 | 2025-07-30 135211,526 - WARNING livekit.agents - failed to synthesize speech, retrying in 2.0s 135211 livekit.1 | Traceback (most recent call last): 135211 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/plugins/cartesia/tts.py”, line 351, in _run 135211 livekit.1 | await asyncio.gather(*tasks) 135211 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/plugins/cartesia/tts.py”, line 309, in _input_task 135211 livekit.1 | self._sent_tokenizer_stream.end_input() 135211 livekit.1 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ 135211 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/agents/tokenize/token_stream.py”, line 94, in end_input 135211 livekit.1 | self.flush() 135211 livekit.1 | ~~~~~~~~~~^^ 135211 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/agents/tokenize/token_stream.py”, line 71, in flush 135211 livekit.1 | self._check_not_closed() 135211 livekit.1 | ~~~~~~~~~~~~~~~~~~~~~~^^ 135211 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/agents/tokenize/token_stream.py”, line 103, in _check_not_closed 135211 livekit.1 | raise RuntimeError(f”{cls.module}.{cls.name} is closed”) 135211 livekit.1 | RuntimeError: livekit.agents.tokenize.token_stream.BufferedSentenceStream is closed 135211 livekit.1 | 135211 livekit.1 | The above exception was the direct cause of the following exception: 135211 livekit.1 | 135211 livekit.1 | Traceback (most recent call last): 135211 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/agents/tts/tts.py”, line 311, in _main_task 135211 livekit.1 | await self._run(output_emitter) 135211 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/plugins/cartesia/tts.py”, line 361, in _run 135211 livekit.1 | raise APIConnectionError() from e 135211 livekit.1 | livekit.agents._exceptions.APIConnectionError: Connection error. (body=None, retryable=True) {“tts”: “livekit.plugins.cartesia.tts.TTS”, “attempt”: 3, “streamed”: true, “pid”: 12590, “job_id”: “AJ_Jqm68j7DhWJo”} 135213 livekit.1 | 2025-07-30 135213,968 - ERROR livekit.agents - Error in _inference_task 135213 livekit.1 | Traceback (most recent call last): 135213 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/plugins/cartesia/tts.py”, line 351, in _run 135213 livekit.1 | await asyncio.gather(*tasks) 135213 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/plugins/cartesia/tts.py”, line 309, in _input_task 135213 livekit.1 | self._sent_tokenizer_stream.end_input() 135213 livekit.1 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ 135213 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/agents/tokenize/token_stream.py”, line 94, in end_input 135213 livekit.1 | self.flush() 135213 livekit.1 | ~~~~~~~~~~^^ 135213 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/agents/tokenize/token_stream.py”, line 71, in flush 135213 livekit.1 | self._check_not_closed() 135213 livekit.1 | ~~~~~~~~~~~~~~~~~~~~~~^^ 135213 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/agents/tokenize/token_stream.py”, line 103, in _check_not_closed 135213 livekit.1 | raise RuntimeError(f”{cls.module}.{cls.name} is closed”) 135213 livekit.1 | RuntimeError: livekit.agents.tokenize.token_stream.BufferedSentenceStream is closed 135213 livekit.1 | 135213 livekit.1 | The above exception was the direct cause of the following exception: 135213 livekit.1 | 135213 livekit.1 | Traceback (most recent call last): 135213 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/agents/utils/log.py”, line 16, in async_fn_logs 135213 livekit.1 | return await fn(*args, **kwargs) 135213 livekit.1 | ^^^^^^^^^^^^^^^^^^^^^^^^^ 135213 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/agents/voice/generation.py”, line 147, in _inference_task 135213 livekit.1 | async for audio_frame in tts_node: 135213 livekit.1 | audio_ch.send_nowait(audio_frame) 135213 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/agents/voice/agent.py”, line 385, in tts_node 135213 livekit.1 | async for ev in stream: 135213 livekit.1 | yield ev.frame 135213 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/agents/tts/tts.py”, line 474, in anext 135213 livekit.1 | raise exc # noqa: B904 135213 livekit.1 | ^^^^^^^^^ 135213 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/agents/tts/tts.py”, line 311, in _main_task 135213 livekit.1 | await self._run(output_emitter) 135213 livekit.1 | File “/Users/olivernaaris/git-projects/polyglotpal/polyglotpal/backend/.venv/lib/python3.13/site-packages/livekit/plugins/cartesia/tts.py”, line 361, in _run 135213 livekit.1 | raise APIConnectionError() from e 135213 livekit.1 | livekit.agents._exceptions.APIConnectionError: Connection error. (body=None, retryable=True) {“pid”: 12590, “job_id”: “AJ_Jqm68j7DhWJo”} What does this error mean?
t
Thanks for reaching out, Oliver. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The error
livekit.agents.tokenize.token_stream.BufferedSentenceStream is closed
occurs when operations are attempted on a
BufferedSentenceStream
that has already been closed. This can happen in the following scenarios: • When the
close()
method is explicitly called, which closes both the input and output of the tokenizer stream. • When
endInput()
is called, marking the input as ended and forbidding additional pushes. To resolve this issue: 1. Check the stream status using the
closed
property before performing operations. 2. Avoid performing operations like
pushText()
or
flush()
after calling
endInput()
or
close()
. 3. If you need to continue processing, create a new
BufferedSentenceStream
instance with the appropriate parameters (e.g.,
func
,
minTokenLength
,
minContextLength
). Let me know if you need further clarification or assistance with implementing these steps. Sources: BufferedSentenceStream | LiveKit Agents