@mastra/voice-elevenlabs 0.10.6 → 0.10.7

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/dist/index.cjs CHANGED
@@ -155,3 +155,5 @@ var ElevenLabsVoice = class extends voice.MastraVoice {
155
155
  };
156
156
 
157
157
  exports.ElevenLabsVoice = ElevenLabsVoice;
158
+ //# sourceMappingURL=index.cjs.map
159
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["MastraVoice","ElevenLabsClient","buffer","File"],"mappings":";;;;;;;AAmCO,IAAM,eAAA,GAAN,cAA8BA,iBAAA,CAAY;AAAA,EACvC,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWR,WAAA,CAAY;AAAA,IACV,WAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACF,GAAuG,EAAC,EAAG;AACzG,IAAA,MAAM,MAAA,GAAS,WAAA,EAAa,MAAA,IAAU,OAAA,CAAQ,GAAA,CAAI,kBAAA;AAClD,IAAA,KAAA,CAAM;AAAA,MACJ,WAAA,EAAa;AAAA,QACX,IAAA,EAAM,aAAa,IAAA,IAAQ,wBAAA;AAAA,QAC3B,QAAQ,WAAA,EAAa;AAAA,OACvB;AAAA,MACA,cAAA,EAAgB;AAAA,QACd,IAAA,EAAM,gBAAgB,IAAA,IAAQ,WAAA;AAAA,QAC9B,QAAQ,cAAA,EAAgB;AAAA,OAC1B;AAAA,MACA;AAAA,KACD,CAAA;AAED,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAM,IAAI,MAAM,+BAA+B,CAAA;AAAA,IACjD;AAEA,IAAA,IAAA,CAAK,MAAA,GAAS,IAAIC,2BAAA,CAAiB;AAAA,MACjC;AAAA,KACD,CAAA;AAED,IAAA,IAAA,CAAK,UAAU,OAAA,IAAW,sBAAA;AAAA,EAC5B;AAAA;A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AAA,QACnB;AAAA,MACF;AACA,MAAA,MAAMC,QAAA,GAAS,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA;AAEnC,MAAA,MAAM,EAAE,eAAe,gBAAA,EAAkB,YAAA,EAAc,UAAU,GAAG,cAAA,EAAe,GAAI,OAAA,IAAW,EAAC;AAEnG,MAAA,MAAM,IAAA,GAAO,IAAIC,WAAA,CAAK,CAACD,QAAM,CAAA,EAAG,CAAA,MAAA,EAAS,QAAA,IAAY,KAAK,CAAA,CAAE,CAAA;AAE5D,MAAA,MAAM,aAAA,GAAgB,MAAM,IAAA,CAAK,MAAA,CAAO,YAAA,CAAa,OAAA;AAAA,QACnD;AAAA,UACE,IAAA;AAAA,UACA,QAAA,EAAU,KAAK,cAAA,EAAgB,IAAA;AAAA,UAC/B,aAAA;AAAA,UACA,gBAAA;AAAA,UACA;AAAA,SACF;AAAA,QACA;AAAA,OACF;AAEA,MAAA,OAAO,aAAA,CAAc,IAAA;AAAA,IACvB,CAAA,EAAG,yBAAyB,CAAA,EAAE;AAE9B,IAAA,OAAO,GAAA;AAAA,EACT;AACF","file":"index.cjs","sourcesContent":["import { File } from 'node:buffer';\nimport { MastraVoice } from '@mastra/core/voice';\nimport { ElevenLabsClient } from 'elevenlabs';\n\ntype ElevenLabsModel =\n | 'eleven_multilingual_v2'\n | 'eleven_flash_v2_5'\n | 'eleven_flash_v2'\n | 'eleven_multilingual_sts_v2'\n | 'eleven_english_sts_v2'\n | 'scribe_v1';\n\ninterface ElevenLabsVoiceConfig {\n name?: ElevenLabsModel;\n apiKey?: string;\n}\n\ninterface SpeechToTextOptions {\n language_code?: string;\n tag_audio_events?: boolean;\n num_speakers?: number;\n filetype?: string;\n}\n\ninterface RequestOptions {\n timeoutInSeconds?: number;\n maxRetries?: number;\n abortSignal?: AbortSignal;\n apiKey?: string | undefined;\n headers?: Record<string, string>;\n}\n\n// Combined options type\ntype ElevenLabsListenOptions = SpeechToTextOptions & RequestOptions;\n\nexport class ElevenLabsVoice extends MastraVoice {\n private client: ElevenLabsClient;\n\n /**\n * Creates an instance of the ElevenLabsVoice class.\n *\n * @param {Object} options - The options for the voice configuration.\n * @param {ElevenLabsVoiceConfig} [options.speechModel] - The configuration for the speech model, including the model name and API key.\n * @param {string} [options.speaker] - The ID of the speaker to use. If not provided, a default speaker will be used.\n *\n * @throws {Error} If the ELEVENLABS_API_KEY is not set in the environment variables.\n */\n constructor({\n speechModel,\n listeningModel,\n speaker,\n }: { speechModel?: ElevenLabsVoiceConfig; listeningModel?: ElevenLabsVoiceConfig; speaker?: string } = {}) {\n const apiKey = speechModel?.apiKey ?? process.env.ELEVENLABS_API_KEY;\n super({\n speechModel: {\n name: speechModel?.name ?? 'eleven_multilingual_v2',\n apiKey: speechModel?.apiKey,\n },\n listeningModel: {\n name: listeningModel?.name ?? 'scribe_v1',\n apiKey: listeningModel?.apiKey,\n },\n speaker,\n });\n\n if (!apiKey) {\n throw new Error('ELEVENLABS_API_KEY is not set');\n }\n\n this.client = new ElevenLabsClient({\n apiKey,\n });\n\n this.speaker = speaker || '9BWtsMINqrJLrRacOk9x'; // Aria is the default speaker\n }\n\n /**\n * Retrieves a list of available speakers from the Eleven Labs API.\n * Each speaker includes their ID, name, language, and gender.\n *\n * @returns {Promise<Array<{ voiceId: string, name: string, language: string, gender: string }>>}\n * A promise that resolves to an array of speaker objects.\n */\n async getSpeakers() {\n const res = await this.traced(async () => {\n const voices = await this.client.voices.getAll();\n return (\n voices?.voices?.map(voice => ({\n voiceId: voice.voice_id,\n name: voice.name,\n language: voice.labels?.language || 'en',\n gender: voice.labels?.gender || 'neutral',\n })) ?? []\n );\n }, 'voice.elevenlabs.voices')();\n\n return res;\n }\n\n private async streamToString(stream: NodeJS.ReadableStream): Promise<string> {\n const chunks: Buffer[] = [];\n for await (const chunk of stream) {\n if (typeof chunk === 'string') {\n chunks.push(Buffer.from(chunk));\n } else {\n chunks.push(chunk);\n }\n }\n return Buffer.concat(chunks).toString('utf-8');\n }\n\n /**\n * Converts text or audio input into speech using the Eleven Labs API.\n *\n * @param {string | NodeJS.ReadableStream} input - The text to be converted to speech or a stream containing audio data.\n * @param {Object} [options] - Optional parameters for the speech generation.\n * @param {string} [options.speaker] - The ID of the speaker to use for the speech. If not provided, the default speaker will be used.\n *\n * @returns {Promise<NodeJS.ReadableStream>} A promise that resolves to a readable stream of the generated speech.\n *\n * @throws {Error} If no speaker is specified or if no speech model is set.\n */\n async speak(input: string | NodeJS.ReadableStream, options?: { speaker?: string }): Promise<NodeJS.ReadableStream> {\n const speaker = options?.speaker || this.speaker;\n if (!speaker) {\n throw new Error('No speaker specified');\n }\n\n if (!this.speechModel?.name) {\n throw new Error('No speech model specified');\n }\n const text = typeof input === 'string' ? input : await this.streamToString(input);\n const res = await this.traced(async () => {\n return await this.client.generate({\n text,\n voice: speaker,\n model_id: this.speechModel?.name as ElevenLabsModel,\n stream: true,\n });\n }, 'voice.elevenlabs.speak')();\n\n return res;\n }\n\n /**\n * Checks if listening capabilities are enabled.\n *\n * @returns {Promise<{ enabled: boolean }>}\n */\n async getListener() {\n return { enabled: true };\n }\n\n /**\n * Converts audio input to text using ElevenLabs Speech-to-Text API.\n *\n * @param input - A readable stream containing the audio data to transcribe\n * @param options - Configuration options for the transcription\n * @param options.language_code - ISO language code (e.g., 'en', 'fr', 'es')\n * @param options.tag_audio_events - Whether to tag audio events like [MUSIC], [LAUGHTER], etc.\n * @param options.num_speakers - Number of speakers to detect in the audio\n * @param options.filetype - Audio file format (e.g., 'mp3', 'wav', 'ogg')\n * @param options.timeoutInSeconds - Request timeout in seconds\n * @param options.maxRetries - Maximum number of retry attempts\n * @param options.abortSignal - Signal to abort the request\n *\n * @returns A Promise that resolves to the transcribed text\n *\n */\n async listen(input: NodeJS.ReadableStream, options?: ElevenLabsListenOptions): Promise<string> {\n const res = await this.traced(async () => {\n const chunks: Buffer[] = [];\n for await (const chunk of input) {\n if (typeof chunk === 'string') {\n chunks.push(Buffer.from(chunk));\n } else {\n chunks.push(chunk);\n }\n }\n const buffer = Buffer.concat(chunks);\n\n const { language_code, tag_audio_events, num_speakers, filetype, ...requestOptions } = options || {};\n\n const file = new File([buffer], `audio.${filetype || 'mp3'}`);\n\n const transcription = await this.client.speechToText.convert(\n {\n file: file,\n model_id: this.listeningModel?.name as ElevenLabsModel,\n language_code,\n tag_audio_events,\n num_speakers,\n },\n requestOptions,\n );\n\n return transcription.text;\n }, 'voice.elevenlabs.listen')();\n\n return res;\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1 +1,92 @@
1
- export { ElevenLabsVoice } from './_tsup-dts-rollup.js';
1
+ import { MastraVoice } from '@mastra/core/voice';
2
+ type ElevenLabsModel = 'eleven_multilingual_v2' | 'eleven_flash_v2_5' | 'eleven_flash_v2' | 'eleven_multilingual_sts_v2' | 'eleven_english_sts_v2' | 'scribe_v1';
3
+ interface ElevenLabsVoiceConfig {
4
+ name?: ElevenLabsModel;
5
+ apiKey?: string;
6
+ }
7
+ interface SpeechToTextOptions {
8
+ language_code?: string;
9
+ tag_audio_events?: boolean;
10
+ num_speakers?: number;
11
+ filetype?: string;
12
+ }
13
+ interface RequestOptions {
14
+ timeoutInSeconds?: number;
15
+ maxRetries?: number;
16
+ abortSignal?: AbortSignal;
17
+ apiKey?: string | undefined;
18
+ headers?: Record<string, string>;
19
+ }
20
+ type ElevenLabsListenOptions = SpeechToTextOptions & RequestOptions;
21
+ export declare class ElevenLabsVoice extends MastraVoice {
22
+ private client;
23
+ /**
24
+ * Creates an instance of the ElevenLabsVoice class.
25
+ *
26
+ * @param {Object} options - The options for the voice configuration.
27
+ * @param {ElevenLabsVoiceConfig} [options.speechModel] - The configuration for the speech model, including the model name and API key.
28
+ * @param {string} [options.speaker] - The ID of the speaker to use. If not provided, a default speaker will be used.
29
+ *
30
+ * @throws {Error} If the ELEVENLABS_API_KEY is not set in the environment variables.
31
+ */
32
+ constructor({ speechModel, listeningModel, speaker, }?: {
33
+ speechModel?: ElevenLabsVoiceConfig;
34
+ listeningModel?: ElevenLabsVoiceConfig;
35
+ speaker?: string;
36
+ });
37
+ /**
38
+ * Retrieves a list of available speakers from the Eleven Labs API.
39
+ * Each speaker includes their ID, name, language, and gender.
40
+ *
41
+ * @returns {Promise<Array<{ voiceId: string, name: string, language: string, gender: string }>>}
42
+ * A promise that resolves to an array of speaker objects.
43
+ */
44
+ getSpeakers(): Promise<{
45
+ voiceId: string;
46
+ name: string | undefined;
47
+ language: string;
48
+ gender: string;
49
+ }[]>;
50
+ private streamToString;
51
+ /**
52
+ * Converts text or audio input into speech using the Eleven Labs API.
53
+ *
54
+ * @param {string | NodeJS.ReadableStream} input - The text to be converted to speech or a stream containing audio data.
55
+ * @param {Object} [options] - Optional parameters for the speech generation.
56
+ * @param {string} [options.speaker] - The ID of the speaker to use for the speech. If not provided, the default speaker will be used.
57
+ *
58
+ * @returns {Promise<NodeJS.ReadableStream>} A promise that resolves to a readable stream of the generated speech.
59
+ *
60
+ * @throws {Error} If no speaker is specified or if no speech model is set.
61
+ */
62
+ speak(input: string | NodeJS.ReadableStream, options?: {
63
+ speaker?: string;
64
+ }): Promise<NodeJS.ReadableStream>;
65
+ /**
66
+ * Checks if listening capabilities are enabled.
67
+ *
68
+ * @returns {Promise<{ enabled: boolean }>}
69
+ */
70
+ getListener(): Promise<{
71
+ enabled: boolean;
72
+ }>;
73
+ /**
74
+ * Converts audio input to text using ElevenLabs Speech-to-Text API.
75
+ *
76
+ * @param input - A readable stream containing the audio data to transcribe
77
+ * @param options - Configuration options for the transcription
78
+ * @param options.language_code - ISO language code (e.g., 'en', 'fr', 'es')
79
+ * @param options.tag_audio_events - Whether to tag audio events like [MUSIC], [LAUGHTER], etc.
80
+ * @param options.num_speakers - Number of speakers to detect in the audio
81
+ * @param options.filetype - Audio file format (e.g., 'mp3', 'wav', 'ogg')
82
+ * @param options.timeoutInSeconds - Request timeout in seconds
83
+ * @param options.maxRetries - Maximum number of retry attempts
84
+ * @param options.abortSignal - Signal to abort the request
85
+ *
86
+ * @returns A Promise that resolves to the transcribed text
87
+ *
88
+ */
89
+ listen(input: NodeJS.ReadableStream, options?: ElevenLabsListenOptions): Promise<string>;
90
+ }
91
+ export {};
92
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,KAAK,eAAe,GAChB,wBAAwB,GACxB,mBAAmB,GACnB,iBAAiB,GACjB,4BAA4B,GAC5B,uBAAuB,GACvB,WAAW,CAAC;AAEhB,UAAU,qBAAqB;IAC7B,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,mBAAmB;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,cAAc;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAGD,KAAK,uBAAuB,GAAG,mBAAmB,GAAG,cAAc,CAAC;AAEpE,qBAAa,eAAgB,SAAQ,WAAW;IAC9C,OAAO,CAAC,MAAM,CAAmB;IAEjC;;;;;;;;OAQG;gBACS,EACV,WAAW,EACX,cAAc,EACd,OAAO,GACR,GAAE;QAAE,WAAW,CAAC,EAAE,qBAAqB,CAAC;QAAC,cAAc,CAAC,EAAE,qBAAqB,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO;IAyBzG;;;;;;OAMG;IACG,WAAW;;;;;;YAgBH,cAAc;IAY5B;;;;;;;;;;OAUG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;IAsBlH;;;;OAIG;IACG,WAAW;;;IAIjB;;;;;;;;;;;;;;;OAeG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC;CAgC/F"}
package/dist/index.js CHANGED
@@ -153,3 +153,5 @@ var ElevenLabsVoice = class extends MastraVoice {
153
153
  };
154
154
 
155
155
  export { ElevenLabsVoice };
156
+ //# sourceMappingURL=index.js.map
157
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAmCO,IAAM,eAAA,GAAN,cAA8B,WAAA,CAAY;AAAA,EACvC,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWR,WAAA,CAAY;AAAA,IACV,WAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACF,GAAuG,EAAC,EAAG;AACzG,IAAA,MAAM,MAAA,GAAS,WAAA,EAAa,MAAA,IAAU,OAAA,CAAQ,GAAA,CAAI,kBAAA;AAClD,IAAA,KAAA,CAAM;AAAA,MACJ,WAAA,EAAa;AAAA,QACX,IAAA,EAAM,aAAa,IAAA,IAAQ,wBAAA;AAAA,QAC3B,QAAQ,WAAA,EAAa;AAAA,OACvB;AAAA,MACA,cAAA,EAAgB;AAAA,QACd,IAAA,EAAM,gBAAgB,IAAA,IAAQ,WAAA;AAAA,QAC9B,QAAQ,cAAA,EAAgB;AAAA,OAC1B;AAAA,MACA;AAAA,KACD,CAAA;AAED,IAAA,IAAI,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B,MAAA,WAAA,MAAiB,SAAS,KAAA,EAAO;AAC/B,QAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,UAAA,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA,QAChC,CAAA,MAAO;AACL,UAAA,MAAA,CAAO,KAAK,KAAK,CAAA;AAAA,QACnB;AAAA,MACF;AACA,MAAA,MAAM,MAAA,GAAS,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA;AAEnC,MAAA,MAAM,EAAE,eAAe,gBAAA,EAAkB,YAAA,EAAc,UAAU,GAAG,cAAA,EAAe,GAAI,OAAA,IAAW,EAAC;AAEnG,MAAA,MAAM,IAAA,GAAO,IAAI,IAAA,CAAK,CAAC,MAAM,CAAA,EAAG,CAAA,MAAA,EAAS,QAAA,IAAY,KAAK,CAAA,CAAE,CAAA;AAE5D,MAAA,MAAM,aAAA,GAAgB,MAAM,IAAA,CAAK,MAAA,CAAO,YAAA,CAAa,OAAA;AAAA,QACnD;AAAA,UACE,IAAA;AAAA,UACA,QAAA,EAAU,KAAK,cAAA,EAAgB,IAAA;AAAA,UAC/B,aAAA;AAAA,UACA,gBAAA;AAAA,UACA;AAAA,SACF;AAAA,QACA;AAAA,OACF;AAEA,MAAA,OAAO,aAAA,CAAc,IAAA;AAAA,IACvB,CAAA,EAAG,yBAAyB,CAAA,EAAE;AAE9B,IAAA,OAAO,GAAA;AAAA,EACT;AACF","file":"index.js","sourcesContent":["import { File } from 'node:buffer';\nimport { MastraVoice } from '@mastra/core/voice';\nimport { ElevenLabsClient } from 'elevenlabs';\n\ntype ElevenLabsModel =\n | 'eleven_multilingual_v2'\n | 'eleven_flash_v2_5'\n | 'eleven_flash_v2'\n | 'eleven_multilingual_sts_v2'\n | 'eleven_english_sts_v2'\n | 'scribe_v1';\n\ninterface ElevenLabsVoiceConfig {\n name?: ElevenLabsModel;\n apiKey?: string;\n}\n\ninterface SpeechToTextOptions {\n language_code?: string;\n tag_audio_events?: boolean;\n num_speakers?: number;\n filetype?: string;\n}\n\ninterface RequestOptions {\n timeoutInSeconds?: number;\n maxRetries?: number;\n abortSignal?: AbortSignal;\n apiKey?: string | undefined;\n headers?: Record<string, string>;\n}\n\n// Combined options type\ntype ElevenLabsListenOptions = SpeechToTextOptions & RequestOptions;\n\nexport class ElevenLabsVoice extends MastraVoice {\n private client: ElevenLabsClient;\n\n /**\n * Creates an instance of the ElevenLabsVoice class.\n *\n * @param {Object} options - The options for the voice configuration.\n * @param {ElevenLabsVoiceConfig} [options.speechModel] - The configuration for the speech model, including the model name and API key.\n * @param {string} [options.speaker] - The ID of the speaker to use. If not provided, a default speaker will be used.\n *\n * @throws {Error} If the ELEVENLABS_API_KEY is not set in the environment variables.\n */\n constructor({\n speechModel,\n listeningModel,\n speaker,\n }: { speechModel?: ElevenLabsVoiceConfig; listeningModel?: ElevenLabsVoiceConfig; speaker?: string } = {}) {\n const apiKey = speechModel?.apiKey ?? process.env.ELEVENLABS_API_KEY;\n super({\n speechModel: {\n name: speechModel?.name ?? 'eleven_multilingual_v2',\n apiKey: speechModel?.apiKey,\n },\n listeningModel: {\n name: listeningModel?.name ?? 'scribe_v1',\n apiKey: listeningModel?.apiKey,\n },\n speaker,\n });\n\n if (!apiKey) {\n throw new Error('ELEVENLABS_API_KEY is not set');\n }\n\n this.client = new ElevenLabsClient({\n apiKey,\n });\n\n this.speaker = speaker || '9BWtsMINqrJLrRacOk9x'; // Aria is the default speaker\n }\n\n /**\n * Retrieves a list of available speakers from the Eleven Labs API.\n * Each speaker includes their ID, name, language, and gender.\n *\n * @returns {Promise<Array<{ voiceId: string, name: string, language: string, gender: string }>>}\n * A promise that resolves to an array of speaker objects.\n */\n async getSpeakers() {\n const res = await this.traced(async () => {\n const voices = await this.client.voices.getAll();\n return (\n voices?.voices?.map(voice => ({\n voiceId: voice.voice_id,\n name: voice.name,\n language: voice.labels?.language || 'en',\n gender: voice.labels?.gender || 'neutral',\n })) ?? []\n );\n }, 'voice.elevenlabs.voices')();\n\n return res;\n }\n\n private async streamToString(stream: NodeJS.ReadableStream): Promise<string> {\n const chunks: Buffer[] = [];\n for await (const chunk of stream) {\n if (typeof chunk === 'string') {\n chunks.push(Buffer.from(chunk));\n } else {\n chunks.push(chunk);\n }\n }\n return Buffer.concat(chunks).toString('utf-8');\n }\n\n /**\n * Converts text or audio input into speech using the Eleven Labs API.\n *\n * @param {string | NodeJS.ReadableStream} input - The text to be converted to speech or a stream containing audio data.\n * @param {Object} [options] - Optional parameters for the speech generation.\n * @param {string} [options.speaker] - The ID of the speaker to use for the speech. If not provided, the default speaker will be used.\n *\n * @returns {Promise<NodeJS.ReadableStream>} A promise that resolves to a readable stream of the generated speech.\n *\n * @throws {Error} If no speaker is specified or if no speech model is set.\n */\n async speak(input: string | NodeJS.ReadableStream, options?: { speaker?: string }): Promise<NodeJS.ReadableStream> {\n const speaker = options?.speaker || this.speaker;\n if (!speaker) {\n throw new Error('No speaker specified');\n }\n\n if (!this.speechModel?.name) {\n throw new Error('No speech model specified');\n }\n const text = typeof input === 'string' ? input : await this.streamToString(input);\n const res = await this.traced(async () => {\n return await this.client.generate({\n text,\n voice: speaker,\n model_id: this.speechModel?.name as ElevenLabsModel,\n stream: true,\n });\n }, 'voice.elevenlabs.speak')();\n\n return res;\n }\n\n /**\n * Checks if listening capabilities are enabled.\n *\n * @returns {Promise<{ enabled: boolean }>}\n */\n async getListener() {\n return { enabled: true };\n }\n\n /**\n * Converts audio input to text using ElevenLabs Speech-to-Text API.\n *\n * @param input - A readable stream containing the audio data to transcribe\n * @param options - Configuration options for the transcription\n * @param options.language_code - ISO language code (e.g., 'en', 'fr', 'es')\n * @param options.tag_audio_events - Whether to tag audio events like [MUSIC], [LAUGHTER], etc.\n * @param options.num_speakers - Number of speakers to detect in the audio\n * @param options.filetype - Audio file format (e.g., 'mp3', 'wav', 'ogg')\n * @param options.timeoutInSeconds - Request timeout in seconds\n * @param options.maxRetries - Maximum number of retry attempts\n * @param options.abortSignal - Signal to abort the request\n *\n * @returns A Promise that resolves to the transcribed text\n *\n */\n async listen(input: NodeJS.ReadableStream, options?: ElevenLabsListenOptions): Promise<string> {\n const res = await this.traced(async () => {\n const chunks: Buffer[] = [];\n for await (const chunk of input) {\n if (typeof chunk === 'string') {\n chunks.push(Buffer.from(chunk));\n } else {\n chunks.push(chunk);\n }\n }\n const buffer = Buffer.concat(chunks);\n\n const { language_code, tag_audio_events, num_speakers, filetype, ...requestOptions } = options || {};\n\n const file = new File([buffer], `audio.${filetype || 'mp3'}`);\n\n const transcription = await this.client.speechToText.convert(\n {\n file: file,\n model_id: this.listeningModel?.name as ElevenLabsModel,\n language_code,\n tag_audio_events,\n num_speakers,\n },\n requestOptions,\n );\n\n return transcription.text;\n }, 'voice.elevenlabs.listen')();\n\n return res;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/voice-elevenlabs",
3
- "version": "0.10.6",
3
+ "version": "0.10.7",
4
4
  "description": "Mastra ElevenLabs voice integration",
5
5
  "type": "module",
6
6
  "files": [
@@ -15,7 +15,7 @@
15
15
  "default": "./dist/index.js"
16
16
  },
17
17
  "require": {
18
- "types": "./dist/index.d.cts",
18
+ "types": "./dist/index.d.ts",
19
19
  "default": "./dist/index.cjs"
20
20
  }
21
21
  },
