Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/phpaisdk/elevenlabs/llms.txt

Use this file to discover all available pages before exploring further.

The ElevenLabs provider integrates with the portable Generate::speech() API, letting you swap TTS providers without rewriting application code. ElevenLabs-specific controls — voice settings, normalization, pronunciation dictionaries, and output format strings — are passed through providerOptions('elevenlabs', [...]) so the portable interface stays clean while full provider fidelity is preserved.

Installation

composer require aisdk/elevenlabs
Set your API key as an environment variable, or configure the provider directly at boot time:
use AiSdk\ElevenLabs;

ElevenLabs::create([
    'apiKey' => 'xi-...',
]);

Basic Usage

1

Build the speech request

Call Generate::speech() with the text you want to synthesize, then chain .model(), .voice(), .format(), and any provider options before calling .run().
use AiSdk\ElevenLabs;
use AiSdk\Generate;

$result = Generate::speech('Welcome to the show.')
    ->model(ElevenLabs::model('eleven_flash_v2_5'))
    ->voice('JBFqnCBsd6RMkjVDRZzb')
    ->format('mp3')
    ->run();
2

Save the output

The result exposes an AudioData object. Call save() with a filesystem path to write the audio file.
$result->output->save(__DIR__ . '/speech.mp3');

Voice IDs

ElevenLabs requires a voice ID for every TTS request. Pass it with the portable .voice() method. If you omit the voice, the adapter throws an InvalidArgumentException before the request is sent.
Generate::speech('Good evening.')
    ->model(ElevenLabs::model('eleven_v3'))
    ->voice('JBFqnCBsd6RMkjVDRZzb')   // ElevenLabs voice ID — required
    ->run();
You can also supply voice_id inside providerOptions('elevenlabs', [...]), but the portable .voice() method takes precedence.

Output Formats

Use .format() to select an audio format with a portable key. The adapter maps it to the appropriate ElevenLabs format string automatically.
.format() valueElevenLabs format stringDescription
mp3 (default)mp3_44100_128MP3 at 44.1 kHz, 128 kbps
wavwav_44100WAV at 44.1 kHz
pcmpcm_44100Raw PCM at 44.1 kHz
ulawulaw_8000µ-law at 8 kHz (telephony)
alawalaw_8000A-law at 8 kHz (telephony)
Generate::speech('Hello.')
    ->model(ElevenLabs::model('eleven_flash_v2_5'))
    ->voice('JBFqnCBsd6RMkjVDRZzb')
    ->format('wav')
    ->run();
When you need an ElevenLabs-specific format string that has no portable equivalent — such as mp3_44100_192 or pcm_22050 — set output_format in providerOptions('elevenlabs', [...]). It overrides the value derived from .format().
->providerOptions('elevenlabs', ['output_format' => 'mp3_44100_192'])

Provider Options

providerOptions('elevenlabs', [...]) accepts the full set of documented ElevenLabs request fields. The adapter routes them to the correct part of the HTTP request automatically.

Query Parameters

The following fields are sent as URL query parameters, not in the request body, matching the ElevenLabs API contract.
output_format
string
An ElevenLabs-specific output format string such as mp3_44100_192 or pcm_22050. Overrides the value derived from the portable .format() method.
enable_logging
bool
When false, ElevenLabs does not store the request in your history. Sent as enable_logging=false in the query string.
optimize_streaming_latency
int
Deprecated ElevenLabs latency-optimization level (0–4). Sent as a query parameter. Prefer eleven_flash_v2_5 for low latency instead.

JSON Body Fields

All other fields are merged into the JSON request body alongside text and model_id.
voice_settings
object
Fine-grained voice control. All sub-fields are optional and override the voice’s saved defaults.
  • stability (float) — Consistency of delivery. Higher values are more predictable; lower values are more expressive.
  • similarity_boost (float) — How closely the output resembles the original voice.
  • style (float) — Stylistic intensity. Only effective on v2 and later models.
  • use_speaker_boost (bool) — Applies a speaker-similarity enhancement pass.
apply_text_normalization
string
Controls how ElevenLabs normalizes text before synthesis. Accepted values are auto, on, and off.
language_code
string
A BCP-47 language code hint (e.g. en, fr, de). Improves pronunciation for multilingual models such as eleven_multilingual_v2.
seed
int
Integer seed for deterministic generation. Using the same seed and input should produce the same audio output.
pronunciation_dictionary_locators
array
Array of pronunciation dictionary locators to apply. Each entry should be an object with pronunciation_dictionary_id and optionally version_id.

Voice Settings Example

use AiSdk\ElevenLabs;
use AiSdk\Generate;

$result = Generate::speech('Welcome to the show.')
    ->model(ElevenLabs::model('eleven_flash_v2_5'))
    ->voice('JBFqnCBsd6RMkjVDRZzb')
    ->format('mp3')
    ->providerOptions('elevenlabs', [
        'voice_settings' => [
            'stability'        => 0.5,
            'similarity_boost' => 0.75,
            'style'            => 0.2,
            'use_speaker_boost' => true,
        ],
        'apply_text_normalization' => 'auto',
        'language_code' => 'en',
        'seed' => 42,
    ])
    ->run();

$result->output->save(__DIR__ . '/speech.mp3');

Full Example with All Options

use AiSdk\ElevenLabs;
use AiSdk\Generate;

$result = Generate::speech('Hello there.')
    ->model(ElevenLabs::model('eleven_flash_v2_5'))
    ->voice('JBFqnCBsd6RMkjVDRZzb')
    ->providerOptions('elevenlabs', [
        // Query parameters
        'output_format'              => 'wav_44100',
        'enable_logging'             => false,
        'optimize_streaming_latency' => 2,

        // JSON body fields
        'seed' => 42,
        'voice_settings' => [
            'stability'        => 0.5,
            'similarity_boost' => 0.75,
        ],
    ])
    ->run();

$result->output->save(__DIR__ . '/speech.wav');

Available Model IDs

eleven_flash_v2_5

Ultra-low-latency model. Best for real-time applications and streaming scenarios.

eleven_v3

Latest high-quality model. Best for expressive, studio-quality voice output.

eleven_multilingual_v2

Multilingual model supporting 29 languages. Use with language_code for best results.
For the lowest possible latency, use eleven_flash_v2_5. For the highest quality output — podcast narration, audiobooks, or voice-over work — use eleven_v3.

Build docs developers (and LLMs) love