How to modify the stt output before it reaches the...
# ask-ai
h
How to modify the stt output before it reaches the llm?
t
Thanks for reaching out, James. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
If you want to tweak the STT output before it gets to the LLM, a great way is to override the
stt_node
method in your own
Agent
subclass. This lets you catch and adjust the transcription from the STT model before passing it along to the LLM for inference. Here’s a simple example to get you started:
Copy code
async def stt_node(self, audio: AsyncIterable[rtc.AudioFrame], model_settings: ModelSettings) -> Optional[AsyncIterable[stt.SpeechEvent]]:
    # Process STT output before it goes to LLM
    events = Agent.default.stt_node(self, audio, model_settings)

    async def process_events():
        async for event in events:
            # Example: Modify the transcript text
            if event.type == stt.SpeechEventType.FINAL_TRANSCRIPT:
                event.alternatives[0].text = event.alternatives[0].text.replace("um", "").replace("uh", "")
            yield event

    return process_events()
Just to break it down: • The
stt_node
method takes the audio input and runs it through the default STT processing. • We then use a custom function to clean up the final transcript by removing filler words like "um" and "uh" before sending it off to the LLM. • The adjusted transcription events are then passed along for whatever comes next. This way, you have complete control over the STT output, so you can do things like clean it up, filter it, or add extra info before it moves forward. Pretty handy, right? Sources: Pipeline nodes and hooks | LiveKit Docs | Voice pipeline nodes | LiveKit Docs