The Speech AI Engineer builds voice-enabled applications - transcription pipelines using Whisper, text-to-speech integration, and real-time voice agents. The critical metric for voice AI is latency: users perceive response times over 1.5s as broken. Pipeline design must prioritize time-to-first-audio above throughput.
Whisper Transcription
import OpenAI from 'openai'; // Whisper API uses OpenAI SDK
import fs from 'fs';
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
// Basic transcription
async function transcribe(audioPath: string, language?: string) {
const response = await openai.audio.transcriptions.create({
file: fs.createReadStream(audioPath),
model: 'whisper-1',
language, // ISO 639-1 code - omit for auto-detection
response_format: 'verbose_json', // Includes word-level timestamps
timestamp_granularities: ['word'],
});
return response;
}
// Word-level timestamps enable: subtitle generation, speaker diarization
// alignment, trim silence, and transcript-audio synchronization
const result = await transcribe('./interview.mp3', 'en');
console.log(result.words); // [{word, start, end}, ...]
TTS Selection
| Service | Quality | Latency | Cost | Use case |
|---|---|---|---|---|
| OpenAI TTS (tts-1-hd) | Excellent | ~500ms | $30/1M chars | High-quality production |
| OpenAI TTS (tts-1) | Good | ~200ms | $15/1M chars | Real-time with streaming |
| ElevenLabs | Best-in-class | ~300ms | $22/1M chars | Voice cloning, emotional TTS |
| Google Cloud TTS | Good | ~100ms | $16/1M chars | High-volume, low cost |
| Local (Kokoro, XTTS) | Good | GPU-dependent | Infrastructure only | Privacy, offline |
Streaming Voice Pipeline
// Low-latency voice agent: STT → LLM → TTS streaming
async function streamingVoiceAgent(audioInput: ArrayBuffer) {
// Step 1: Transcribe (Whisper streaming - chunks as they arrive)
const transcript = await transcribeStream(audioInput);
// Step 2: LLM response with streaming enabled
const llmStream = client.messages.stream({
model: 'claude-haiku-4-5-20251001', // Haiku for speed - 50ms TTFT
max_tokens: 256, // Short responses for voice - users can't listen to essays
messages: [{ role: 'user', content: transcript }],
});
// Step 3: Convert each text chunk to audio as it arrives
// Buffer to sentence boundaries - TTS sounds better on complete sentences
let buffer = '';
for await (const event of llmStream) {
if (event.type === 'content_block_delta' && event.delta.type === 'text_delta') {
buffer += event.delta.text;
if (buffer.match(/[.!?]\s/)) {
await streamTTS(buffer); // Send sentence to TTS, play audio
buffer = '';
}
}
}
if (buffer.trim()) await streamTTS(buffer);
}
// Target: <800ms from end of user speech to start of TTS audio