ElevenLabs API Voice Synthesis
This page provides the configuration and developer setup details for integrating ElevenLabs Text-to-Speech (TTS) voice synthesis in Mockrithm's mock interview console.
1. Architectural Role
ElevenLabs powers the speech generation for our AI interviewers. When the interview backend generates a text question or response, it is sent to the ElevenLabs streaming API to synthesize natural-sounding voice audio.
graph LR
Text[Question Text] --> API[ElevenLabs Streaming API]
API --> AudioChunks[PCM Audio Chunks]
AudioChunks --> WebSocket[WebSocket Client Buffer]
WebSocket --> Speaker[Speaker Playback]2. Voice Configurations Configurations
We use specific voice presets to match different interviewer personas (e.g. Rachel for a friendly tone, Dom for a strict technical review).
| Voice Name | Voice ID (ElevenLabs ID) | Tone Profile | Senority Mode |
|---|---|---|---|
| Rachel | 21m00Tcm4TlvDq8ikWAM | Professional, friendly | Junior / Mid |
| Dom | AZnzlk1XvdvUeBnXmlld | Direct, technical | Senior / Lead |
| Clyde | ErXwobaYiN019PkySvjV | Conversational, steady | Behavioral |
3. Streaming Code Implementation
Here is the implementation code to establish a real-time voice stream from ElevenLabs:
import axios from "axios";
import { Readable } from "stream";
interface SynthesisConfig {
text: string;
voiceId: string;
stability?: number;
similarityBoost?: number;
}
export async function streamVoiceAudio({
text,
voiceId,
stability = 0.75,
similarityBoost = 0.85
}: SynthesisConfig): Promise<Readable> {
const ELEVENLABS_API_KEY = process.env.ELEVENLABS_API_KEY;
if (!ELEVENLABS_API_KEY) throw new Error("ElevenLabs API Key not configured.");
const response = await axios({
method: "POST",
url: `https://api.elevenlabs.io/v1/text-to-speech/${voiceId}/stream`,
headers: {
"accept": "audio/mpeg",
"xi-api-key": ELEVENLABS_API_KEY,
"content-type": "application/json",
},
data: {
text,
model_id: "eleven_monolingual_v1",
voice_settings: {
stability,
similarity_boost: similarityBoost,
},
},
responseType: "stream",
});
return response.data as Readable;
}