@mastra/voice-murf 0.13.0 → 0.13.1-alpha.1

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.js CHANGED
@@ -1,532 +1,639 @@
1
- import { PassThrough } from 'stream';
2
-
3
- // src/index.ts
4
-
5
- // ../../packages/_internal-core/dist/chunk-3M4SEWMI.js
6
- var RegisteredLogger = {
7
- LLM: "LLM"};
8
- var LogLevel = {
9
- DEBUG: "debug",
10
- INFO: "info",
11
- WARN: "warn",
12
- ERROR: "error"};
1
+ import { PassThrough } from "stream";
2
+ //#region ../../packages/_internal-core/dist/logger/index.js
3
+ /**
4
+ * Export a tracked exception through the adapter sink, mirroring the
5
+ * DualLogger dual-write shape (`errorId`/`domain`/`category`/`details`/`cause`
6
+ * when present on a MastraError-like value). Never throws into the caller.
7
+ */
8
+ function exportTrackedException(ctx, error, metadata) {
9
+ if (!ctx?.options.export) return;
10
+ try {
11
+ const mastraError = error;
12
+ ctx.getLogSink()?.error(error.message, {
13
+ ...mastraError.id !== void 0 ? { errorId: mastraError.id } : {},
14
+ ...mastraError.domain !== void 0 ? { domain: mastraError.domain } : {},
15
+ ...mastraError.category !== void 0 ? { category: mastraError.category } : {},
16
+ ...mastraError.details !== void 0 ? { details: mastraError.details } : {},
17
+ ...error.cause instanceof Error ? { cause: error.cause.message } : {},
18
+ ...metadata
19
+ });
20
+ } catch {}
21
+ }
22
+ /**
23
+ * Adapt IMastraLogger's variadic args into the structured `data` payload of
24
+ * an exported log record. Extracts the first plain object as data,
25
+ * serializes an Error arg, and collects remaining primitives under `args`
26
+ * so the derived record preserves all context from the native call.
27
+ */
28
+ function buildLogRecordData(args) {
29
+ const objectData = args.find((arg) => arg !== null && typeof arg === "object" && !Array.isArray(arg) && !(arg instanceof Error));
30
+ const errorArg = args.find((arg) => arg instanceof Error);
31
+ const extraArgs = args.filter((arg) => arg !== objectData && arg !== errorArg);
32
+ if (!objectData && !errorArg && extraArgs.length === 0) return void 0;
33
+ return {
34
+ ...objectData ?? {},
35
+ ...errorArg ? { error: {
36
+ name: errorArg.name,
37
+ message: errorArg.message,
38
+ stack: errorArg.stack
39
+ } } : {},
40
+ ...extraArgs.length > 0 ? { args: extraArgs } : {}
41
+ };
42
+ }
43
+ const RegisteredLogger = {
44
+ AGENT: "AGENT",
45
+ OBSERVABILITY: "OBSERVABILITY",
46
+ AUTH: "AUTH",
47
+ BROWSER: "BROWSER",
48
+ NETWORK: "NETWORK",
49
+ WORKFLOW: "WORKFLOW",
50
+ LLM: "LLM",
51
+ TTS: "TTS",
52
+ VOICE: "VOICE",
53
+ VECTOR: "VECTOR",
54
+ BUNDLER: "BUNDLER",
55
+ DEPLOYER: "DEPLOYER",
56
+ MEMORY: "MEMORY",
57
+ STORAGE: "STORAGE",
58
+ EMBEDDINGS: "EMBEDDINGS",
59
+ MCP_SERVER: "MCP_SERVER",
60
+ SERVER_CACHE: "SERVER_CACHE",
61
+ SERVER: "SERVER",
62
+ WORKSPACE: "WORKSPACE",
63
+ CHANNEL: "CHANNEL"
64
+ };
65
+ const LogLevel = {
66
+ DEBUG: "debug",
67
+ INFO: "info",
68
+ WARN: "warn",
69
+ ERROR: "error",
70
+ NONE: "silent"
71
+ };
13
72
  var MastraLogger = class {
14
- name;
15
- level;
16
- transports;
17
- constructor(options = {}) {
18
- this.name = options.name || "Mastra";
19
- this.level = options.level || LogLevel.ERROR;
20
- this.transports = new Map(Object.entries(options.transports || {}));
21
- }
22
- getTransports() {
23
- return this.transports;
24
- }
25
- trackException(_error, _metadata) {
26
- }
27
- async listLogs(transportId, params) {
28
- if (!transportId || !this.transports.has(transportId)) {
29
- return { logs: [], total: 0, page: params?.page ?? 1, perPage: params?.perPage ?? 100, hasMore: false };
30
- }
31
- return this.transports.get(transportId).listLogs?.(params) ?? {
32
- logs: [],
33
- total: 0,
34
- page: params?.page ?? 1,
35
- perPage: params?.perPage ?? 100,
36
- hasMore: false
37
- };
38
- }
39
- async listLogsByRunId({
40
- transportId,
41
- runId,
42
- fromDate,
43
- toDate,
44
- logLevel,
45
- filters,
46
- page,
47
- perPage
48
- }) {
49
- if (!transportId || !this.transports.has(transportId) || !runId) {
50
- return { logs: [], total: 0, page: page ?? 1, perPage: perPage ?? 100, hasMore: false };
51
- }
52
- return this.transports.get(transportId).listLogsByRunId?.({ runId, fromDate, toDate, logLevel, filters, page, perPage }) ?? {
53
- logs: [],
54
- total: 0,
55
- page: page ?? 1,
56
- perPage: perPage ?? 100,
57
- hasMore: false
58
- };
59
- }
73
+ name;
74
+ level;
75
+ transports;
76
+ constructor(options = {}) {
77
+ this.name = options.name || "Mastra";
78
+ this.level = options.level || LogLevel.ERROR;
79
+ this.transports = new Map(Object.entries(options.transports || {}));
80
+ }
81
+ getTransports() {
82
+ return this.transports;
83
+ }
84
+ trackException(_error, _metadata) {}
85
+ async listLogs(transportId, params) {
86
+ if (!transportId || !this.transports.has(transportId)) return {
87
+ logs: [],
88
+ total: 0,
89
+ page: params?.page ?? 1,
90
+ perPage: params?.perPage ?? 100,
91
+ hasMore: false
92
+ };
93
+ return this.transports.get(transportId).listLogs?.(params) ?? {
94
+ logs: [],
95
+ total: 0,
96
+ page: params?.page ?? 1,
97
+ perPage: params?.perPage ?? 100,
98
+ hasMore: false
99
+ };
100
+ }
101
+ async listLogsByRunId({ transportId, runId, fromDate, toDate, logLevel, filters, page, perPage }) {
102
+ if (!transportId || !this.transports.has(transportId) || !runId) return {
103
+ logs: [],
104
+ total: 0,
105
+ page: page ?? 1,
106
+ perPage: perPage ?? 100,
107
+ hasMore: false
108
+ };
109
+ return this.transports.get(transportId).listLogsByRunId?.({
110
+ runId,
111
+ fromDate,
112
+ toDate,
113
+ logLevel,
114
+ filters,
115
+ page,
116
+ perPage
117
+ }) ?? {
118
+ logs: [],
119
+ total: 0,
120
+ page: page ?? 1,
121
+ perPage: perPage ?? 100,
122
+ hasMore: false
123
+ };
124
+ }
60
125
  };
