@mastra/voice-elevenlabs 0.1.1-alpha.1 → 0.1.1-alpha.3

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.
@@ -1,18 +1,23 @@
1
1
 
2
- > @mastra/voice-elevenlabs@0.1.1-alpha.1 build /home/runner/work/mastra/mastra/voice/elevenlabs
3
- > tsup src/index.ts --format esm --experimental-dts --clean --treeshake
2
+ > @mastra/voice-elevenlabs@0.1.1-alpha.3 build /home/runner/work/mastra/mastra/voice/elevenlabs
3
+ > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.3.6
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 8591ms
9
+ TSC ⚡️ Build success in 7812ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.7.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/voice/elevenlabs/dist/_tsup-dts-rollup.d.ts
14
- DTS ⚡️ Build success in 5735ms
14
+ Analysis will use the bundled TypeScript version 5.7.3
15
+ Writing package typings: /home/runner/work/mastra/mastra/voice/elevenlabs/dist/_tsup-dts-rollup.d.cts
16
+ DTS ⚡️ Build success in 8313ms
15
17
  CLI Cleaning output folder
16
18
  ESM Build start
19
+ CJS Build start
17
20
  ESM dist/index.js 5.00 KB
18
- ESM ⚡️ Build success in 286ms
21
+ ESM ⚡️ Build success in 582ms
22
+ CJS dist/index.cjs 5.04 KB
23
+ CJS ⚡️ Build success in 582ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @mastra/voice-elevenlabs
2
2
 
3
+ ## 0.1.1-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - bb4f447: Add support for commonjs
8
+ - Updated dependencies [0fd78ac]
9
+ - Updated dependencies [0d25b75]
10
+ - Updated dependencies [fd14a3f]
11
+ - Updated dependencies [3f369a2]
12
+ - Updated dependencies [4d4e1e1]
13
+ - Updated dependencies [bb4f447]
14
+ - @mastra/core@0.4.3-alpha.3
15
+
16
+ ## 0.1.1-alpha.2
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [2512a93]
21
+ - Updated dependencies [e62de74]
22
+ - @mastra/core@0.4.3-alpha.2
23
+
3
24
  ## 0.1.1-alpha.1
4
25
 
5
26
  ### Patch Changes
