I want to implement a custom STT model. The model ...
# ask-ai
n
I want to implement a custom STT model. The model has streaming capabilities but no built in VAD or anything which would indicate a end of speech. I would set up a websocket connection so that the agent would periodically send audio frames and receive interim transcripts. The agent should also send a message indicating an end of speech event which should come from VAD used in Livekit. What's the best way to implement such a solution?
t
Thanks for reaching out, Karl. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It sounds like you want streaming STT with LiveKit-driven VAD to signal end-of-speech, over a WebSocket. Here’s the recommended pattern: • Capture audio frames from the participant track and forward to your STT: ◦ Inside an agent, use
rtc.AudioStream
to iterate frames and send them to your WebSocket/STT backend; resample/chunk per your model needs (e.g., 20–50 ms) Processing raw tracks. ◦ Alternative: use Track Egress → WebSocket if you want LiveKit to push pcm_s16le frames directly to your server Track egress. • Use VAD for endpointing and send explicit “end-of-speech” events: ◦ Run Silero VAD in the agent to detect start/stop of speech and emit an end-of-speech signal to your backend alongside the streaming audio/transcripts Silero VAD plugin. ◦ Set AgentSession turn detection to VAD-only if you want VAD to drive turns Turn detection. • Implement your custom streaming STT as an STT node/instance: ◦ Create a custom STT that accepts pushed audio frames (resampled as required), and emits interim/final transcripts. Use the STT streaming interface to
push_frame
and output `SpeechEvent`s STT models, Pipeline nodes. ◦ If you ever switch to non‑streaming STT, pair VAD with a StreamAdapter to buffer until end-of-speech, then send the chunk STT models. Would you like a minimal code sketch showing
AudioStream
+ Silero VAD + push to your WebSocket, and how to emit interim/final transcripts with an end-of-speech flag? Sources: Speech-to-text (STT) models | LiveKit Docs | Pipeline nodes and hooks | LiveKit docs | Silero VAD plugin | LiveKit docs | Turn detection and interruptions | LiveKit Docs | Processing raw media tracks | LiveKit docs
n
Yes, I would like minimal code example implementing the stt.STT and stt.SpeechStream classes for this use case
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
n
Give me the example Python code how you would do the integration