I want to discard some user utterances recognized ...
# ask-ai
c
I want to discard some user utterances recognized by the STT that are too short, how should I do that?
t
Thanks for reaching out, Guillaume. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to discard very short STT-recognized user utterances. Use the agent lifecycle hook that runs after STT but before the agent responds: implement
on_user_turn_completed
, check the recognized message length (characters or words), and raise
StopResponse()
when the utterance is too short. Example (Python):
Copy code
from livekit import agents

async def on_user_turn_completed(
    self,
    *,
    turn_ctx: agents.llm.ChatContext,
    new_message: agents.ChatMessage,
):
    # discard utterances shorter than 3 characters
    if len(new_message.text_content) < 3:
        raise agents.voice.StopResponse()
If you prefer word-based filtering, replace the length check with
len(new_message.text_content.split()) < N
. Would you like a variant for your language or a JavaScript example? Sources: Pipeline nodes and hooks | LiveKit docs