@@ -0,0 +1,90 @@
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
+ * Converts audio input to text using ElevenLabs Speech-to-Text API.
53
+ *
54
+ * @param input - A readable stream containing the audio data to transcribe
55
+ * @param options - Configuration options for the transcription
56
+ * @param options.language_code - ISO language code (e.g., 'en', 'fr', 'es')
57
+ * @param options.tag_audio_events - Whether to tag audio events like [MUSIC], [LAUGHTER], etc.
58
+ * @param options.num_speakers - Number of speakers to detect in the audio
59
+ * @param options.filetype - Audio file format (e.g., 'mp3', 'wav', 'ogg')
60
+ * @param options.timeoutInSeconds - Request timeout in seconds
61
+ * @param options.maxRetries - Maximum number of retry attempts
62
+ * @param options.abortSignal - Signal to abort the request
63
+ *
64
+ * @returns A Promise that resolves to the transcribed text
65
+ *
66
+ */
67
+ listen(input: NodeJS.ReadableStream, options?: ElevenLabsListenOptions): Promise<string>;
68
+ }
69
+
70
+ declare interface ElevenLabsVoiceConfig {
71
+ name?: ElevenLabsModel;
72
+ apiKey?: string;
73
+ }
74
+
75
+ declare interface RequestOptions {
76
+ timeoutInSeconds?: number;
77
+ maxRetries?: number;
78
+ abortSignal?: AbortSignal;
79
+ apiKey?: string | undefined;
80
+ headers?: Record<string, string>;
81
+ }
82
+
83
+ declare interface SpeechToTextOptions {
84
+ language_code?: string;
85
+ tag_audio_events?: boolean;
86
+ num_speakers?: number;
87
+ filetype?: string;
88
+ }
89
+
90
+ export { }
package/dist/index.cjs ADDED
@@ -0,0 +1,141 @@
1
+ 'use strict';
2
+
3
+ var buffer = require('buffer');
4
+ var voice = require('@mastra/core/voice');
5
+ var elevenlabs = require('elevenlabs');
6
+
7
+ // src/index.ts
8
+ var ElevenLabsVoice = class extends voice.MastraVoice {
9
+ client;
10
+ /**
11
+ * Creates an instance of the ElevenLabsVoice class.
12
+ *
13
+ * @param {Object} options - The options for the voice configuration.
14
+ * @param {ElevenLabsVoiceConfig} [options.speechModel] - The configuration for the speech model, including the model name and API key.
15
+ * @param {string} [options.speaker] - The ID of the speaker to use. If not provided, a default speaker will be used.
16
+ *
17
+ * @throws {Error} If the ELEVENLABS_API_KEY is not set in the environment variables.
18
+ */
19
+ constructor({
20
+ speechModel,
21
+ listeningModel,
22
+ speaker
23
+ } = {}) {
24
+ const apiKey = speechModel?.apiKey ?? process.env.ELEVENLABS_API_KEY;
25
+ super({
26
+ speechModel: {
27
+ name: speechModel?.name ?? "eleven_multilingual_v2",
28
+ apiKey: speechModel?.apiKey
29
+ },
30
+ listeningModel: {
31
+ name: listeningModel?.name ?? "scribe_v1",
32
+ apiKey: listeningModel?.apiKey
33
+ },
34
+ speaker
35
+ });
36
+ if (!apiKey) {
37
+ throw new Error("ELEVENLABS_API_KEY is not set");
38
+ }
39
+ this.client = new elevenlabs.ElevenLabsClient({
40
+ apiKey
41
+ });
42
+ this.speaker = speaker || "9BWtsMINqrJLrRacOk9x";
43
+ }
44
+ /**
45
+ * Retrieves a list of available speakers from the Eleven Labs API.
46
+ * Each speaker includes their ID, name, language, and gender.
47
+ *
48
+ * @returns {Promise<Array<{ voiceId: string, name: string, language: string, gender: string }>>}
49
+ * A promise that resolves to an array of speaker objects.
50
+ */
51
+ async getSpeakers() {
52
+ const res = await this.traced(async () => {
53
+ const voices = await this.client.voices.getAll();
54
+ return voices?.voices?.map((voice) => ({
55
+ voiceId: voice.voice_id,
56
+ name: voice.name,
57
+ language: voice.labels?.language || "en",
58
+ gender: voice.labels?.gender || "neutral"
59
+ })) ?? [];
60
+ }, "voice.elevenlabs.voices")();
61
+ return res;
62
+ }
63
+ async streamToString(stream) {
64
+ const chunks = [];
65
+ for await (const chunk of stream) {
66
+ chunks.push(Buffer.from(chunk));
67
+ }
68
+ return Buffer.concat(chunks).toString("utf-8");
69
+ }
70
+ /**
71
+ * Converts text or audio input into speech using the Eleven Labs API.
72
+ *
73
+ * @param {string | NodeJS.ReadableStream} input - The text to be converted to speech or a stream containing audio data.
74
+ * @param {Object} [options] - Optional parameters for the speech generation.
75
+ * @param {string} [options.speaker] - The ID of the speaker to use for the speech. If not provided, the default speaker will be used.
76
+ *
77
+ * @returns {Promise<NodeJS.ReadableStream>} A promise that resolves to a readable stream of the generated speech.
78
+ *
79
+ * @throws {Error} If no speaker is specified or if no speech model is set.
80
+ */
81
+ async speak(input, options) {
82
+ const speaker = options?.speaker || this.speaker;
83
+ if (!speaker) {
84
+ throw new Error("No speaker specified");
85
+ }
86
+ if (!this.speechModel?.name) {
87
+ throw new Error("No speech model specified");
88
+ }
89
+ const text = typeof input === "string" ? input : await this.streamToString(input);
90
+ const res = await this.traced(async () => {
91
+ return await this.client.generate({
92
+ text,
93
+ voice: speaker,
94
+ model_id: this.speechModel?.name,
95
+ stream: true
96
+ });
97
+ }, "voice.elevenlabs.speak")();
98
+ return res;
99
+ }
100
+ /**
101
+ * Converts audio input to text using ElevenLabs Speech-to-Text API.
102
+ *
103
+ * @param input - A readable stream containing the audio data to transcribe
104
+ * @param options - Configuration options for the transcription
105
+ * @param options.language_code - ISO language code (e.g., 'en', 'fr', 'es')
106
+ * @param options.tag_audio_events - Whether to tag audio events like [MUSIC], [LAUGHTER], etc.
107
+ * @param options.num_speakers - Number of speakers to detect in the audio
108
+ * @param options.filetype - Audio file format (e.g., 'mp3', 'wav', 'ogg')
109
+ * @param options.timeoutInSeconds - Request timeout in seconds
110
+ * @param options.maxRetries - Maximum number of retry attempts
111
+ * @param options.abortSignal - Signal to abort the request
112
+ *
113
+ * @returns A Promise that resolves to the transcribed text
114
+ *
115
+ */
116
+ async listen(input, options) {
117
+ const res = await this.traced(async () => {
118
+ const chunks = [];
119
+ for await (const chunk of input) {
120
+ chunks.push(Buffer.from(chunk));
121
+ }
122
+ const buffer$1 = Buffer.concat(chunks);
123
+ const { language_code, tag_audio_events, num_speakers, filetype, ...requestOptions } = options || {};
124
+ const file = new buffer.File([buffer$1], `audio.${filetype || "mp3"}`);
125
+ const transcription = await this.client.speechToText.convert(
126
+ {
127
+ file,
128
+ model_id: this.listeningModel?.name,
129
+ language_code,
130
+ tag_audio_events,
131
+ num_speakers
132
+ },
133
+ requestOptions
134
+ );
135
+ return transcription.text;
136
+ }, "voice.elevenlabs.listen")();
137
+ return res;
138
+ }
139
+ };
140
+
141
+ exports.ElevenLabsVoice = ElevenLabsVoice;
@@ -0,0 +1 @@
1
+ export { ElevenLabsVoice } from './_tsup-dts-rollup.cjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/voice-elevenlabs",
3
- "version": "0.1.1-alpha.1",
3
+ "version": "0.1.1-alpha.3",
4
4
  "description": "Mastra ElevenLabs voice integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -10,6 +10,10 @@
10
10
  "import": {
11
11
  "types": "./dist/index.d.ts",
12
12
  "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.cts",
16
+ "default": "./dist/index.cjs"
13
17
  }
14
18
  },
15
19
  "./package.json": "./package.json"
@@ -17,7 +21,7 @@
17
21
  "dependencies": {
18
22
  "elevenlabs": "^1.50.2",
19
23
  "zod": "^3.24.1",
20
- "@mastra/core": "^0.4.3-alpha.1"
24
+ "@mastra/core": "^0.4.3-alpha.3"
21
25
  },
22
26
  "devDependencies": {
23
27
  "@microsoft/api-extractor": "^7.49.2",
@@ -29,7 +33,7 @@
29
33
  "@internal/lint": "0.0.0"
30
34
  },
31
35
  "scripts": {
32
- "build": "tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
36
+ "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake",
33
37
  "build:watch": "tsup build --watch",
34
38
  "test": "vitest run",
35
39
  "lint": "eslint ."