61
- var ConsoleLogger = class _ConsoleLogger extends MastraLogger {
62
- component;
63
- filter;
64
- constructor(options = {}) {
65
- super(options);
66
- this.component = options.component;
67
- this.filter = options.filter;
68
- }
69
- child(componentOrBindings) {
70
- const component = typeof componentOrBindings === "string" ? componentOrBindings : componentOrBindings?.component ?? this.component;
71
- return new _ConsoleLogger({
72
- name: this.name,
73
- level: this.level,
74
- component,
75
- filter: this.filter
76
- });
77
- }
78
- shouldLog(level, message, args) {
79
- if (!this.filter) return true;
80
- try {
81
- return this.filter({ component: this.component, level, message, args });
82
- } catch (e) {
83
- console.error(`[Logger] Filter error for component=${this.component} level=${level}:`, e);
84
- return true;
85
- }
86
- }
87
- prefix() {
88
- return this.component ? `[${this.component}] ` : "";
89
- }
90
- debug(message, ...args) {
91
- if (this.level === LogLevel.DEBUG && this.shouldLog(LogLevel.DEBUG, message, args)) {
92
- console.info(`${this.prefix()}${message}`, ...args);
93
- }
94
- }
95
- info(message, ...args) {
96
- if ((this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.INFO, message, args)) {
97
- console.info(`${this.prefix()}${message}`, ...args);
98
- }
99
- }
100
- warn(message, ...args) {
101
- if ((this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.WARN, message, args)) {
102
- console.warn(`${this.prefix()}${message}`, ...args);
103
- }
104
- }
105
- error(message, ...args) {
106
- if ((this.level === LogLevel.ERROR || this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.ERROR, message, args)) {
107
- console.error(`${this.prefix()}${message}`, ...args);
108
- }
109
- }
110
- async listLogs(_transportId, _params) {
111
- return { logs: [], total: 0, page: _params?.page ?? 1, perPage: _params?.perPage ?? 100, hasMore: false };
112
- }
113
- async listLogsByRunId(_args) {
114
- return { logs: [], total: 0, page: _args.page ?? 1, perPage: _args.perPage ?? 100, hasMore: false };
115
- }
126
+ var ConsoleLogger = class ConsoleLogger extends MastraLogger {
127
+ component;
128
+ filter;
129
+ #adapterContext;
130
+ constructor(options = {}) {
131
+ super(options);
132
+ this.component = options.component;
133
+ this.filter = options.filter;
134
+ }
135
+ /**
136
+ * Adapter hook (see `AdaptableLogger`): enables native trace correlation
137
+ * (trace_id/span_id appended to console output) and observability export
138
+ * derived from the same record. Called by Mastra during setup.
139
+ */
140
+ __attachObservability(ctx) {
141
+ this.#adapterContext = ctx;
142
+ }
143
+ child(componentOrBindings) {
144
+ const component = typeof componentOrBindings === "string" ? componentOrBindings : componentOrBindings?.component ?? this.component;
145
+ const child = new ConsoleLogger({
146
+ name: this.name,
147
+ level: this.level,
148
+ component,
149
+ filter: this.filter
150
+ });
151
+ if (this.#adapterContext) child.__attachObservability(this.#adapterContext);
152
+ return child;
153
+ }
154
+ /**
155
+ * Native-record correlation: when a span is active, append the trace
156
+ * fields object to the console args so every destination sees them.
157
+ */
158
+ #correlate(args) {
159
+ const ctx = this.#adapterContext;
160
+ if (!ctx?.options.correlation) return args;
161
+ try {
162
+ const fields = ctx.resolveTraceFields();
163
+ return fields ? [...args, fields] : args;
164
+ } catch {
165
+ return args;
166
+ }
167
+ }
168
+ /**
169
+ * Export the record derived from the same native call to observability.
170
+ * Mirrors DualLogger semantics: export is independent of the console
171
+ * level filter, and never throws into the caller.
172
+ */
173
+ #export(level, message, args) {
174
+ const ctx = this.#adapterContext;
175
+ if (!ctx?.options.export) return;
176
+ try {
177
+ ctx.getLogSink()?.[level](message, buildLogRecordData(args));
178
+ } catch {}
179
+ }
180
+ shouldLog(level, message, args) {
181
+ if (!this.filter) return true;
182
+ try {
183
+ return this.filter({
184
+ component: this.component,
185
+ level,
186
+ message,
187
+ args
188
+ });
189
+ } catch (e) {
190
+ console.error(`[Logger] Filter error for component=${this.component} level=${level}:`, e);
191
+ return true;
192
+ }
193
+ }
194
+ prefix() {
195
+ return this.component ? `[${this.component}] ` : "";
196
+ }
197
+ debug(message, ...args) {
198
+ if (this.level === LogLevel.DEBUG && this.shouldLog(LogLevel.DEBUG, message, args)) console.info(`${this.prefix()}${message}`, ...this.#correlate(args));
199
+ this.#export("debug", message, args);
200
+ }
201
+ info(message, ...args) {
202
+ if ((this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.INFO, message, args)) console.info(`${this.prefix()}${message}`, ...this.#correlate(args));
203
+ this.#export("info", message, args);
204
+ }
205
+ warn(message, ...args) {
206
+ if ((this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.WARN, message, args)) console.warn(`${this.prefix()}${message}`, ...this.#correlate(args));
207
+ this.#export("warn", message, args);
208
+ }
209
+ error(message, ...args) {
210
+ if ((this.level === LogLevel.ERROR || this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.ERROR, message, args)) console.error(`${this.prefix()}${message}`, ...this.#correlate(args));
211
+ this.#export("error", message, args);
212
+ }
213
+ trackException(error, metadata) {
214
+ exportTrackedException(this.#adapterContext, error, metadata);
215
+ }
216
+ async listLogs(_transportId, _params) {
217
+ return {
218
+ logs: [],
219
+ total: 0,
220
+ page: _params?.page ?? 1,
221
+ perPage: _params?.perPage ?? 100,
222
+ hasMore: false
223
+ };
224
+ }
225
+ async listLogsByRunId(_args) {
226
+ return {
227
+ logs: [],
228
+ total: 0,
229
+ page: _args.page ?? 1,
230
+ perPage: _args.perPage ?? 100,
231
+ hasMore: false
232
+ };
233
+ }
116
234
  };
117
-
118
- // ../../packages/_internal-core/dist/base/index.js
235
+ //#endregion
236
+ //#region ../../packages/_internal-core/dist/base/index.js
119
237
  var MastraBase = class {
120
- component = RegisteredLogger.LLM;
121
- logger;
122
- name;
123
- #rawConfig;
124
- constructor({
125
- component,
126
- name,
127
- rawConfig
128
- }) {
129
- this.component = component || RegisteredLogger.LLM;
130
- this.name = name;
131
- this.#rawConfig = rawConfig;
132
- this.logger = new ConsoleLogger({ name: `${this.component} - ${this.name}` });
133
- }
134
- /**
135
- * Returns the raw storage configuration this primitive was created from,
136
- * or undefined if it was created from code.
137
- */
138
- toRawConfig() {
139
- return this.#rawConfig;
140
- }
141
- /**
142
- * Sets the raw storage configuration for this primitive.
143
- * @internal
144
- */
145
- __setRawConfig(rawConfig) {
146
- this.#rawConfig = rawConfig;
147
- }
148
- /**
149
- * Set the logger for the agent
150
- * @param logger
151
- */
152
- __setLogger(logger) {
153
- this.logger = "child" in logger && typeof logger.child === "function" ? logger.child({ component: this.component }) : logger;
154
- }
238
+ component = RegisteredLogger.LLM;
239
+ logger;
240
+ name;
241
+ #rawConfig;
242
+ constructor({ component, name, rawConfig }) {
243
+ this.component = component || RegisteredLogger.LLM;
244
+ this.name = name;
245
+ this.#rawConfig = rawConfig;
246
+ this.logger = new ConsoleLogger({ name: `${this.component} - ${this.name}` });
247
+ }
248
+ /**
249
+ * Returns the raw storage configuration this primitive was created from,
250
+ * or undefined if it was created from code.
251
+ */
252
+ toRawConfig() {
253
+ return this.#rawConfig;
254
+ }
255
+ /**
256
+ * Sets the raw storage configuration for this primitive.
257
+ * @internal
258
+ */
259
+ __setRawConfig(rawConfig) {
260
+ this.#rawConfig = rawConfig;
261
+ }
262
+ /**
263
+ * Set the logger for the agent
264
+ * @param logger
265
+ */
266
+ __setLogger(logger) {
267
+ this.logger = "child" in logger && typeof logger.child === "function" ? logger.child({ component: this.component }) : logger;
268
+ }
155
269
  };
156
-
157
- // ../../packages/_internals/voice/dist/chunk-NWNKSBZV.js
270
+ //#endregion
271
+ //#region ../../packages/_internals/voice/dist/aisdk-C_K-VCwq.js
158
272
  var MastraVoice = class extends MastraBase {
159
- listeningModel;
160
- speechModel;
161
- speaker;
162
- realtimeConfig;
163
- constructor({ listeningModel, speechModel, speaker, realtimeConfig, name } = {}) {
164
- super({
165
- component: "VOICE",
166
- name
167
- });
168
- this.listeningModel = listeningModel;
169
- this.speechModel = speechModel;
170
- this.speaker = speaker;
171
- this.realtimeConfig = realtimeConfig;
172
- }
173
- /**
174
- * Custom serialization for tracing/observability spans.
175
- * Excludes `apiKey` from listeningModel / speechModel / realtimeConfig
176
- * and any provider-specific state held by subclasses. Subclasses that
177
- * need to expose additional non-sensitive fields can override.
178
- */
179
- serializeForSpan() {
180
- return {
181
- component: "VOICE",
182
- name: this.name,
183
- speaker: this.speaker,
184
- listeningModel: this.listeningModel ? { name: this.listeningModel.name } : void 0,
185
- speechModel: this.speechModel ? { name: this.speechModel.name } : void 0,
186
- realtimeModel: this.realtimeConfig?.model
187
- };
188
- }
189
- updateConfig(_options) {
190
- this.logger.debug("updateConfig not implemented by this voice provider");
191
- }
192
- /**
193
- * Initializes a WebSocket or WebRTC connection for real-time communication
194
- * @returns Promise that resolves when the connection is established
195
- */
196
- async connect(_options) {
197
- this.logger.debug("connect not implemented by this voice provider");
198
- }
199
- /**
200
- * Relay audio data to the voice provider for real-time processing
201
- * @param audioData Audio data to relay
202
- */
203
- async send(_audioData) {
204
- this.logger.debug("relay not implemented by this voice provider");
205
- }
206
- /**
207
- * Trigger voice providers to respond
208
- */
209
- async answer(_options) {
210
- this.logger.debug("answer not implemented by this voice provider");
211
- }
212
- /**
213
- * Equip the voice provider with instructions
214
- * @param instructions Instructions to add
215
- */
216
- addInstructions(_instructions) {
217
- }
218
- /**
219
- * Equip the voice provider with tools
220
- * @param tools Array of tools to add
221
- */
222
- addTools(_tools) {
223
- }
224
- /**
225
- * Disconnect from the WebSocket or WebRTC connection
226
- */
227
- close() {
228
- this.logger.debug("close not implemented by this voice provider");
229
- }
230
- /**
231
- * Register an event listener
232
- * @param event Event name (e.g., 'speaking', 'writing', 'error')
233
- * @param callback Callback function that receives event data
234
- */
235
- on(_event, _callback) {
236
- this.logger.debug("on not implemented by this voice provider");
237
- }
238
- /**
239
- * Remove an event listener
240
- * @param event Event name (e.g., 'speaking', 'writing', 'error')
241
- * @param callback Callback function to remove
242
- */
243
- off(_event, _callback) {
244
- this.logger.debug("off not implemented by this voice provider");
245
- }
246
- /**
247
- * Get available speakers/voices
248
- * @returns Array of available voice IDs and their metadata
249
- */
250
- getSpeakers() {
251
- this.logger.debug("getSpeakers not implemented by this voice provider");
252
- return Promise.resolve([]);
253
- }
254
- /**
255
- * Get available speakers/voices
256
- * @returns Array of available voice IDs and their metadata
257
- */
258
- getListener() {
259
- this.logger.debug("getListener not implemented by this voice provider");
260
- return Promise.resolve({ enabled: false });
261
- }
273
+ listeningModel;
274
+ speechModel;
275
+ speaker;
276
+ realtimeConfig;
277
+ constructor({ listeningModel, speechModel, speaker, realtimeConfig, name } = {}) {
278
+ super({
279
+ component: "VOICE",
280
+ name
281
+ });
282
+ this.listeningModel = listeningModel;
283
+ this.speechModel = speechModel;
284
+ this.speaker = speaker;
285
+ this.realtimeConfig = realtimeConfig;
286
+ }
287
+ /**
288
+ * Custom serialization for tracing/observability spans.
289
+ * Excludes `apiKey` from listeningModel / speechModel / realtimeConfig
290
+ * and any provider-specific state held by subclasses. Subclasses that
291
+ * need to expose additional non-sensitive fields can override.
292
+ */
293
+ serializeForSpan() {
294
+ return {
295
+ component: "VOICE",
296
+ name: this.name,
297
+ speaker: this.speaker,
298
+ listeningModel: this.listeningModel ? { name: this.listeningModel.name } : void 0,
299
+ speechModel: this.speechModel ? { name: this.speechModel.name } : void 0,
300
+ realtimeModel: this.realtimeConfig?.model
301
+ };
302
+ }
303
+ updateConfig(_options) {
304
+ this.logger.debug("updateConfig not implemented by this voice provider");
305
+ }
306
+ /**
307
+ * Initializes a WebSocket or WebRTC connection for real-time communication
308
+ * @returns Promise that resolves when the connection is established
309
+ */
310
+ async connect(_options) {
311
+ this.logger.debug("connect not implemented by this voice provider");
312
+ }
313
+ /**
314
+ * Relay audio data to the voice provider for real-time processing
315
+ * @param audioData Audio data to relay
316
+ */
317
+ async send(_audioData) {
318
+ this.logger.debug("relay not implemented by this voice provider");
319
+ }
320
+ /**
321
+ * Trigger voice providers to respond
322
+ */
323
+ async answer(_options) {
324
+ this.logger.debug("answer not implemented by this voice provider");
325
+ }
326
+ /**
327
+ * Equip the voice provider with instructions
328
+ * @param instructions Instructions to add
329
+ */
330
+ addInstructions(_instructions) {}
331
+ /**
332
+ * Equip the voice provider with tools
333
+ * @param tools Array of tools to add
334
+ */
335
+ addTools(_tools) {}
336
+ /**
337
+ * Disconnect from the WebSocket or WebRTC connection
338
+ */
339
+ close() {
340
+ this.logger.debug("close not implemented by this voice provider");
341
+ }
342
+ /**
343
+ * Register an event listener
344
+ * @param event Event name (e.g., 'speaking', 'writing', 'error')
345
+ * @param callback Callback function that receives event data
346
+ */
347
+ on(_event, _callback) {
348
+ this.logger.debug("on not implemented by this voice provider");
349
+ }
350
+ /**
351
+ * Remove an event listener
352
+ * @param event Event name (e.g., 'speaking', 'writing', 'error')
353
+ * @param callback Callback function to remove
354
+ */
355
+ off(_event, _callback) {
356
+ this.logger.debug("off not implemented by this voice provider");
357
+ }
358
+ /**
359
+ * Get available speakers/voices
360
+ * @returns Array of available voice IDs and their metadata
361
+ */
362
+ getSpeakers() {
363
+ this.logger.debug("getSpeakers not implemented by this voice provider");
364
+ return Promise.resolve([]);
365
+ }
366
+ /**
367
+ * Get available speakers/voices
368
+ * @returns Array of available voice IDs and their metadata
369
+ */
370
+ getListener() {
371
+ this.logger.debug("getListener not implemented by this voice provider");
372
+ return Promise.resolve({ enabled: false });
373
+ }
262
374
  };
263
-
264
- // src/voices.ts
265
- var MURF_VOICES = [
266
- "en-UK-hazel",
267
- "en-US-cooper",
268
- "en-US-imani",
269
- "it-IT-giorgio",
270
- "en-US-wayne",
271
- "en-IN-shivani",
272
- "en-US-daniel",
273
- "bn-IN-anwesha",
274
- "es-MX-alejandro",
275
- "en-AU-joyce",
276
- "en-US-zion",
277
- "en-IN-isha",
278
- "en-US-riley",
279
- "ko-KR-hwan",
280
- "fr-FR-ad\xE9lie",
281
- "en-US-carter",
282
- "en-UK-gabriel",
283
- "en-UK-juliet",
284
- "en-IN-arohi",
285
- "fr-FR-maxime",
286
- "de-DE-josephine",
287
- "en-UK-hugo",
288
- "en-US-samantha",
289
- "de-DE-erna",
290
- "zh-CN-baolin",
291
- "pt-BR-isadora",
292
- "it-IT-vincenzo",
293
- "en-US-terrell",
294
- "en-US-denzel",
295
- "en-UK-heidi",
296
- "en-US-miles",
297
- "en-US-abigail",
298
- "fr-FR-justine",
299
- "it-IT-greta",
300
- "en-AU-shane",
301
- "en-UK-peter",
302
- "nl-NL-famke",
303
- "en-AU-ivy",
304
- "nl-NL-dirk",
305
- "fr-FR-axel",
306
- "es-ES-carla",
307
- "en-US-claire",
308
- "ko-KR-jangmi",
309
- "ko-KR-sanghoon",
310
- "it-IT-vera",
311
- "hi-IN-rahul",
312
- "es-ES-elvira",
313
- "es-ES-enrique",
314
- "en-UK-aiden",
315
- "en-US-ronnie",
316
- "en-UK-amber",
317
- "hi-IN-shweta",
318
- "hi-IN-amit",
319
- "en-AU-jimm",
320
- "en-UK-pearl",
321
- "pt-BR-ben\xEDcio",
322
- "en-UK-freddie",
323
- "en-US-ryan",
324
- "pt-BR-eloa",
325
- "en-US-charlotte",
326
- "de-DE-lia",
327
- "en-US-natalie",
328
- "en-US-michelle",
329
- "en-US-phoebe",
330
- "es-ES-carmen",
331
- "en-US-caleb",
332
- "en-US-iris",
333
- "en-UK-harrison",
334
- "en-US-marcus",
335
- "en-US-josie",
336
- "en-US-daisy",
337
- "en-US-charles",
338
- "en-UK-reggie",
339
- "en-US-julia",
340
- "en-SCOTT-emily",
341
- "en-US-dylan",
342
- "es-MX-valeria",
343
- "en-IN-eashwar",
344
- "en-AU-evelyn",
345
- "de-DE-lara",
346
- "en-US-evander",
347
- "en-SCOTT-rory",
348
- "ta-IN-iniya",
349
- "en-AU-leyton",
350
- "fr-FR-louise",
351
- "zh-CN-wei",
352
- "ko-KR-gyeong",
353
- "de-DE-matthias",
354
- "en-IN-rohan",
355
- "en-US-delilah",
356
- "bn-IN-abhik",
357
- "en-US-angela",
358
- "en-US-naomi",
359
- "es-MX-carlos",
360
- "nl-NL-merel",
361
- "en-US-alicia",
362
- "en-IN-alia",
363
- "zh-CN-jiao",
364
- "en-US-june",
365
- "en-AU-ashton",
366
- "en-UK-finley",
367
- "pl-PL-blazej",
368
- "zh-CN-zhang",
369
- "en-AU-kylie",
370
- "en-US-jayden",
371
- "en-IN-aarav",
372
- "de-DE-bj\xF6rn",
373
- "bn-IN-ishani",
374
- "zh-CN-yuxan",
375
- "fr-FR-louis",
376
- "ko-KR-jong-su",
377
- "en-AU-harper",
378
- "en-UK-ruby",
379
- "en-US-ken",
380
- "ta-IN-mani",
381
- "de-DE-ralf",
382
- "en-UK-jaxon",
383
- "en-US-river",
384
- "en-IN-priya",
385
- "en-UK-theo",
386
- "en-UK-katie",
387
- "pl-PL-jacek",
388
- "it-IT-lorenzo",
389
- "hi-IN-shaan",
390
- "en-US-amara",
391
- "en-UK-mason",
392
- "en-IN-surya",
393
- "en-US-finn",
394
- "pt-BR-gustavo",
395
- "hi-IN-kabir",
396
- "es-ES-javier",
397
- "en-AU-mitch",
398
- "pt-BR-heitor",
399
- "en-US-edmund",
400
- "hi-IN-ayushi",
401
- "pl-PL-kasia",
402
- "es-MX-luisa",
403
- "zh-CN-tao",
404
- "en-US-molly"
375
+ //#endregion
376
+ //#region src/voices.ts
377
+ /**
378
+ * List of available voices for Murf TTS
379
+ */
380
+ const MURF_VOICES = [
381
+ "en-UK-hazel",
382
+ "en-US-cooper",
383
+ "en-US-imani",
384
+ "it-IT-giorgio",
385
+ "en-US-wayne",
386
+ "en-IN-shivani",
387
+ "en-US-daniel",
388
+ "bn-IN-anwesha",
389
+ "es-MX-alejandro",
390
+ "en-AU-joyce",
391
+ "en-US-zion",
392
+ "en-IN-isha",
393
+ "en-US-riley",
394
+ "ko-KR-hwan",
395
+ "fr-FR-adélie",
396
+ "en-US-carter",
397
+ "en-UK-gabriel",
398
+ "en-UK-juliet",
399
+ "en-IN-arohi",
400
+ "fr-FR-maxime",
401
+ "de-DE-josephine",
402
+ "en-UK-hugo",
403
+ "en-US-samantha",
404
+ "de-DE-erna",
405
+ "zh-CN-baolin",
406
+ "pt-BR-isadora",
407
+ "it-IT-vincenzo",
408
+ "en-US-terrell",
409
+ "en-US-denzel",
410
+ "en-UK-heidi",
411
+ "en-US-miles",
412
+ "en-US-abigail",
413
+ "fr-FR-justine",
414
+ "it-IT-greta",
415
+ "en-AU-shane",
416
+ "en-UK-peter",
417
+ "nl-NL-famke",
418
+ "en-AU-ivy",
419
+ "nl-NL-dirk",
420
+ "fr-FR-axel",
421
+ "es-ES-carla",
422
+ "en-US-claire",
423
+ "ko-KR-jangmi",
424
+ "ko-KR-sanghoon",
425
+ "it-IT-vera",
426
+ "hi-IN-rahul",
427
+ "es-ES-elvira",
428
+ "es-ES-enrique",
429
+ "en-UK-aiden",
430
+ "en-US-ronnie",
431
+ "en-UK-amber",
432
+ "hi-IN-shweta",
433
+ "hi-IN-amit",
434
+ "en-AU-jimm",
435
+ "en-UK-pearl",
436
+ "pt-BR-benício",
437
+ "en-UK-freddie",
438
+ "en-US-ryan",
439
+ "pt-BR-eloa",
440
+ "en-US-charlotte",
441
+ "de-DE-lia",
442
+ "en-US-natalie",
443
+ "en-US-michelle",
444
+ "en-US-phoebe",
445
+ "es-ES-carmen",
446
+ "en-US-caleb",
447
+ "en-US-iris",
448
+ "en-UK-harrison",
449
+ "en-US-marcus",
450
+ "en-US-josie",
451
+ "en-US-daisy",
452
+ "en-US-charles",
453
+ "en-UK-reggie",
454
+ "en-US-julia",
455
+ "en-SCOTT-emily",
456
+ "en-US-dylan",
457
+ "es-MX-valeria",
458
+ "en-IN-eashwar",
459
+ "en-AU-evelyn",
460
+ "de-DE-lara",
461
+ "en-US-evander",
462
+ "en-SCOTT-rory",
463
+ "ta-IN-iniya",
464
+ "en-AU-leyton",
465
+ "fr-FR-louise",
466
+ "zh-CN-wei",
467
+ "ko-KR-gyeong",
468
+ "de-DE-matthias",
469
+ "en-IN-rohan",
470
+ "en-US-delilah",
471
+ "bn-IN-abhik",
472
+ "en-US-angela",
473
+ "en-US-naomi",
474
+ "es-MX-carlos",
475
+ "nl-NL-merel",
476
+ "en-US-alicia",
477
+ "en-IN-alia",
478
+ "zh-CN-jiao",
479
+ "en-US-june",
480
+ "en-AU-ashton",
481
+ "en-UK-finley",
482
+ "pl-PL-blazej",
483
+ "zh-CN-zhang",
484
+ "en-AU-kylie",
485
+ "en-US-jayden",
486
+ "en-IN-aarav",
487
+ "de-DE-björn",
488
+ "bn-IN-ishani",
489
+ "zh-CN-yuxan",
490
+ "fr-FR-louis",
491
+ "ko-KR-jong-su",
492
+ "en-AU-harper",
493
+ "en-UK-ruby",
494
+ "en-US-ken",
495
+ "ta-IN-mani",
496
+ "de-DE-ralf",
497
+ "en-UK-jaxon",
498
+ "en-US-river",
499
+ "en-IN-priya",
500
+ "en-UK-theo",
501
+ "en-UK-katie",
502
+ "pl-PL-jacek",
503
+ "it-IT-lorenzo",
504
+ "hi-IN-shaan",
505
+ "en-US-amara",
506
+ "en-UK-mason",
507
+ "en-IN-surya",
508
+ "en-US-finn",
509
+ "pt-BR-gustavo",
510
+ "hi-IN-kabir",
511
+ "es-ES-javier",
512
+ "en-AU-mitch",
513
+ "pt-BR-heitor",
514
+ "en-US-edmund",
515
+ "hi-IN-ayushi",
516
+ "pl-PL-kasia",
517
+ "es-MX-luisa",
518
+ "zh-CN-tao",
519
+ "en-US-molly"
405
520
  ];
406
-
407
- // src/index.ts
408
- var DEFAULT_RETRY_COUNT = 2;
409
- var RETRY_STATUS_CODES = /* @__PURE__ */ new Set([408, 413, 429, 500, 502, 503, 504]);
410
- var RETRY_DELAY_MS = 300;
521
+ //#endregion
522
+ //#region src/index.ts
523
+ const DEFAULT_RETRY_COUNT = 2;
524
+ const RETRY_STATUS_CODES = /* @__PURE__ */ new Set([
525
+ 408,
526
+ 413,
527
+ 429,
528
+ 500,
529
+ 502,
530
+ 503,
531
+ 504
532
+ ]);
533
+ const RETRY_DELAY_MS = 300;
411
534
  var MurfVoice = class extends MastraVoice {
412
- baseUrl = "https://api.murf.ai";
413
- apiKey;
414
- defaultVoice;
415
- properties;
416
- constructor({ speechModel, speaker } = {}) {
417
- super({
418
- speechModel: {
419
- name: speechModel?.name ?? "GEN2",
420
- apiKey: speechModel?.apiKey ?? process.env.MURF_API_KEY
421
- },
422
- speaker: speaker ?? MURF_VOICES[0]
423
- });
424
- const apiKey = this.speechModel?.apiKey;
425
- if (!apiKey) {
426
- throw new Error("MURF_API_KEY is not set");
427
- }
428
- this.apiKey = apiKey;
429
- this.properties = {
430
- ...speechModel?.properties
431
- };
432
- this.defaultVoice = speaker ?? MURF_VOICES[0];
433
- }
434
- async streamToString(stream) {
435
- const chunks = [];
436
- for await (const chunk of stream) {
437
- if (typeof chunk === "string") {
438
- chunks.push(Buffer.from(chunk));
439
- } else {
440
- chunks.push(chunk);
441
- }
442
- }
443
- return Buffer.concat(chunks).toString("utf-8");
444
- }
445
- async speak(input, options) {
446
- const text = typeof input === "string" ? input : await this.streamToString(input);
447
- const response = await this.makeRequest("/v1/speech/generate", {
448
- voiceId: options?.speaker || this.defaultVoice,
449
- text,
450
- modelVersion: this.speechModel?.name,
451
- ...this.properties,
452
- ...options?.properties
453
- });
454
- const stream = new PassThrough();
455
- const audioResponse = await fetch(response.audioFile);
456
- if (!audioResponse.body) {
457
- throw new Error("No response body received");
458
- }
459
- const reader = audioResponse.body.getReader();
460
- (async () => {
461
- try {
462
- while (true) {
463
- const { done, value } = await reader.read();
464
- if (done) {
465
- stream.end();
466
- break;
467
- }
468
- stream.write(value);
469
- }
470
- } catch (error) {
471
- stream.destroy(error);
472
- }
473
- })().catch((error) => {
474
- stream.destroy(error);
475
- });
476
- return stream;
477
- }
478
- /**
479
- * Checks if listening capabilities are enabled.
480
- *
481
- * @returns {Promise<{ enabled: boolean }>}
482
- */
483
- async getListener() {
484
- return { enabled: false };
485
- }
486
- async listen(_input, _options) {
487
- throw new Error("Murf does not support speech recognition");
488
- }
489
- async makeRequest(endpoint, payload) {
490
- let lastError;
491
- for (let attempt = 0; attempt <= DEFAULT_RETRY_COUNT; attempt++) {
492
- if (attempt > 0) {
493
- await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS * 2 ** (attempt - 1)));
494
- }
495
- const res = await fetch(`${this.baseUrl}${endpoint}`, {
496
- method: "POST",
497
- headers: {
498
- "api-key": this.apiKey,
499
- "Content-Type": "application/json"
500
- },
501
- body: JSON.stringify(payload)
502
- });
503
- if (res.ok) {
504
- return await res.json();
505
- }
506
- if (!RETRY_STATUS_CODES.has(res.status) || attempt === DEFAULT_RETRY_COUNT) {
507
- let errorMessage;
508
- try {
509
- const error = await res.json();
510
- errorMessage = error.message || res.statusText;
511
- } catch {
512
- errorMessage = res.statusText;
513
- }
514
- throw new Error(`Murf API Error: ${errorMessage}`);
515
- }
516
- lastError = new Error(`Murf API Error: ${res.statusText}`);
517
- }
518
- throw lastError ?? new Error("Murf API Error: request failed");
519
- }
520
- async getSpeakers() {
521
- return MURF_VOICES.map((voice) => ({
522
- voiceId: voice,
523
- name: voice,
524
- language: voice.split("-")[0],
525
- gender: "neutral"
526
- }));
527
- }
535
+ baseUrl = "https://api.murf.ai";
536
+ apiKey;
537
+ defaultVoice;
538
+ properties;
539
+ constructor({ speechModel, speaker } = {}) {
540
+ super({
541
+ speechModel: {
542
+ name: speechModel?.name ?? "GEN2",
543
+ apiKey: speechModel?.apiKey ?? process.env.MURF_API_KEY
544
+ },
545
+ speaker: speaker ?? MURF_VOICES[0]
546
+ });
547
+ const apiKey = this.speechModel?.apiKey;
548
+ if (!apiKey) throw new Error("MURF_API_KEY is not set");
549
+ this.apiKey = apiKey;
550
+ this.properties = { ...speechModel?.properties };
551
+ this.defaultVoice = speaker ?? MURF_VOICES[0];
552
+ }
553
+ async streamToString(stream) {
554
+ const chunks = [];
555
+ for await (const chunk of stream) if (typeof chunk === "string") chunks.push(Buffer.from(chunk));
556
+ else chunks.push(chunk);
557
+ return Buffer.concat(chunks).toString("utf-8");
558
+ }
559
+ async speak(input, options) {
560
+ const text = typeof input === "string" ? input : await this.streamToString(input);
561
+ const response = await this.makeRequest("/v1/speech/generate", {
562
+ voiceId: options?.speaker || this.defaultVoice,
563
+ text,
564
+ modelVersion: this.speechModel?.name,
565
+ ...this.properties,
566
+ ...options?.properties
567
+ });
568
+ const stream = new PassThrough();
569
+ const audioResponse = await fetch(response.audioFile);
570
+ if (!audioResponse.body) throw new Error("No response body received");
571
+ const reader = audioResponse.body.getReader();
572
+ (async () => {
573
+ try {
574
+ while (true) {
575
+ const { done, value } = await reader.read();
576
+ if (done) {
577
+ stream.end();
578
+ break;
579
+ }
580
+ stream.write(value);
581
+ }
582
+ } catch (error) {
583
+ stream.destroy(error);
584
+ }
585
+ })().catch((error) => {
586
+ stream.destroy(error);
587
+ });
588
+ return stream;
589
+ }
590
+ /**
591
+ * Checks if listening capabilities are enabled.
592
+ *
593
+ * @returns {Promise<{ enabled: boolean }>}
594
+ */
595
+ async getListener() {
596
+ return { enabled: false };
597
+ }
598
+ async listen(_input, _options) {
599
+ throw new Error("Murf does not support speech recognition");
600
+ }
601
+ async makeRequest(endpoint, payload) {
602
+ let lastError;
603
+ for (let attempt = 0; attempt <= DEFAULT_RETRY_COUNT; attempt++) {
604
+ if (attempt > 0) await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS * 2 ** (attempt - 1)));
605
+ const res = await fetch(`${this.baseUrl}${endpoint}`, {
606
+ method: "POST",
607
+ headers: {
608
+ "api-key": this.apiKey,
609
+ "Content-Type": "application/json"
610
+ },
611
+ body: JSON.stringify(payload)
612
+ });
613
+ if (res.ok) return await res.json();
614
+ if (!RETRY_STATUS_CODES.has(res.status) || attempt === DEFAULT_RETRY_COUNT) {
615
+ let errorMessage;
616
+ try {
617
+ errorMessage = (await res.json()).message || res.statusText;
618
+ } catch {
619
+ errorMessage = res.statusText;
620
+ }
621
+ throw new Error(`Murf API Error: ${errorMessage}`);
622
+ }
623
+ lastError = /* @__PURE__ */ new Error(`Murf API Error: ${res.statusText}`);
624
+ }
625
+ throw lastError ?? /* @__PURE__ */ new Error("Murf API Error: request failed");
626
+ }
627
+ async getSpeakers() {
628
+ return MURF_VOICES.map((voice) => ({
629
+ voiceId: voice,
630
+ name: voice,
631
+ language: voice.split("-")[0],
632
+ gender: "neutral"
633
+ }));
634
+ }
528
635
  };
529
-
636
+ //#endregion
530
637
  export { MurfVoice };
531
- //# sourceMappingURL=index.js.map
638
+
532
639
  //# sourceMappingURL=index.js.map