The PHP AI SDK Live API provides a server-side WebSocket integration for ElevenLabs Scribe v2 Realtime. You stream raw audio bytes to the session and iterate over typed events as the transcript materializes in real time — receiving revisable partial updates as audio arrives, and committed final transcripts when each utterance is complete.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.
Installation
Install the ElevenLabs provider and the optionalaisdk/transport package, which supplies a ready-made WebSocket transport:
aisdk/transport is optional. Any class implementing AiSdk\Live\Contracts\TransportInterface works in its place — the event normalization and protocol encoding always come from this package.Basic Server-Side Usage
Open a live session
Call
Live::transcribe(), chain configuration, and connect using Transport::auto(). The session is synchronous and stays open until you stop iterating or call $session->close().Send and commit audio
Call
sendAudio() with raw PCM bytes as they become available. When you have sent a complete utterance, call commitAudio() to signal ElevenLabs to finalize the transcript for that segment.Transcript Event Types
TranscriptUpdate
A partial, revisable transcript emitted as audio is received. The text may change with subsequent
TranscriptUpdate events before the utterance is committed. Corresponds to ElevenLabs partial_transcript messages.TranscriptCompleted
A committed, final transcript for a completed utterance. No further updates will modify this text. Corresponds to ElevenLabs
committed_transcript messages.ProviderEvent
A raw ElevenLabs message that has no portable SDK equivalent. Inspect
$event->providerType and $event->payload to access ElevenLabs-specific data such as committed_transcript_with_timestamps or session_started.LiveError
A normalized error event. Inspect
$event->code for the ElevenLabs error type and $event->message for a human-readable description.Timestamps and ProviderEvent
When include_timestamps is true, ElevenLabs sends two messages for each committed utterance: the standard committed_transcript and then a committed_transcript_with_timestamps message containing per-word timing metadata. The adapter normalizes the first into a TranscriptCompleted event. The second is delivered as a ProviderEvent to preserve the word metadata without duplicating the portable completion event.
Provider Options
Pass ElevenLabs-specific session configuration throughproviderOptions('elevenlabs', [...]). All recognized fields are sent as WebSocket URL query parameters.
Controls when audio segments are committed. Use
'vad' to let ElevenLabs detect speech boundaries automatically, or 'manual' to commit utterances yourself with $session->commitAudio().When
true, each committed utterance is followed by a committed_transcript_with_timestamps ProviderEvent containing per-word start and end times.When
true, ElevenLabs includes detected language information in its response messages.Duration of silence (in seconds) after which the VAD considers the current utterance complete. Only applies when
commit_strategy is 'vad'.Voice activity detection sensitivity threshold. Higher values require louder or clearer speech to trigger VAD. Only applies when
commit_strategy is 'vad'.Minimum duration of speech (in milliseconds) required before the VAD treats audio as an utterance. Only applies when
commit_strategy is 'vad'.Minimum silence gap (in milliseconds) between detected utterances. Only applies when
commit_strategy is 'vad'.When
true, Scribe applies background noise suppression before transcribing.An array of domain-specific terms to boost recognition accuracy. Each term is sent as a separate
keyterms query parameter.When
true, Scribe omits filler words and false starts from the transcript.When
false, ElevenLabs does not store the session in your history.Audio Format Mapping
Use the portable.audioFormat() method on the builder. The adapter maps common portable identifiers to their ElevenLabs equivalents before connecting.
| Portable value | ElevenLabs format | Description |
|---|---|---|
'pcm' or 'pcm16' or 'audio/pcm' | pcm_16000 | 16-bit PCM at 16 kHz |
'pcmu' or 'mulaw' or 'g711_ulaw' | ulaw_8000 | µ-law at 8 kHz (telephony) |
| Any other string | Passed through as-is | Use ElevenLabs format strings directly |
Error Handling
ElevenLabs Scribe Realtime can return typed error messages over the WebSocket. The adapter normalizes them all toLiveError events. Check $event->code to branch on specific conditions.
LiveError:
| Code | Description |
|---|---|
auth_error | Invalid or missing API key |
quota_exceeded | Account quota exhausted |
transcriber_error | Internal Scribe processing error |
input_error | Malformed audio input |
error | Generic error |
commit_throttled | Commit rate exceeded |
unaccepted_terms | Terms of service not accepted |
rate_limited | Request rate too high |
queue_overflow | Session queue is full |
resource_exhausted | Server resource limit reached |
session_time_limit_exceeded | Maximum session duration reached |
chunk_size_exceeded | Audio chunk too large |
insufficient_audio_activity | Not enough audio to produce a transcript |
Client-Secret Flow for Browser Connections
For browser-based applications, you should never expose your workspace API key to client-side JavaScript. Instead, your server generates a short-lived single-use token and returns only its value to authenticated clients. The browser then connects directly to ElevenLabs using that token.Server: Generate a Token
Call.clientSecret() on the builder instead of .connect(). It returns a ClientSecret object with a value string and an expiresAt Unix timestamp (15 minutes from creation).
Browser: Connect with the Token
The browser receives the token and constructs a WebSocket URL directly to ElevenLabs. Thexi-api-key header is never used in client-side code.
