React SDK
useScribe: real-time speech-to-text transcription in React
useScribe: real-time speech-to-text transcription in React
For an overview of Scribe and its capabilities, see the Speech to Text overview. For step-by-step usage guides, see Client-side streaming.
Use the ElevenLabs speech-to-text skill to transcribe audio from your AI coding assistant:
@elevenlabs/react re-exports everything from @elevenlabs/client, so you don’t need to install
both packages.
Here is a minimal working example that connects to Scribe and displays real-time transcription:
Scribe requires a single-use token for authentication. Create an API endpoint on your server:
Your ElevenLabs API key is sensitive. Never expose it to the client. Always generate the token on the server.
Configure the hook with default options and callbacks:
These options control when transcripts are automatically committed when using the VAD commit strategy.
The microphone object accepts:
All event callbacks are optional and can be provided as hook options:
{ text: string }.{ text: string }.{ text: string; words?: { start: number; end: number }[] }.Error | Event.{ error: string }.The generic onError callback fires for all errors. Specific error callbacks are also available for granular handling. All specific error callbacks receive { error: string }.
Stream audio directly from the user’s microphone:
Transcribe pre-recorded audio files:
"disconnected", "connecting", "connected", "transcribing", or "error".TranscriptSegment objects (see below).null.Each committed transcript segment has the following structure:
Connect to Scribe. Options provided here override hook defaults:
Disconnect and clean up resources:
Send audio data (manual mode only):
The previousText field can only be sent in the first audio chunk of a session. Sending it in
subsequent chunks results in an error.
Manually commit the current transcription:
Clear all transcripts from state:
Get the underlying connection instance:
Control when transcriptions are committed:
For more details, see Transcripts and commit strategies.
Here is a complete example of a React component using the useScribe hook with VAD-based commit strategy: