@micdrop/elevenlabs 1.2.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @micdrop/elevenlabs
2
2
 
3
- [Micdrop website](https://micdrop.dev) | [Documentation](https://micdrop.dev/docs/ai-integration/provided-integrations/elevenlabs)
3
+ [Micdrop website](https://micdrop.dev) | [Documentation](https://micdrop.dev/docs/text-to-speech/elevenlabs)
4
4
 
5
5
  `@micdrop/elevenlabs` streams ElevenLabs text to speech for [@micdrop/server](https://micdrop.dev/docs/server). It works with Eleven v4 Turbo, Eleven v4, Eleven v3, Flash v2.5, Turbo v2.5 and Multilingual v2, and picks the WebSocket each model needs.
6
6
 
@@ -23,6 +23,7 @@ const tts = new ElevenLabsTTS({
23
23
  voiceId: '21m00Tcm4TlvDq8ikWAM', // ElevenLabs voice ID
24
24
  modelId: 'eleven_v4_turbo', // Optional: model to use
25
25
  language: 'en', // Optional: language code
26
+ sampleRate: 24000, // Optional: 48000 by default
26
27
  voiceSettings: {
27
28
  stability: 0.5,
28
29
  },
@@ -46,7 +47,7 @@ const tts = new ElevenLabsTTS({
46
47
  voiceId: '21m00Tcm4TlvDq8ikWAM',
47
48
  })
48
49
 
49
- // Audio is raw PCM, 16 bits, 16 kHz, mono
50
+ // Audio is raw PCM, 16 bits, mono, at tts.sampleRate
50
51
  tts.on('Audio', (chunk) => console.log('Audio:', chunk.length, 'bytes'))
51
52
  tts.on('Failed', (texts) => console.error('Failed:', texts))
52
53
 
@@ -55,12 +56,12 @@ tts.speak(Readable.from(['Hello! ', 'What can I do for you?']))
55
56
 
56
57
  ### Events
57
58
 
58
- | Event | Payload | Description |
59
- | -------- | ---------- | ------------------------------------------------------------------------ |
60
- | `Audio` | `Buffer` | A chunk of audio, PCM 16 bits, 16 kHz, mono, ready to be played. |
61
- | `Failed` | `string[]` | The text left unspoken when `ElevenLabsTTS` gives up after its retries. |
59
+ | Event | Payload | Description |
60
+ | -------- | ---------- | -------------------------------------------------------------------------------------------------------------------------- |
61
+ | `Audio` | `Buffer` | A chunk of audio, PCM 16 bits, mono, at `tts.sampleRate` (the `sampleRate` option, 48 kHz by default), ready to be played. |
62
+ | `Failed` | `string[]` | The text left unspoken when `ElevenLabsTTS` gives up after its retries. |
62
63
 
63
- See the [TTS interface](https://micdrop.dev/docs/ai-integration/custom-integrations/custom-tts) for the full contract.
64
+ See the [TTS interface](https://micdrop.dev/docs/text-to-speech/custom) for the full contract.
64
65
 
65
66
  ### Models
66
67
 
@@ -77,7 +78,7 @@ ElevenLabs counts each open connection to the Text to Dialogue WebSocket as one
77
78
 
78
79
  ## Documentation
79
80
 
80
- Read full [documentation of the ElevenLabs integration for Micdrop](https://micdrop.dev/docs/ai-integration/provided-integrations/elevenlabs) on the [website](https://micdrop.dev).
81
+ Read full [documentation of the ElevenLabs integration for Micdrop](https://micdrop.dev/docs/text-to-speech/elevenlabs) on the [website](https://micdrop.dev).
81
82
 
82
83
  ## License
83
84
 
package/dist/index.d.mts CHANGED
@@ -1,13 +1,24 @@
1
- import { TTS } from '@micdrop/server';
1
+ import { TTS, MicdropModel, MicdropVoice } from '@micdrop/server';
2
2
  import { Readable } from 'stream';
3
3
  import { TextToSpeechStreamRequestOutputFormat, VoiceSettings } from '@elevenlabs/elevenlabs-js/api';
4
4
 
5
5
  type ElevenLabsModelId = 'eleven_v4_turbo' | 'eleven_v4' | 'eleven_v3_conversational' | 'eleven_v3' | 'eleven_flash_v2_5' | 'eleven_multilingual_v2' | 'eleven_turbo_v2_5';
6
+ /** Rates ElevenLabs streams raw PCM at. 44100 needs a Pro plan or above. */
7
+ type ElevenLabsSampleRate = 8000 | 16000 | 22050 | 24000 | 32000 | 44100 | 48000;
6
8
  interface ElevenLabsTTSOptions {
7
9
  apiKey: string;
8
10
  voiceId: string;
9
11
  modelId?: ElevenLabsModelId;
10
12
  language?: string;
13
+ /**
14
+ * Rate of the audio, in Hz, 48000 by default, the highest one offered. It
15
+ * goes to the client as is, so the voice is never resampled on the server.
16
+ */
17
+ sampleRate?: ElevenLabsSampleRate;
18
+ /**
19
+ * @deprecated Use `sampleRate`. The client only plays raw PCM, so only the
20
+ * `pcm_*` formats work.
21
+ */
11
22
  outputFormat?: TextToSpeechStreamRequestOutputFormat;
12
23
  voiceSettings?: VoiceSettings;
13
24
  connectionTimeout?: number;
@@ -15,7 +26,13 @@ interface ElevenLabsTTSOptions {
15
26
  maxRetry?: number;
16
27
  }
17
28
  declare const DEFAULT_MODEL_ID = "eleven_turbo_v2_5";
18
- declare const DEFAULT_OUTPUT_FORMAT = "pcm_16000";
29
+ declare const DEFAULT_SAMPLE_RATE: ElevenLabsSampleRate;
30
+ /** @deprecated Use `DEFAULT_SAMPLE_RATE` */
31
+ declare const DEFAULT_OUTPUT_FORMAT = "pcm_48000";
32
+ /** The `output_format` asked of ElevenLabs */
33
+ declare function getOutputFormat(options: ElevenLabsTTSOptions): TextToSpeechStreamRequestOutputFormat;
34
+ /** Rate of the audio ElevenLabs sends, read from its `output_format` */
35
+ declare function getSampleRate(options: ElevenLabsTTSOptions): number;
19
36
  /** Eleven v3 and v4 only run on the Text to Dialogue WebSocket */
20
37
  declare function isDialogueModel(modelId: string): boolean;
21
38
  type ElevenLabsWebSocketMessage = ElevenLabsWebSocketAudioOutputMessage | ElevenLabsWebSocketFinalOutputMessage | ElevenLabsWebSocketErrorMessage;
@@ -68,11 +85,37 @@ type ElevenLabsDialogueMessage = {
68
85
  * so the model picks the one this class drives.
69
86
  */
70
87
  declare class ElevenLabsTTS extends TTS {
88
+ /**
89
+ * Lists the models that speak, with the languages each one reads.
90
+ *
91
+ * The list is fetched once and shared by every call of the process for a
92
+ * day. `refresh` fetches it again.
93
+ */
94
+ static listModels(options: {
95
+ apiKey: string;
96
+ refresh?: boolean;
97
+ }): Promise<MicdropModel[]>;
98
+ /**
99
+ * Lists the voices the account can speak with: the premade ones, and the
100
+ * ones cloned, designed or added from the library.
101
+ *
102
+ * `language`, such as `fr` or `fr-FR`, keeps the voices that speak it.
103
+ *
104
+ * The list is fetched once and shared by every call of the process for a
105
+ * day. `refresh` fetches it again, for a voice added a moment ago.
106
+ */
107
+ static listVoices(options: {
108
+ apiKey: string;
109
+ language?: string;
110
+ refresh?: boolean;
111
+ }): Promise<MicdropVoice[]>;
71
112
  private readonly webSocket;
113
+ private readonly rate;
72
114
  constructor(options: ElevenLabsTTSOptions);
115
+ get sampleRate(): number;
73
116
  speak(textStream: Readable): void;
74
117
  cancel(): void;
75
118
  destroy(): void;
76
119
  }
77
120
 
78
- export { DEFAULT_MODEL_ID, DEFAULT_OUTPUT_FORMAT, type ElevenLabsDialogueClientMessage, type ElevenLabsDialogueInput, type ElevenLabsDialogueMessage, type ElevenLabsModelId, ElevenLabsTTS, type ElevenLabsTTSOptions, type ElevenLabsWebSocketAudioOutputMessage, type ElevenLabsWebSocketAudioOutputMessageAlignment, type ElevenLabsWebSocketErrorMessage, type ElevenLabsWebSocketFinalOutputMessage, type ElevenLabsWebSocketMessage, isDialogueModel };
121
+ export { DEFAULT_MODEL_ID, DEFAULT_OUTPUT_FORMAT, DEFAULT_SAMPLE_RATE, type ElevenLabsDialogueClientMessage, type ElevenLabsDialogueInput, type ElevenLabsDialogueMessage, type ElevenLabsModelId, type ElevenLabsSampleRate, ElevenLabsTTS, type ElevenLabsTTSOptions, type ElevenLabsWebSocketAudioOutputMessage, type ElevenLabsWebSocketAudioOutputMessageAlignment, type ElevenLabsWebSocketErrorMessage, type ElevenLabsWebSocketFinalOutputMessage, type ElevenLabsWebSocketMessage, getOutputFormat, getSampleRate, isDialogueModel };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,24 @@
1
- import { TTS } from '@micdrop/server';
1
+ import { TTS, MicdropModel, MicdropVoice } from '@micdrop/server';
2
2
  import { Readable } from 'stream';
3
3
  import { TextToSpeechStreamRequestOutputFormat, VoiceSettings } from '@elevenlabs/elevenlabs-js/api';
4
4
 
5
5
  type ElevenLabsModelId = 'eleven_v4_turbo' | 'eleven_v4' | 'eleven_v3_conversational' | 'eleven_v3' | 'eleven_flash_v2_5' | 'eleven_multilingual_v2' | 'eleven_turbo_v2_5';
6
+ /** Rates ElevenLabs streams raw PCM at. 44100 needs a Pro plan or above. */
7
+ type ElevenLabsSampleRate = 8000 | 16000 | 22050 | 24000 | 32000 | 44100 | 48000;
6
8
  interface ElevenLabsTTSOptions {
7
9
  apiKey: string;
8
10
  voiceId: string;
9
11
  modelId?: ElevenLabsModelId;
10
12
  language?: string;
13
+ /**
14
+ * Rate of the audio, in Hz, 48000 by default, the highest one offered. It
15
+ * goes to the client as is, so the voice is never resampled on the server.
16
+ */
17
+ sampleRate?: ElevenLabsSampleRate;
18
+ /**
19
+ * @deprecated Use `sampleRate`. The client only plays raw PCM, so only the
20
+ * `pcm_*` formats work.
21
+ */
11
22
  outputFormat?: TextToSpeechStreamRequestOutputFormat;
12
23
  voiceSettings?: VoiceSettings;
13
24
  connectionTimeout?: number;
@@ -15,7 +26,13 @@ interface ElevenLabsTTSOptions {
15
26
  maxRetry?: number;
16
27
  }
17
28
  declare const DEFAULT_MODEL_ID = "eleven_turbo_v2_5";
18
- declare const DEFAULT_OUTPUT_FORMAT = "pcm_16000";
29
+ declare const DEFAULT_SAMPLE_RATE: ElevenLabsSampleRate;
30
+ /** @deprecated Use `DEFAULT_SAMPLE_RATE` */
31
+ declare const DEFAULT_OUTPUT_FORMAT = "pcm_48000";
32
+ /** The `output_format` asked of ElevenLabs */
33
+ declare function getOutputFormat(options: ElevenLabsTTSOptions): TextToSpeechStreamRequestOutputFormat;
34
+ /** Rate of the audio ElevenLabs sends, read from its `output_format` */
35
+ declare function getSampleRate(options: ElevenLabsTTSOptions): number;
19
36
  /** Eleven v3 and v4 only run on the Text to Dialogue WebSocket */
20
37
  declare function isDialogueModel(modelId: string): boolean;
21
38
  type ElevenLabsWebSocketMessage = ElevenLabsWebSocketAudioOutputMessage | ElevenLabsWebSocketFinalOutputMessage | ElevenLabsWebSocketErrorMessage;
@@ -68,11 +85,37 @@ type ElevenLabsDialogueMessage = {
68
85
  * so the model picks the one this class drives.
69
86
  */
70
87
  declare class ElevenLabsTTS extends TTS {
88
+ /**
89
+ * Lists the models that speak, with the languages each one reads.
90
+ *
91
+ * The list is fetched once and shared by every call of the process for a
92
+ * day. `refresh` fetches it again.
93
+ */
94
+ static listModels(options: {
95
+ apiKey: string;
96
+ refresh?: boolean;
97
+ }): Promise<MicdropModel[]>;
98
+ /**
99
+ * Lists the voices the account can speak with: the premade ones, and the
100
+ * ones cloned, designed or added from the library.
101
+ *
102
+ * `language`, such as `fr` or `fr-FR`, keeps the voices that speak it.
103
+ *
104
+ * The list is fetched once and shared by every call of the process for a
105
+ * day. `refresh` fetches it again, for a voice added a moment ago.
106
+ */
107
+ static listVoices(options: {
108
+ apiKey: string;
109
+ language?: string;
110
+ refresh?: boolean;
111
+ }): Promise<MicdropVoice[]>;
71
112
  private readonly webSocket;
113
+ private readonly rate;
72
114
  constructor(options: ElevenLabsTTSOptions);
115
+ get sampleRate(): number;
73
116
  speak(textStream: Readable): void;
74
117
  cancel(): void;
75
118
  destroy(): void;
76
119
  }
77
120
 
78
- export { DEFAULT_MODEL_ID, DEFAULT_OUTPUT_FORMAT, type ElevenLabsDialogueClientMessage, type ElevenLabsDialogueInput, type ElevenLabsDialogueMessage, type ElevenLabsModelId, ElevenLabsTTS, type ElevenLabsTTSOptions, type ElevenLabsWebSocketAudioOutputMessage, type ElevenLabsWebSocketAudioOutputMessageAlignment, type ElevenLabsWebSocketErrorMessage, type ElevenLabsWebSocketFinalOutputMessage, type ElevenLabsWebSocketMessage, isDialogueModel };
121
+ export { DEFAULT_MODEL_ID, DEFAULT_OUTPUT_FORMAT, DEFAULT_SAMPLE_RATE, type ElevenLabsDialogueClientMessage, type ElevenLabsDialogueInput, type ElevenLabsDialogueMessage, type ElevenLabsModelId, type ElevenLabsSampleRate, ElevenLabsTTS, type ElevenLabsTTSOptions, type ElevenLabsWebSocketAudioOutputMessage, type ElevenLabsWebSocketAudioOutputMessageAlignment, type ElevenLabsWebSocketErrorMessage, type ElevenLabsWebSocketFinalOutputMessage, type ElevenLabsWebSocketMessage, getOutputFormat, getSampleRate, isDialogueModel };