in my function "before_tts_cb", I want to stop TTS...
# ask-ai
a
in my function "before_tts_cb", I want to stop TTS to be processed.. what should I do in my function which prevents TTS generation?
t
Thanks for reaching out, Hiren. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
If you want to stop TTS processing right in your
before_tts_cb
function, a simple way is to return empty content so no audio gets synthesized. Here’s a quick example to show you how:
Copy code
async def _before_tts_cb(agent: VoicePipelineAgent, text: str | AsyncIterable[str]):
    # Check if you want to stop TTS
    if should_stop_tts():
        if isinstance(text, str):
            return ""  # Just return an empty string
        else:
            # Return an empty async generator for streaming
            async def empty_stream():
                return
                yield  # This line never actually runs
            return empty_stream()
    
    # Otherwise, go ahead and process normally
    return text
And if you’re working with LiveKit Agents 1.0 or newer, you might want to check out the `tts_node`—it gives you even more flexibility to customize your TTS pipeline. Feel free to reach out if you want a hand with that or have any specific scenarios where you want to stop TTS. I’m here to help! Sources: chain-of-thought-tts/agent.py | VoicePipelineAgent | LiveKit Docs | Agents v0.x migration guide | LiveKit Docs