1. Speech-to-Text Pipeline Optimization
The biggest bottleneck in AI voice latency is the audio streaming pipeline. Traditional HTTP POST requests add unnecessary TCP handshakes and chunk delays. By utilizing raw WebSocket streams encoded in 16kHz PCM audio, we bypass buffer latency entirely.
- PCM 16-bit audio streaming over bidirectional WebSockets
- VAD (Voice Activity Detection) frame trimming before transcription
- Whisper AI v3 large-v3-turbo model deployed on NVIDIA H100 Tensor Core GPUs
const ws = new WebSocket("wss://api.appduniya.co.in/v1/voice/stream");
ws.onopen = () => {
navigator.mediaDevices.getUserMedia({ audio: true }).then((stream) => {
const audioContext = new AudioContext({ sampleRate: 16000 });
const source = audioContext.createMediaStreamSource(stream);
const processor = audioContext.createScriptProcessor(2048, 1, 1);
processor.onaudioprocess = (e) => {
const inputData = e.inputBuffer.getChannelData(0);
ws.send(inputData.buffer);
};
});
};2. Large Language Model Streaming & Sentence Truncation
Waiting for the full LLM response string before initiating Text-to-Speech (TTS) introduces 1.5 to 2.5 seconds of artificial silence. Our architecture streams token responses sentence-by-sentence directly into ElevenLabs & OpenAI Realtime TTS endpoints.
- Sentence boundary regex parsing for zero-wait TTS audio queueing
- Contextual memory caching via Redis VectorDB for sub-50ms context retrieval
- Fallback fallback models (GPT-4o-mini) when network latency spikes
Key Technical Takeaways
- 1Always use WebSockets over HTTP REST for real-time audio streams.
- 2Implement Voice Activity Detection (VAD) on the edge to reduce GPU inferencing costs by 40%.
- 3Stream LLM output sentence-by-sentence directly into TTS models for human-like response times.
