Creates a new ElevenLabsTextToSpeechProvider.
Provider configuration including API key and optional defaults.
const provider = new ElevenLabsTextToSpeechProvider({
apiKey: 'xi-xxxx',
voiceId: 'pNInz6obpgDQGcFmaJgB',
model: 'eleven_multilingual_v2',
});
Synthesizes speech from text using the ElevenLabs TTS API.
The text to convert to audio.
Optional synthesis settings. Use providerSpecificOptions
to control ElevenLabs-specific voice settings (stability, similarityBoost,
style, useSpeakerBoost).
A promise resolving to the MP3 audio buffer and metadata.
When the ElevenLabs API returns a non-2xx status code. Common causes: invalid API key (401), voice not found (404), character limit exceeded (400), or rate limit (429).
const result = await provider.synthesize('Hello there!', {
voice: 'pNInz6obpgDQGcFmaJgB',
providerSpecificOptions: {
stability: 0.3, // More expressive
similarityBoost: 0.9, // Closer to original voice
style: 0.5, // Moderate style exaggeration
},
});
Fetches the user's voice library from the ElevenLabs API.
Returns available voices mapped to the normalized SpeechVoice shape. Gracefully returns an empty array on API errors (e.g. network failure, invalid key) to avoid breaking voice selection UIs.
The voice library includes both ElevenLabs' pre-made voices and any custom/cloned voices in the user's account.
A promise resolving to an array of available voices, or an empty array if the API call fails.
const voices = await provider.listAvailableVoices();
const rachel = voices.find(v => v.name === 'Rachel');
Readonly idUnique provider identifier used for registration and resolution.
Readonly displayHuman-readable display name for UI and logging.
Readonly supportsStreaming is supported — ElevenLabs offers a WebSocket streaming endpoint, and even the REST endpoint can be consumed as a stream.
Text-to-speech provider that uses the ElevenLabs TTS API.
API Contract
POST {baseUrl}/text-to-speech/{voiceId}xi-api-key: <apiKey>headerapplication/jsonaudio/mpeg(MP3 response){ text, model_id, voice_settings: { stability, similarity_boost, style, use_speaker_boost } }Voice Settings
ElevenLabs exposes fine-grained voice control via
voice_settings:These can be passed via
options.providerSpecificOptions.Voice ID Resolution
The voice ID is resolved with the following priority:
options.voice(per-call override)config.voiceId(constructor default)options.providerSpecificOptions.voiceId(legacy override path)'EXAVITQu4vr4xnSDxMaL'(hardcoded fallback — the "Sarah" voice)Voice Listing
listAvailableVoices fetches the user's voice library from the
/voicesendpoint and maps each entry to the normalized SpeechVoice shape. Returns an empty array on API errors (graceful degradation).See
ElevenLabsTextToSpeechProviderConfig for configuration options
Example