Mockrithm Docs

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 NameVoice ID (ElevenLabs ID)Tone ProfileSenority Mode
Rachel21m00Tcm4TlvDq8ikWAMProfessional, friendlyJunior / Mid
DomAZnzlk1XvdvUeBnXmlldDirect, technicalSenior / Lead
ClydeErXwobaYiN019PkySvjVConversational, steadyBehavioral

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;
}

4. Easing Latency & Best Practices

On this page