Realtime Translate TTS: speak in one language, hear another
A Python pipeline that listens to live audio, transcribes it as a stream, translates it with a fast language model and speaks the translation back in a native voice.
The problem
A live conversation across two languages needs a translated voice back with as little delay as possible, and typing into a translator breaks the flow of speaking.
How I built it
The pipeline captures audio in 20 ms chunks with a noise gate, streams it to Deepgram Nova-3 over a WebSocket, translates the finished text with Llama 3.3 70B on Groq, and plays the result through a neural voice chosen for the target language (voices are mapped for Urdu, Hindi, Spanish, French, German, Arabic, Chinese and Japanese). Source and target languages are command-line options.
What got hard
- Translating fragments mid-sentence gives poor translations, but waiting for a full thought adds delay.
The pipeline collects every finished transcript piece of a thought and translates only after a set stretch of silence (4 seconds by default, one setting to change it). That wait is the largest part of the delay, and it is the trade-off I chose for sentence-level quality. The translator also keeps the last few utterances as context so consecutive sentences stay coherent.
- A single translation provider outage would stop the whole conversation.
Groq is the primary translator and DeepSeek V3 is an automatic fallback behind the same prompt, so a failed call is retried on the second provider before the pipeline gives up.
- Digital noise from a virtual audio cable was being picked up as speech.
A noise gate replaces any 20 ms chunk below a loudness threshold with silence before it is sent, so the speech service only hears real speech.
- A long-lived streaming connection can drop mid-session, and a dropped connection would end the conversation.
A keep-alive message goes out every 8 seconds and the connection reconnects automatically with a growing wait (capped at 10 seconds), up to five attempts.
The result
A working command-line demo of the full loop (capture, stream, translate, speak), built in early April 2026, with the language pair and voice selectable from the command line.
The ← and → keys turn the page too.