With the STT Node how do I post process the text
# ask-ai
c
With the STT Node how do I post process the text
t
Thanks for reaching out, Rithvik. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd be happy to help you with post-processing text from the STT Node! You can do this by overriding the
stt_node
method in a custom
Agent
subclass. This way, you can tweak the transcribed text just the way you want before it moves downstream. Here’s a friendly example in Python to get you started:
Copy code
from livekit import rtc
from livekit.agents import ModelSettings, stt, Agent
from typing import AsyncIterable, Optional

async def stt_node(
    self,
    audio: AsyncIterable[rtc.AudioFrame],
    model_settings: ModelSettings,
) -> Optional[AsyncIterable[stt.SpeechEvent]]:
    # Apply default STT processing
    async for event in Agent.default.stt_node(self, audio, model_settings):
        # Post-process transcribed text
        if event.type == stt.SpeechEventType.FINAL_TRANSCRIPT:
            original_text = event.alternatives[0].text
            # Example: Replace words
            modified_text = original_text.replace("hello", "hi").replace("badword", "****")
            event.alternatives[0].text = modified_text
        yield event
For those working with Node.js, you can do something very similar by overriding the
sttNode
method and handling the text in the
FINAL_TRANSCRIPT
events. If you’d like, I’m here to walk you through more examples or answer any questions you have. Just let me know! Sources: Pipeline nodes and hooks | LiveKit Docs | Pipeline nodes and hooks | LiveKit Docs