Transcription API
Transcription API
Unified interface for all transcription providers with streaming support
Transcription API
VoiceRouter provides a unified interface for transcribing audio using any supported provider. Switch between Deepgram, Gladia, Assembly AI, and more with a single config change.
Quick Start
import { createRouter } from "voice-router-dev";
const router = createRouter({
provider: "gladia",
apiKey: process.env.GLADIA_API_KEY,
});
// Transcribe audio
const result = await router.transcribe({
audio: audioBuffer,
language: "en",
});
console.log(result.text);Streaming Transcription
VoiceRouter supports real-time streaming transcription:
const stream = await router.transcribeStream({
language: "en",
});
// Send audio chunks
stream.send(audioChunk);
// Receive transcription updates
stream.on("transcript", (data) => {
console.log(data.text);
});
// Close when done
stream.close();Supported Providers
| Provider | Real-time | Batch | Diarization |
|---|---|---|---|
| Deepgram | Yes | Yes | Yes |
| Gladia | Yes | Yes | Yes |
| Assembly AI | Yes | Yes | Yes |
| OpenAI Whisper | No | Yes | Yes |
| Speechmatics | No | Yes | Yes |
| Google Speech | Yes | Yes | Yes |
| Azure Speech | Yes | Yes | Yes |
Configuration Options
const router = createRouter({
provider: "gladia",
apiKey: process.env.GLADIA_API_KEY,
options: {
model: "accurate",
language: "en",
punctuate: true,
diarize: true,
smart_format: true,
},
});Switching Providers
Switch providers without changing your application code:
// Before: Using Gladia
const router = createRouter({
provider: "gladia",
apiKey: process.env.GLADIA_API_KEY,
});
// After: Using Deepgram (same code works!)
const router = createRouter({
provider: "deepgram",
apiKey: process.env.DEEPGRAM_API_KEY,
});Error Handling
VoiceRouter provides consistent error handling across all providers:
try {
const result = await router.transcribe({ audio });
} catch (error) {
if (error.code === "RATE_LIMIT") {
// Handle rate limiting
} else if (error.code === "INVALID_AUDIO") {
// Handle invalid audio format
}
}