@@ -33,15 +33,16 @@
33
33
  "tsup": "^8.5.0",
34
34
  "typescript": "^5.8.3",
35
35
  "vitest": "^3.2.4",
36
- "@internal/lint": "0.0.24",
37
- "@mastra/core": "0.12.0"
36
+ "@internal/lint": "0.0.27",
37
+ "@mastra/core": "0.13.0",
38
+ "@internal/types-builder": "0.0.2"
38
39
  },
39
40
  "peerDependencies": {
40
- "@mastra/core": ">=0.10.7-0 <0.13.0-0"
41
+ "@mastra/core": ">=0.10.7-0 <0.14.0-0"
41
42
  },
42
43
  "scripts": {
43
- "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
44
- "build:watch": "tsup build --watch",
44
+ "build": "tsup --silent --config tsup.config.ts",
45
+ "build:watch": "tsup build --watch && tsc -p tsconfig.build.json",
45
46
  "test": "vitest run",
46
47
  "lint": "eslint ."
47
48
  }
@@ -1,98 +0,0 @@
1
- import { MastraVoice } from '@mastra/core/voice';
2
-
3
- declare type ElevenLabsListenOptions = SpeechToTextOptions & RequestOptions;
4
-
5
- declare type ElevenLabsModel = 'eleven_multilingual_v2' | 'eleven_flash_v2_5' | 'eleven_flash_v2' | 'eleven_multilingual_sts_v2' | 'eleven_english_sts_v2' | 'scribe_v1';
6
-
7
- export declare class ElevenLabsVoice extends MastraVoice {
8
- private client;
9
- /**
10
- * Creates an instance of the ElevenLabsVoice class.
11
- *
12
- * @param {Object} options - The options for the voice configuration.
13
- * @param {ElevenLabsVoiceConfig} [options.speechModel] - The configuration for the speech model, including the model name and API key.
14
- * @param {string} [options.speaker] - The ID of the speaker to use. If not provided, a default speaker will be used.
15
- *
16
- * @throws {Error} If the ELEVENLABS_API_KEY is not set in the environment variables.
17
- */
18
- constructor({ speechModel, listeningModel, speaker, }?: {
19
- speechModel?: ElevenLabsVoiceConfig;
20
- listeningModel?: ElevenLabsVoiceConfig;
21
- speaker?: string;
22
- });
23
- /**
24
- * Retrieves a list of available speakers from the Eleven Labs API.
25
- * Each speaker includes their ID, name, language, and gender.
26
- *
27
- * @returns {Promise<Array<{ voiceId: string, name: string, language: string, gender: string }>>}
28
- * A promise that resolves to an array of speaker objects.
29
- */
30
- getSpeakers(): Promise<{
31
- voiceId: string;
32
- name: string | undefined;
33
- language: string;
34
- gender: string;
35
- }[]>;
36
- private streamToString;
37
- /**
38
- * Converts text or audio input into speech using the Eleven Labs API.
39
- *
40
- * @param {string | NodeJS.ReadableStream} input - The text to be converted to speech or a stream containing audio data.
41
- * @param {Object} [options] - Optional parameters for the speech generation.
42
- * @param {string} [options.speaker] - The ID of the speaker to use for the speech. If not provided, the default speaker will be used.
43
- *
44
- * @returns {Promise<NodeJS.ReadableStream>} A promise that resolves to a readable stream of the generated speech.
45
- *
46
- * @throws {Error} If no speaker is specified or if no speech model is set.
47
- */
48
- speak(input: string | NodeJS.ReadableStream, options?: {
49
- speaker?: string;
50
- }): Promise<NodeJS.ReadableStream>;
51
- /**
52
- * Checks if listening capabilities are enabled.
53
- *
54
- * @returns {Promise<{ enabled: boolean }>}
55
- */
56
- getListener(): Promise<{
57
- enabled: boolean;
58
- }>;
59
- /**
60
- * Converts audio input to text using ElevenLabs Speech-to-Text API.
61
- *
62
- * @param input - A readable stream containing the audio data to transcribe
63
- * @param options - Configuration options for the transcription
64
- * @param options.language_code - ISO language code (e.g., 'en', 'fr', 'es')
65
- * @param options.tag_audio_events - Whether to tag audio events like [MUSIC], [LAUGHTER], etc.
66
- * @param options.num_speakers - Number of speakers to detect in the audio
67
- * @param options.filetype - Audio file format (e.g., 'mp3', 'wav', 'ogg')
68
- * @param options.timeoutInSeconds - Request timeout in seconds
69
- * @param options.maxRetries - Maximum number of retry attempts
70
- * @param options.abortSignal - Signal to abort the request
71
- *
72
- * @returns A Promise that resolves to the transcribed text
73
- *
74
- */
75
- listen(input: NodeJS.ReadableStream, options?: ElevenLabsListenOptions): Promise<string>;
76
- }
77
-
78
- declare interface ElevenLabsVoiceConfig {
79
- name?: ElevenLabsModel;
80
- apiKey?: string;
81
- }
82
-
83
- declare interface RequestOptions {
84
- timeoutInSeconds?: number;
85
- maxRetries?: number;
86
- abortSignal?: AbortSignal;
87
- apiKey?: string | undefined;
88
- headers?: Record<string, string>;
89
- }
90
-
91
- declare interface SpeechToTextOptions {
92
- language_code?: string;
93
- tag_audio_events?: boolean;
94
- num_speakers?: number;
95
- filetype?: string;
96
- }
97
-
98
- export { }
@@ -1,98 +0,0 @@
1
- import { MastraVoice } from '@mastra/core/voice';
2
-
3
- declare type ElevenLabsListenOptions = SpeechToTextOptions & RequestOptions;
4
-
5
- declare type ElevenLabsModel = 'eleven_multilingual_v2' | 'eleven_flash_v2_5' | 'eleven_flash_v2' | 'eleven_multilingual_sts_v2' | 'eleven_english_sts_v2' | 'scribe_v1';
6
-
7
- export declare class ElevenLabsVoice extends MastraVoice {
8
- private client;
9
- /**
10
- * Creates an instance of the ElevenLabsVoice class.
11
- *
12
- * @param {Object} options - The options for the voice configuration.
13
- * @param {ElevenLabsVoiceConfig} [options.speechModel] - The configuration for the speech model, including the model name and API key.
14
- * @param {string} [options.speaker] - The ID of the speaker to use. If not provided, a default speaker will be used.
15
- *
16
- * @throws {Error} If the ELEVENLABS_API_KEY is not set in the environment variables.
17
- */
18
- constructor({ speechModel, listeningModel, speaker, }?: {
19
- speechModel?: ElevenLabsVoiceConfig;
20
- listeningModel?: ElevenLabsVoiceConfig;
21
- speaker?: string;
22
- });
23
- /**
24
- * Retrieves a list of available speakers from the Eleven Labs API.
25
- * Each speaker includes their ID, name, language, and gender.
26
- *
27
- * @returns {Promise<Array<{ voiceId: string, name: string, language: string, gender: string }>>}
28
- * A promise that resolves to an array of speaker objects.
29
- */
30
- getSpeakers(): Promise<{
31
- voiceId: string;
32
- name: string | undefined;
33
- language: string;
34
- gender: string;
35
- }[]>;
36
- private streamToString;
37
- /**
38
- * Converts text or audio input into speech using the Eleven Labs API.
39
- *
40
- * @param {string | NodeJS.ReadableStream} input - The text to be converted to speech or a stream containing audio data.
41
- * @param {Object} [options] - Optional parameters for the speech generation.
42
- * @param {string} [options.speaker] - The ID of the speaker to use for the speech. If not provided, the default speaker will be used.
43
- *
44
- * @returns {Promise<NodeJS.ReadableStream>} A promise that resolves to a readable stream of the generated speech.
45
- *
46
- * @throws {Error} If no speaker is specified or if no speech model is set.
47
- */
48
- speak(input: string | NodeJS.ReadableStream, options?: {
49
- speaker?: string;
50
- }): Promise<NodeJS.ReadableStream>;
51
- /**
52
- * Checks if listening capabilities are enabled.
53
- *
54
- * @returns {Promise<{ enabled: boolean }>}
55
- */
56
- getListener(): Promise<{
57
- enabled: boolean;
58
- }>;
59
- /**
60
- * Converts audio input to text using ElevenLabs Speech-to-Text API.
61
- *
62
- * @param input - A readable stream containing the audio data to transcribe
63
- * @param options - Configuration options for the transcription
64
- * @param options.language_code - ISO language code (e.g., 'en', 'fr', 'es')
65
- * @param options.tag_audio_events - Whether to tag audio events like [MUSIC], [LAUGHTER], etc.
66
- * @param options.num_speakers - Number of speakers to detect in the audio
67
- * @param options.filetype - Audio file format (e.g., 'mp3', 'wav', 'ogg')
68
- * @param options.timeoutInSeconds - Request timeout in seconds
69
- * @param options.maxRetries - Maximum number of retry attempts
70
- * @param options.abortSignal - Signal to abort the request
71
- *
72
- * @returns A Promise that resolves to the transcribed text
73
- *
74
- */
75
- listen(input: NodeJS.ReadableStream, options?: ElevenLabsListenOptions): Promise<string>;
76
- }
77
-
78
- declare interface ElevenLabsVoiceConfig {
79
- name?: ElevenLabsModel;
80
- apiKey?: string;
81
- }
82
-
83
- declare interface RequestOptions {
84
- timeoutInSeconds?: number;
85
- maxRetries?: number;
86
- abortSignal?: AbortSignal;
87
- apiKey?: string | undefined;
88
- headers?: Record<string, string>;
89
- }
90
-
91
- declare interface SpeechToTextOptions {
92
- language_code?: string;
93
- tag_audio_events?: boolean;
94
- num_speakers?: number;
95
- filetype?: string;
96
- }
97
-
98
- export { }
package/dist/index.d.cts DELETED
@@ -1 +0,0 @@
1
- export { ElevenLabsVoice } from './_tsup-dts-rollup.cjs';