how to use transcription_node
# ask-ai
p
how to use transcription_node
t
Thanks for reaching out, Bryner. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The
transcription_node
in LiveKit is a handy tool that lets you tweak or clean up the transcribed text before it gets sent out. It’s part of the STT-LLM-TTS pipeline and you can customize it for things like fixing punctuation, tidying up formatting, or swapping out unwanted characters. Here’s a simple example to show you how to override the `transcription_node`:
Copy code
async def transcription_node(self, text: AsyncIterable[str], model_settings: ModelSettings):
    async def process_text():
        async for chunk in text:
            modified_chunk = chunk.replace("hello", "👋 HELLO").replace("goodbye", "GOODBYE 👋")
            yield modified_chunk
    return process_text()
If you’re looking to do something more advanced, like syncing with TTS-aligned transcriptions or filtering structured LLM output, there are extra options and methods we can explore together. Just let me know what you’re aiming for, and I’d be happy to help! Sources: pipeline-llm/transcription_node.py | Text and transcriptions | LiveKit Docs | How to capture real-time agent transcriptions during conversations | Text and transcriptions | LiveKit Docs | Transcriptions | LiveKit Docs
p
before it gets send out to where? llm or tts?
t
The
transcription_node
takes the text output from the LLM and gets it ready for the final display, like showing it on the UI or sending it to client-facing streams. Just a heads-up—it doesn’t send the text straight to the TTS system. Here’s how it works in the pipeline: 1. The LLM creates the text output. 2. The
transcription_node
tweaks or cleans up that text. 3. The polished text is then sent to the right output channel (like a transcription display). 4. Meanwhile, a separate stream can be sent off to the TTS system to turn text into audio. If you want me to walk you through any part of this or need more details, just let me know—I’m here to help! Sources: Pipeline nodes and hooks | LiveKit Docs | examples/voice_agents/realtime_with_tts.py
p
then what do i need to modify the output from LLM and before sending it to TTS
t
Hey there! If you want to tweak the LLM output before it goes to TTS, you can use the
tts_node
method in LiveKit Agents v1.x. This lets you catch the text and make any changes before it’s sent off to the TTS engine. Here’s a quick example:
Copy code
async def tts_node(self, text: AsyncIterable[str], model_settings: ModelSettings):
    async def process_text():
        async for chunk in text:
            modified_chunk = chunk.replace("lol", "<laugh>").replace("LOL", "<laugh>")
            yield modified_chunk

    return Agent.default.tts_node(self, process_text(), model_settings)
And if you’re working with an older version (v0.x), no worries! You can do something similar using the
before_tts_cb
callback. Just give me a shout if you want help with a specific version or need more details—I’m here to help! Sources: pipeline-tts/tts_node.py | chain-of-thought-tts/README.mdoc | VoicePipelineAgent | LiveKit Docs | Agents 0.x migration guide | LiveKit Docs
p
how about stt_node
t
The
stt_node
in LiveKit lets you tailor the speech-to-text (STT) processing pipeline to fit your needs. It turns user audio into text for the LLM, and you can even override it to add your own audio preprocessing or text post-processing. Here’s a friendly example of how you might override the `stt_node`:
Copy code
async def stt_node(
    self, audio: AsyncIterable[rtc.AudioFrame], model_settings: ModelSettings
) -> Optional[AsyncIterable[stt.SpeechEvent]]:
    # Custom audio preprocessing
    async def filtered_audio():
        async for frame in audio:
            # insert custom audio preprocessing here
            yield frame

    # Use default STT implementation with filtered audio
    async for event in Agent.default.stt_node(self, filtered_audio(), model_settings):
        # insert custom text postprocessing here
        yield event
This way, you can filter or improve the audio, or tweak the transcription before it reaches the LLM. If you want to chat about a specific use case or need a hand, just let me know—I’m here to help! Sources: Voice pipeline nodes | LiveKit Docs | Pipeline nodes and hooks | LiveKit Docs | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/stt.py