livekit / agents

Build real-time multimodal AI applications 🤖🎙️📹
https://docs.livekit.io/agents
Apache License 2.0
1.16k stars 230 forks source link

Crash while using- before_tts_cb #728

Open Test-isom opened 3 weeks ago

Test-isom commented 3 weeks ago

{"message": "Error in _str_synthesis_task\nTraceback (most recent call last):\n File \"/root/pythonenv/enve/lib/python3.10/site-packages/livekit/agents/utils/log.py\", line 16, in async_fn_logs\n return await fn(*args, **kwargs)\n File \"/root/pythonenv/enve/lib/python3.10/site-packages/livekit/agents/voice_assistant/agent_output.py\", line 195, in _str_synthesis_task\n handle.tts_forwarder.push_text(transcript)\n File \"/root/pythonenv/enve/lib/python3.10/site-packages/livekit/agents/transcription/tts_forwarder.py\", line 200, in push_text\n self._text_data.pushed_text += text\nTypeError: can only concatenate str (not \"async_generator\") to str", "level": "ERROR", "pid": 772990, "job_id": "AJ_owPeUnBxdvK3", "timestamp": "2024-09-09T10:18:21.988046+00:00"}

davidzhao commented 3 weeks ago

Can you share what your before_tts_cb is doing?

Test-isom commented 2 weeks ago

sure, not sure if iam doing something wrong, aim was to replace asterisk(currently i control it via prompt) before passing them to TTS,

initially it was this- if isinstance(text, AsyncIterable): async def process_async_text(): async for chunk in text: yield chunk.replace('*', '')

        return process_async_text()

    return text.replace('*', '')

Later i tried it with-

return tokenize.utils.replace_words(text=text, replacements={"*": ""})

Took reference from this-

https://github.com/livekit/agents/blob/main/examples/voice-assistant/custom_pronunciation.py