|
| 1 | +--- |
| 2 | +title: ElevenLabs |
| 3 | +description: Learn how to use the ElevenLabs provider for the AI SDK. |
| 4 | +--- |
| 5 | + |
| 6 | +# ElevenLabs Provider |
| 7 | + |
| 8 | +The [ElevenLabs](https://elevenlabs.io/) provider contains language model support for the ElevenLabs transcription API. |
| 9 | + |
| 10 | +## Setup |
| 11 | + |
| 12 | +The ElevenLabs provider is available in the `@ai-sdk/elevenlabs` module. You can install it with |
| 13 | + |
| 14 | +<Tabs items={['pnpm', 'npm', 'yarn']}> |
| 15 | + <Tab> |
| 16 | + <Snippet text="pnpm add @ai-sdk/elevenlabs" dark /> |
| 17 | + </Tab> |
| 18 | + <Tab> |
| 19 | + <Snippet text="npm install @ai-sdk/elevenlabs" dark /> |
| 20 | + </Tab> |
| 21 | + <Tab> |
| 22 | + <Snippet text="yarn add @ai-sdk/elevenlabs" dark /> |
| 23 | + </Tab> |
| 24 | +</Tabs> |
| 25 | + |
| 26 | +## Provider Instance |
| 27 | + |
| 28 | +You can import the default provider instance `elevenlabs` from `@ai-sdk/elevenlabs`: |
| 29 | + |
| 30 | +```ts |
| 31 | +import { elevenlabs } from '@ai-sdk/elevenlabs'; |
| 32 | +``` |
| 33 | + |
| 34 | +If you need a customized setup, you can import `createElevenLabs` from `@ai-sdk/elevenlabs` and create a provider instance with your settings: |
| 35 | + |
| 36 | +```ts |
| 37 | +import { createElevenLabs } from '@ai-sdk/elevenlabs'; |
| 38 | + |
| 39 | +const elevenlabs = createElevenLabs({ |
| 40 | + // custom settings, e.g. |
| 41 | + fetch: customFetch, |
| 42 | +}); |
| 43 | +``` |
| 44 | + |
| 45 | +You can use the following optional settings to customize the ElevenLabs provider instance: |
| 46 | + |
| 47 | +- **apiKey** _string_ |
| 48 | + |
| 49 | + API key that is being sent using the `Authorization` header. |
| 50 | + It defaults to the `ELEVENLABS_API_KEY` environment variable. |
| 51 | + |
| 52 | +- **headers** _Record<string,string>_ |
| 53 | + |
| 54 | + Custom headers to include in the requests. |
| 55 | + |
| 56 | +- **fetch** _(input: RequestInfo, init?: RequestInit) => Promise<Response>_ |
| 57 | + |
| 58 | + Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation. |
| 59 | + Defaults to the global `fetch` function. |
| 60 | + You can use it as a middleware to intercept requests, |
| 61 | + or to provide a custom fetch implementation for e.g. testing. |
| 62 | + |
| 63 | +## Transcription Models |
| 64 | + |
| 65 | +You can create models that call the [ElevenLabs transcription API](https://elevenlabs.io/speech-to-text) |
| 66 | +using the `.transcription()` factory method. |
| 67 | + |
| 68 | +The first argument is the model id e.g. `scribe_v1`. |
| 69 | + |
| 70 | +```ts |
| 71 | +const model = elevenlabs.transcription('scribe_v1'); |
| 72 | +``` |
| 73 | + |
| 74 | +You can also pass additional provider-specific options using the `providerOptions` argument. For example, supplying the input language in ISO-639-1 (e.g. `en`) format can sometimes improve transcription performance if known beforehand. |
| 75 | + |
| 76 | +```ts highlight="6" |
| 77 | +import { experimental_transcribe as transcribe } from 'ai'; |
| 78 | +import { elevenlabs } from '@ai-sdk/elevenlabs'; |
| 79 | + |
| 80 | +const result = await transcribe({ |
| 81 | + model: elevenlabs.transcription('scribe_v1'), |
| 82 | + audio: new Uint8Array([1, 2, 3, 4]), |
| 83 | + providerOptions: { elevenlabs: { languageCode: 'en' } }, |
| 84 | +}); |
| 85 | +``` |
| 86 | + |
| 87 | +The following provider options are available: |
| 88 | + |
| 89 | +- **languageCode** _string_ |
| 90 | + |
| 91 | + An ISO-639-1 or ISO-639-3 language code corresponding to the language of the audio file. |
| 92 | + Can sometimes improve transcription performance if known beforehand. |
| 93 | + Defaults to `null`, in which case the language is predicted automatically. |
| 94 | + |
| 95 | +- **tagAudioEvents** _boolean_ |
| 96 | + |
| 97 | + Whether to tag audio events like (laughter), (footsteps), etc. in the transcription. |
| 98 | + Defaults to `true`. |
| 99 | + |
| 100 | +- **numSpeakers** _integer_ |
| 101 | + |
| 102 | + The maximum amount of speakers talking in the uploaded file. |
| 103 | + Can help with predicting who speaks when. |
| 104 | + The maximum amount of speakers that can be predicted is 32. |
| 105 | + Defaults to `null`, in which case the amount of speakers is set to the maximum value the model supports. |
| 106 | + |
| 107 | +- **timestampsGranularity** _enum_ |
| 108 | + |
| 109 | + The granularity of the timestamps in the transcription. |
| 110 | + Defaults to `'word'`. |
| 111 | + Allowed values: `'none'`, `'word'`, `'character'`. |
| 112 | + |
| 113 | +- **diarize** _boolean_ |
| 114 | + |
| 115 | + Whether to annotate which speaker is currently talking in the uploaded file. |
| 116 | + Defaults to `true`. |
| 117 | + |
| 118 | +- **fileFormat** _enum_ |
| 119 | + |
| 120 | + The format of input audio. |
| 121 | + Defaults to `'other'`. |
| 122 | + Allowed values: `'pcm_s16le_16'`, `'other'`. |
| 123 | + For `'pcm_s16le_16'`, the input audio must be 16-bit PCM at a 16kHz sample rate, single channel (mono), and little-endian byte order. |
| 124 | + Latency will be lower than with passing an encoded waveform. |
| 125 | + |
| 126 | +### Model Capabilities |
| 127 | + |
| 128 | +| Model | Transcription | Duration | Segments | Language | |
| 129 | +| ------------------------ | ------------------- | ------------------- | ------------------- | ------------------- | |
| 130 | +| `scribe_v1` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | |
| 131 | +| `scribe_v1_experimental` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | |
0 commit comments