@mastra/voice-openai 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 +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +86 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +6 -6
- package/dist/_tsup-dts-rollup.d.cts +0 -91
- package/dist/_tsup-dts-rollup.d.ts +0 -91
- package/dist/index.d.cts +0 -3
package/dist/index.cjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["MastraVoice","OpenAI","PassThrough"],"mappings":";;;;;;;;;;;AAyBO,IAAM,WAAA,GAAN,cAA0BA,iBAAA,CAAY;AAAA,EAC3C,YAAA;AAAA,EACA,eAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,WAAA,CAAY;AAAA,IACV,cAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,GACF,GAII,EAAC,EAAG;AACN,IAAA,MAAM,aAAA,GAAgB,QAAQ,GAAA,CAAI,cAAA;AAClC,IAAA,MAAM,kBAAA,GAAqB;AAAA,MACzB,IAAA,EAAM,OAAA;AAAA,MACN,MAAA,EAAQ;AAAA,KACV;AACA,IAAA,MAAM,qBAAA,GAAwB;AAAA,MAC5B,IAAA,EAAM,WAAA;AAAA,MACN,MAAA,EAAQ;AAAA,KACV;AAEA,IAAA,KAAA,CAAM;AAAA,MACJ,WAAA,EAAa;AAAA,QACX,IAAA,EAAM,WAAA,EAAa,IAAA,IAAQ,kBAAA,CAAmB,IAAA;AAAA,QAC9C,MAAA,EAAQ,WAAA,EAAa,MAAA,IAAU,kBAAA,CAAmB;AAAA,OACpD;AAAA,MACA,cAAA,EAAgB;AAAA,QACd,IAAA,EAAM,cAAA,EAAgB,IAAA,IAAQ,qBAAA,CAA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AAA,CAAK,CAAC,WAAW,CAAA,EAAG,CAAA,MAAA,EAAS,QAAA,IAAY,KAAK,CAAA,CAAE,CAAA;AAEjE,MAAA,MAAM,WAAW,MAAM,IAAA,CAAK,eAAA,CAAiB,KAAA,CAAM,eAAe,MAAA,CAAO;AAAA,QACvE,KAAA,EAAO,IAAA,CAAK,cAAA,EAAgB,IAAA,IAAQ,WAAA;AAAA,QACpC,IAAA;AAAA,QACA,GAAG;AAAA,OACJ,CAAA;AAED,MAAA,OAAO,QAAA,CAAS,IAAA;AAAA,IAClB,CAAA,EAAG,qBAAqB,CAAA,EAAE;AAE1B,IAAA,OAAO,IAAA;AAAA,EACT;AACF","file":"index.cjs","sourcesContent":["import { PassThrough } from 'stream';\n\nimport { MastraVoice } from '@mastra/core/voice';\nimport OpenAI from 'openai';\n\ntype OpenAIVoiceId = 'alloy' | 'echo' | 'fable' | 'onyx' | 'nova' | 'shimmer' | 'ash' | 'coral' | 'sage';\ntype OpenAIModel = 'tts-1' | 'tts-1-hd' | 'whisper-1';\n\nexport interface OpenAIConfig {\n name?: OpenAIModel;\n apiKey?: string;\n}\n\nexport interface OpenAIVoiceConfig {\n speech?: {\n model: 'tts-1' | 'tts-1-hd';\n apiKey?: string;\n speaker?: OpenAIVoiceId;\n };\n listening?: {\n model: 'whisper-1';\n apiKey?: string;\n };\n}\n\nexport class OpenAIVoice extends MastraVoice {\n speechClient?: OpenAI;\n listeningClient?: OpenAI;\n\n /**\n * Constructs an instance of OpenAIVoice with optional configurations for speech and listening models.\n *\n * @param {Object} [config] - Configuration options for the OpenAIVoice instance.\n * @param {OpenAIConfig} [config.listeningModel] - Configuration for the listening model, including model name and API key.\n * @param {OpenAIConfig} [config.speechModel] - Configuration for the speech model, including model name and API key.\n * @param {string} [config.speaker] - The default speaker's voice to use for speech synthesis.\n * @throws {Error} - Throws an error if no API key is provided for either the speech or listening model.\n */\n constructor({\n listeningModel,\n speechModel,\n speaker,\n }: {\n listeningModel?: OpenAIConfig;\n speechModel?: OpenAIConfig;\n speaker?: string;\n } = {}) {\n const defaultApiKey = process.env.OPENAI_API_KEY;\n const defaultSpeechModel = {\n name: 'tts-1',\n apiKey: defaultApiKey,\n };\n const defaultListeningModel = {\n name: 'whisper-1',\n apiKey: defaultApiKey,\n };\n\n super({\n speechModel: {\n name: speechModel?.name ?? defaultSpeechModel.name,\n apiKey: speechModel?.apiKey ?? defaultSpeechModel.apiKey,\n },\n listeningModel: {\n name: listeningModel?.name ?? defaultListeningModel.name,\n apiKey: listeningModel?.apiKey ?? defaultListeningModel.apiKey,\n },\n speaker: speaker ?? 'alloy',\n });\n\n const speechApiKey = speechModel?.apiKey || defaultApiKey;\n if (!speechApiKey) {\n throw new Error('No API key provided for speech model');\n }\n this.speechClient = new OpenAI({ apiKey: speechApiKey });\n\n const listeningApiKey = listeningModel?.apiKey || defaultApiKey;\n if (!listeningApiKey) {\n throw new Error('No API key provided for listening model');\n }\n this.listeningClient = new OpenAI({ apiKey: listeningApiKey });\n\n if (!this.speechClient && !this.listeningClient) {\n throw new Error('At least one of OPENAI_API_KEY, speechModel.apiKey, or listeningModel.apiKey must be set');\n }\n }\n\n /**\n * Retrieves a list of available speakers for the speech model.\n *\n * @returns {Promise<Array<{ voiceId: OpenAIVoiceId }>>} - A promise that resolves to an array of objects,\n * each containing a `voiceId` representing an available speaker.\n * @throws {Error} - Throws an error if the speech model is not configured.\n */\n async getSpeakers(): Promise<Array<{ voiceId: OpenAIVoiceId }>> {\n if (!this.speechModel) {\n throw new Error('Speech model not configured');\n }\n\n return [\n { voiceId: 'alloy' },\n { voiceId: 'echo' },\n { voiceId: 'fable' },\n { voiceId: 'onyx' },\n { voiceId: 'nova' },\n { voiceId: 'shimmer' },\n { voiceId: 'ash' },\n { voiceId: 'coral' },\n { voiceId: 'sage' },\n ];\n }\n\n /**\n * Converts text or audio input into speech using the configured speech model.\n *\n * @param {string | NodeJS.ReadableStream} input - The text or audio stream to be converted into speech.\n * @param {Object} [options] - Optional parameters for the speech synthesis.\n * @param {string} [options.speaker] - The speaker's voice to use for the speech synthesis.\n * @param {number} [options.speed] - The speed at which the speech should be synthesized.\n * @returns {Promise<NodeJS.ReadableStream>} - A promise that resolves to a readable stream of the synthesized audio.\n * @throws {Error} - Throws an error if the speech model is not configured or if the input text is empty.\n */\n async speak(\n input: string | NodeJS.ReadableStream,\n options?: {\n speaker?: string;\n speed?: number;\n [key: string]: any;\n },\n ): Promise<NodeJS.ReadableStream> {\n if (!this.speechClient) {\n throw new Error('Speech model not configured');\n }\n\n if (typeof input !== 'string') {\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 input = Buffer.concat(chunks).toString('utf-8');\n }\n\n if (input.trim().length === 0) {\n throw new Error('Input text is empty');\n }\n\n const audio = await this.traced(async () => {\n const response = await this.speechClient!.audio.speech.create({\n model: this.speechModel?.name ?? 'tts-1',\n voice: (options?.speaker ?? this.speaker) as OpenAIVoiceId,\n response_format: options?.responseFormat ?? 'mp3',\n input,\n speed: options?.speed || 1.0,\n });\n\n const passThrough = new PassThrough();\n const buffer = Buffer.from(await response.arrayBuffer());\n passThrough.end(buffer);\n return passThrough;\n }, 'voice.openai.speak')();\n\n return audio;\n }\n\n /**\n * Checks if listening capabilities are enabled.\n *\n * @returns {Promise<{ enabled: boolean }>}\n */\n async getListener() {\n if (!this.listeningClient) {\n return { enabled: false };\n }\n return { enabled: true };\n }\n\n /**\n * Transcribes audio from a given stream using the configured listening model.\n *\n * @param {NodeJS.ReadableStream} audioStream - The audio stream to be transcribed.\n * @param {Object} [options] - Optional parameters for the transcription.\n * @param {string} [options.filetype] - The file type of the audio stream.\n * Supported types include 'mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm'.\n * @returns {Promise<string>} - A promise that resolves to the transcribed text.\n * @throws {Error} - Throws an error if the listening model is not configured.\n */\n async listen(\n audioStream: NodeJS.ReadableStream,\n options?: {\n filetype?: 'mp3' | 'mp4' | 'mpeg' | 'mpga' | 'm4a' | 'wav' | 'webm';\n [key: string]: any;\n },\n ): Promise<string> {\n if (!this.listeningClient) {\n throw new Error('Listening model not configured');\n }\n\n const chunks: Buffer[] = [];\n for await (const chunk of audioStream) {\n if (typeof chunk === 'string') {\n chunks.push(Buffer.from(chunk));\n } else {\n chunks.push(chunk);\n }\n }\n const audioBuffer = Buffer.concat(chunks);\n\n const text = await this.traced(async () => {\n const { filetype, ...otherOptions } = options || {};\n const file = new File([audioBuffer], `audio.${filetype || 'mp3'}`);\n\n const response = await this.listeningClient!.audio.transcriptions.create({\n model: this.listeningModel?.name || 'whisper-1',\n file: file as any,\n ...otherOptions,\n });\n\n return response.text;\n }, 'voice.openai.listen')();\n\n return text;\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { MastraVoice } from '@mastra/core/voice';
|
|
2
|
+
import OpenAI from 'openai';
|
|
3
|
+
type OpenAIVoiceId = 'alloy' | 'echo' | 'fable' | 'onyx' | 'nova' | 'shimmer' | 'ash' | 'coral' | 'sage';
|
|
4
|
+
type OpenAIModel = 'tts-1' | 'tts-1-hd' | 'whisper-1';
|
|
5
|
+
export interface OpenAIConfig {
|
|
6
|
+
name?: OpenAIModel;
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface OpenAIVoiceConfig {
|
|
10
|
+
speech?: {
|
|
11
|
+
model: 'tts-1' | 'tts-1-hd';
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
speaker?: OpenAIVoiceId;
|
|
14
|
+
};
|
|
15
|
+
listening?: {
|
|
16
|
+
model: 'whisper-1';
|
|
17
|
+
apiKey?: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare class OpenAIVoice extends MastraVoice {
|
|
21
|
+
speechClient?: OpenAI;
|
|
22
|
+
listeningClient?: OpenAI;
|
|
23
|
+
/**
|
|
24
|
+
* Constructs an instance of OpenAIVoice with optional configurations for speech and listening models.
|
|
25
|
+
*
|
|
26
|
+
* @param {Object} [config] - Configuration options for the OpenAIVoice instance.
|
|
27
|
+
* @param {OpenAIConfig} [config.listeningModel] - Configuration for the listening model, including model name and API key.
|
|
28
|
+
* @param {OpenAIConfig} [config.speechModel] - Configuration for the speech model, including model name and API key.
|
|
29
|
+
* @param {string} [config.speaker] - The default speaker's voice to use for speech synthesis.
|
|
30
|
+
* @throws {Error} - Throws an error if no API key is provided for either the speech or listening model.
|
|
31
|
+
*/
|
|
32
|
+
constructor({ listeningModel, speechModel, speaker, }?: {
|
|
33
|
+
listeningModel?: OpenAIConfig;
|
|
34
|
+
speechModel?: OpenAIConfig;
|
|
35
|
+
speaker?: string;
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves a list of available speakers for the speech model.
|
|
39
|
+
*
|
|
40
|
+
* @returns {Promise<Array<{ voiceId: OpenAIVoiceId }>>} - A promise that resolves to an array of objects,
|
|
41
|
+
* each containing a `voiceId` representing an available speaker.
|
|
42
|
+
* @throws {Error} - Throws an error if the speech model is not configured.
|
|
43
|
+
*/
|
|
44
|
+
getSpeakers(): Promise<Array<{
|
|
45
|
+
voiceId: OpenAIVoiceId;
|
|
46
|
+
}>>;
|
|
47
|
+
/**
|
|
48
|
+
* Converts text or audio input into speech using the configured speech model.
|
|
49
|
+
*
|
|
50
|
+
* @param {string | NodeJS.ReadableStream} input - The text or audio stream to be converted into speech.
|
|
51
|
+
* @param {Object} [options] - Optional parameters for the speech synthesis.
|
|
52
|
+
* @param {string} [options.speaker] - The speaker's voice to use for the speech synthesis.
|
|
53
|
+
* @param {number} [options.speed] - The speed at which the speech should be synthesized.
|
|
54
|
+
* @returns {Promise<NodeJS.ReadableStream>} - A promise that resolves to a readable stream of the synthesized audio.
|
|
55
|
+
* @throws {Error} - Throws an error if the speech model is not configured or if the input text is empty.
|
|
56
|
+
*/
|
|
57
|
+
speak(input: string | NodeJS.ReadableStream, options?: {
|
|
58
|
+
speaker?: string;
|
|
59
|
+
speed?: number;
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
}): Promise<NodeJS.ReadableStream>;
|
|
62
|
+
/**
|
|
63
|
+
* Checks if listening capabilities are enabled.
|
|
64
|
+
*
|
|
65
|
+
* @returns {Promise<{ enabled: boolean }>}
|
|
66
|
+
*/
|
|
67
|
+
getListener(): Promise<{
|
|
68
|
+
enabled: boolean;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Transcribes audio from a given stream using the configured listening model.
|
|
72
|
+
*
|
|
73
|
+
* @param {NodeJS.ReadableStream} audioStream - The audio stream to be transcribed.
|
|
74
|
+
* @param {Object} [options] - Optional parameters for the transcription.
|
|
75
|
+
* @param {string} [options.filetype] - The file type of the audio stream.
|
|
76
|
+
* Supported types include 'mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm'.
|
|
77
|
+
* @returns {Promise<string>} - A promise that resolves to the transcribed text.
|
|
78
|
+
* @throws {Error} - Throws an error if the listening model is not configured.
|
|
79
|
+
*/
|
|
80
|
+
listen(audioStream: NodeJS.ReadableStream, options?: {
|
|
81
|
+
filetype?: 'mp3' | 'mp4' | 'mpeg' | 'mpga' | 'm4a' | 'wav' | 'webm';
|
|
82
|
+
[key: string]: any;
|
|
83
|
+
}): Promise<string>;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
|
86
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,KAAK,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,KA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,KAAA,CAAM,eAAe,MAAA,CAAO;AAAA,QACvE,KAAA,EAAO,IAAA,CAAK,cAAA,EAAgB,IAAA,IAAQ,WAAA;AAAA,QACpC,IAAA;AAAA,QACA,GAAG;AAAA,OACJ,CAAA;AAED,MAAA,OAAO,QAAA,CAAS,IAAA;AAAA,IAClB,CAAA,EAAG,qBAAqB,CAAA,EAAE;AAE1B,IAAA,OAAO,IAAA;AAAA,EACT;AACF","file":"index.js","sourcesContent":["import { PassThrough } from 'stream';\n\nimport { MastraVoice } from '@mastra/core/voice';\nimport OpenAI from 'openai';\n\ntype OpenAIVoiceId = 'alloy' | 'echo' | 'fable' | 'onyx' | 'nova' | 'shimmer' | 'ash' | 'coral' | 'sage';\ntype OpenAIModel = 'tts-1' | 'tts-1-hd' | 'whisper-1';\n\nexport interface OpenAIConfig {\n name?: OpenAIModel;\n apiKey?: string;\n}\n\nexport interface OpenAIVoiceConfig {\n speech?: {\n model: 'tts-1' | 'tts-1-hd';\n apiKey?: string;\n speaker?: OpenAIVoiceId;\n };\n listening?: {\n model: 'whisper-1';\n apiKey?: string;\n };\n}\n\nexport class OpenAIVoice extends MastraVoice {\n speechClient?: OpenAI;\n listeningClient?: OpenAI;\n\n /**\n * Constructs an instance of OpenAIVoice with optional configurations for speech and listening models.\n *\n * @param {Object} [config] - Configuration options for the OpenAIVoice instance.\n * @param {OpenAIConfig} [config.listeningModel] - Configuration for the listening model, including model name and API key.\n * @param {OpenAIConfig} [config.speechModel] - Configuration for the speech model, including model name and API key.\n * @param {string} [config.speaker] - The default speaker's voice to use for speech synthesis.\n * @throws {Error} - Throws an error if no API key is provided for either the speech or listening model.\n */\n constructor({\n listeningModel,\n speechModel,\n speaker,\n }: {\n listeningModel?: OpenAIConfig;\n speechModel?: OpenAIConfig;\n speaker?: string;\n } = {}) {\n const defaultApiKey = process.env.OPENAI_API_KEY;\n const defaultSpeechModel = {\n name: 'tts-1',\n apiKey: defaultApiKey,\n };\n const defaultListeningModel = {\n name: 'whisper-1',\n apiKey: defaultApiKey,\n };\n\n super({\n speechModel: {\n name: speechModel?.name ?? defaultSpeechModel.name,\n apiKey: speechModel?.apiKey ?? defaultSpeechModel.apiKey,\n },\n listeningModel: {\n name: listeningModel?.name ?? defaultListeningModel.name,\n apiKey: listeningModel?.apiKey ?? defaultListeningModel.apiKey,\n },\n speaker: speaker ?? 'alloy',\n });\n\n const speechApiKey = speechModel?.apiKey || defaultApiKey;\n if (!speechApiKey) {\n throw new Error('No API key provided for speech model');\n }\n this.speechClient = new OpenAI({ apiKey: speechApiKey });\n\n const listeningApiKey = listeningModel?.apiKey || defaultApiKey;\n if (!listeningApiKey) {\n throw new Error('No API key provided for listening model');\n }\n this.listeningClient = new OpenAI({ apiKey: listeningApiKey });\n\n if (!this.speechClient && !this.listeningClient) {\n throw new Error('At least one of OPENAI_API_KEY, speechModel.apiKey, or listeningModel.apiKey must be set');\n }\n }\n\n /**\n * Retrieves a list of available speakers for the speech model.\n *\n * @returns {Promise<Array<{ voiceId: OpenAIVoiceId }>>} - A promise that resolves to an array of objects,\n * each containing a `voiceId` representing an available speaker.\n * @throws {Error} - Throws an error if the speech model is not configured.\n */\n async getSpeakers(): Promise<Array<{ voiceId: OpenAIVoiceId }>> {\n if (!this.speechModel) {\n throw new Error('Speech model not configured');\n }\n\n return [\n { voiceId: 'alloy' },\n { voiceId: 'echo' },\n { voiceId: 'fable' },\n { voiceId: 'onyx' },\n { voiceId: 'nova' },\n { voiceId: 'shimmer' },\n { voiceId: 'ash' },\n { voiceId: 'coral' },\n { voiceId: 'sage' },\n ];\n }\n\n /**\n * Converts text or audio input into speech using the configured speech model.\n *\n * @param {string | NodeJS.ReadableStream} input - The text or audio stream to be converted into speech.\n * @param {Object} [options] - Optional parameters for the speech synthesis.\n * @param {string} [options.speaker] - The speaker's voice to use for the speech synthesis.\n * @param {number} [options.speed] - The speed at which the speech should be synthesized.\n * @returns {Promise<NodeJS.ReadableStream>} - A promise that resolves to a readable stream of the synthesized audio.\n * @throws {Error} - Throws an error if the speech model is not configured or if the input text is empty.\n */\n async speak(\n input: string | NodeJS.ReadableStream,\n options?: {\n speaker?: string;\n speed?: number;\n [key: string]: any;\n },\n ): Promise<NodeJS.ReadableStream> {\n if (!this.speechClient) {\n throw new Error('Speech model not configured');\n }\n\n if (typeof input !== 'string') {\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 input = Buffer.concat(chunks).toString('utf-8');\n }\n\n if (input.trim().length === 0) {\n throw new Error('Input text is empty');\n }\n\n const audio = await this.traced(async () => {\n const response = await this.speechClient!.audio.speech.create({\n model: this.speechModel?.name ?? 'tts-1',\n voice: (options?.speaker ?? this.speaker) as OpenAIVoiceId,\n response_format: options?.responseFormat ?? 'mp3',\n input,\n speed: options?.speed || 1.0,\n });\n\n const passThrough = new PassThrough();\n const buffer = Buffer.from(await response.arrayBuffer());\n passThrough.end(buffer);\n return passThrough;\n }, 'voice.openai.speak')();\n\n return audio;\n }\n\n /**\n * Checks if listening capabilities are enabled.\n *\n * @returns {Promise<{ enabled: boolean }>}\n */\n async getListener() {\n if (!this.listeningClient) {\n return { enabled: false };\n }\n return { enabled: true };\n }\n\n /**\n * Transcribes audio from a given stream using the configured listening model.\n *\n * @param {NodeJS.ReadableStream} audioStream - The audio stream to be transcribed.\n * @param {Object} [options] - Optional parameters for the transcription.\n * @param {string} [options.filetype] - The file type of the audio stream.\n * Supported types include 'mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm'.\n * @returns {Promise<string>} - A promise that resolves to the transcribed text.\n * @throws {Error} - Throws an error if the listening model is not configured.\n */\n async listen(\n audioStream: NodeJS.ReadableStream,\n options?: {\n filetype?: 'mp3' | 'mp4' | 'mpeg' | 'mpga' | 'm4a' | 'wav' | 'webm';\n [key: string]: any;\n },\n ): Promise<string> {\n if (!this.listeningClient) {\n throw new Error('Listening model not configured');\n }\n\n const chunks: Buffer[] = [];\n for await (const chunk of audioStream) {\n if (typeof chunk === 'string') {\n chunks.push(Buffer.from(chunk));\n } else {\n chunks.push(chunk);\n }\n }\n const audioBuffer = Buffer.concat(chunks);\n\n const text = await this.traced(async () => {\n const { filetype, ...otherOptions } = options || {};\n const file = new File([audioBuffer], `audio.${filetype || 'mp3'}`);\n\n const response = await this.listeningClient!.audio.transcriptions.create({\n model: this.listeningModel?.name || 'whisper-1',\n file: file as any,\n ...otherOptions,\n });\n\n return response.text;\n }, 'voice.openai.listen')();\n\n return text;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/voice-openai",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.7",
|
|
4
4
|
"description": "Mastra OpenAI speech integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"openai": "^5.10.
|
|
26
|
+
"openai": "^5.10.2",
|
|
27
27
|
"zod": "^3.25.67"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
@@ -33,15 +33,15 @@
|
|
|
33
33
|
"tsup": "^8.5.0",
|
|
34
34
|
"typescript": "^5.8.3",
|
|
35
35
|
"vitest": "^3.2.4",
|
|
36
|
-
"@internal/lint": "0.0.
|
|
37
|
-
"@mastra/core": "0.12.
|
|
36
|
+
"@internal/lint": "0.0.25",
|
|
37
|
+
"@mastra/core": "0.12.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@mastra/core": ">=0.10.7-0 <0.13.0-0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
|
-
"build": "tsup
|
|
44
|
-
"build:watch": "
|
|
43
|
+
"build": "tsup --silent --config tsup.config.ts",
|
|
44
|
+
"build:watch": "tsup --watch --silent --config tsup.config.ts",
|
|
45
45
|
"test": "vitest run",
|
|
46
46
|
"lint": "eslint ."
|
|
47
47
|
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { MastraVoice } from '@mastra/core/voice';
|
|
2
|
-
import OpenAI from 'openai';
|
|
3
|
-
|
|
4
|
-
export declare interface OpenAIConfig {
|
|
5
|
-
name?: OpenAIModel;
|
|
6
|
-
apiKey?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
declare type OpenAIModel = 'tts-1' | 'tts-1-hd' | 'whisper-1';
|
|
10
|
-
|
|
11
|
-
export declare class OpenAIVoice extends MastraVoice {
|
|
12
|
-
speechClient?: OpenAI;
|
|
13
|
-
listeningClient?: OpenAI;
|
|
14
|
-
/**
|
|
15
|
-
* Constructs an instance of OpenAIVoice with optional configurations for speech and listening models.
|
|
16
|
-
*
|
|
17
|
-
* @param {Object} [config] - Configuration options for the OpenAIVoice instance.
|
|
18
|
-
* @param {OpenAIConfig} [config.listeningModel] - Configuration for the listening model, including model name and API key.
|
|
19
|
-
* @param {OpenAIConfig} [config.speechModel] - Configuration for the speech model, including model name and API key.
|
|
20
|
-
* @param {string} [config.speaker] - The default speaker's voice to use for speech synthesis.
|
|
21
|
-
* @throws {Error} - Throws an error if no API key is provided for either the speech or listening model.
|
|
22
|
-
*/
|
|
23
|
-
constructor({ listeningModel, speechModel, speaker, }?: {
|
|
24
|
-
listeningModel?: OpenAIConfig;
|
|
25
|
-
speechModel?: OpenAIConfig;
|
|
26
|
-
speaker?: string;
|
|
27
|
-
});
|
|
28
|
-
/**
|
|
29
|
-
* Retrieves a list of available speakers for the speech model.
|
|
30
|
-
*
|
|
31
|
-
* @returns {Promise<Array<{ voiceId: OpenAIVoiceId }>>} - A promise that resolves to an array of objects,
|
|
32
|
-
* each containing a `voiceId` representing an available speaker.
|
|
33
|
-
* @throws {Error} - Throws an error if the speech model is not configured.
|
|
34
|
-
*/
|
|
35
|
-
getSpeakers(): Promise<Array<{
|
|
36
|
-
voiceId: OpenAIVoiceId;
|
|
37
|
-
}>>;
|
|
38
|
-
/**
|
|
39
|
-
* Converts text or audio input into speech using the configured speech model.
|
|
40
|
-
*
|
|
41
|
-
* @param {string | NodeJS.ReadableStream} input - The text or audio stream to be converted into speech.
|
|
42
|
-
* @param {Object} [options] - Optional parameters for the speech synthesis.
|
|
43
|
-
* @param {string} [options.speaker] - The speaker's voice to use for the speech synthesis.
|
|
44
|
-
* @param {number} [options.speed] - The speed at which the speech should be synthesized.
|
|
45
|
-
* @returns {Promise<NodeJS.ReadableStream>} - A promise that resolves to a readable stream of the synthesized audio.
|
|
46
|
-
* @throws {Error} - Throws an error if the speech model is not configured or if the input text is empty.
|
|
47
|
-
*/
|
|
48
|
-
speak(input: string | NodeJS.ReadableStream, options?: {
|
|
49
|
-
speaker?: string;
|
|
50
|
-
speed?: number;
|
|
51
|
-
[key: string]: any;
|
|
52
|
-
}): Promise<NodeJS.ReadableStream>;
|
|
53
|
-
/**
|
|
54
|
-
* Checks if listening capabilities are enabled.
|
|
55
|
-
*
|
|
56
|
-
* @returns {Promise<{ enabled: boolean }>}
|
|
57
|
-
*/
|
|
58
|
-
getListener(): Promise<{
|
|
59
|
-
enabled: boolean;
|
|
60
|
-
}>;
|
|
61
|
-
/**
|
|
62
|
-
* Transcribes audio from a given stream using the configured listening model.
|
|
63
|
-
*
|
|
64
|
-
* @param {NodeJS.ReadableStream} audioStream - The audio stream to be transcribed.
|
|
65
|
-
* @param {Object} [options] - Optional parameters for the transcription.
|
|
66
|
-
* @param {string} [options.filetype] - The file type of the audio stream.
|
|
67
|
-
* Supported types include 'mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm'.
|
|
68
|
-
* @returns {Promise<string>} - A promise that resolves to the transcribed text.
|
|
69
|
-
* @throws {Error} - Throws an error if the listening model is not configured.
|
|
70
|
-
*/
|
|
71
|
-
listen(audioStream: NodeJS.ReadableStream, options?: {
|
|
72
|
-
filetype?: 'mp3' | 'mp4' | 'mpeg' | 'mpga' | 'm4a' | 'wav' | 'webm';
|
|
73
|
-
[key: string]: any;
|
|
74
|
-
}): Promise<string>;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export declare interface OpenAIVoiceConfig {
|
|
78
|
-
speech?: {
|
|
79
|
-
model: 'tts-1' | 'tts-1-hd';
|
|
80
|
-
apiKey?: string;
|
|
81
|
-
speaker?: OpenAIVoiceId;
|
|
82
|
-
};
|
|
83
|
-
listening?: {
|
|
84
|
-
model: 'whisper-1';
|
|
85
|
-
apiKey?: string;
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
declare type OpenAIVoiceId = 'alloy' | 'echo' | 'fable' | 'onyx' | 'nova' | 'shimmer' | 'ash' | 'coral' | 'sage';
|
|
90
|
-
|
|
91
|
-
export { }
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { MastraVoice } from '@mastra/core/voice';
|
|
2
|
-
import OpenAI from 'openai';
|
|
3
|
-
|
|
4
|
-
export declare interface OpenAIConfig {
|
|
5
|
-
name?: OpenAIModel;
|
|
6
|
-
apiKey?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
declare type OpenAIModel = 'tts-1' | 'tts-1-hd' | 'whisper-1';
|
|
10
|
-
|
|
11
|
-
export declare class OpenAIVoice extends MastraVoice {
|
|
12
|
-
speechClient?: OpenAI;
|
|
13
|
-
listeningClient?: OpenAI;
|
|
14
|
-
/**
|
|
15
|
-
* Constructs an instance of OpenAIVoice with optional configurations for speech and listening models.
|
|
16
|
-
*
|
|
17
|
-
* @param {Object} [config] - Configuration options for the OpenAIVoice instance.
|
|
18
|
-
* @param {OpenAIConfig} [config.listeningModel] - Configuration for the listening model, including model name and API key.
|
|
19
|
-
* @param {OpenAIConfig} [config.speechModel] - Configuration for the speech model, including model name and API key.
|
|
20
|
-
* @param {string} [config.speaker] - The default speaker's voice to use for speech synthesis.
|
|
21
|
-
* @throws {Error} - Throws an error if no API key is provided for either the speech or listening model.
|
|
22
|
-
*/
|
|
23
|
-
constructor({ listeningModel, speechModel, speaker, }?: {
|
|
24
|
-
listeningModel?: OpenAIConfig;
|
|
25
|
-
speechModel?: OpenAIConfig;
|
|
26
|
-
speaker?: string;
|
|
27
|
-
});
|
|
28
|
-
/**
|
|
29
|
-
* Retrieves a list of available speakers for the speech model.
|
|
30
|
-
*
|
|
31
|
-
* @returns {Promise<Array<{ voiceId: OpenAIVoiceId }>>} - A promise that resolves to an array of objects,
|
|
32
|
-
* each containing a `voiceId` representing an available speaker.
|
|
33
|
-
* @throws {Error} - Throws an error if the speech model is not configured.
|
|
34
|
-
*/
|
|
35
|
-
getSpeakers(): Promise<Array<{
|
|
36
|
-
voiceId: OpenAIVoiceId;
|
|
37
|
-
}>>;
|
|
38
|
-
/**
|
|
39
|
-
* Converts text or audio input into speech using the configured speech model.
|
|
40
|
-
*
|
|
41
|
-
* @param {string | NodeJS.ReadableStream} input - The text or audio stream to be converted into speech.
|
|
42
|
-
* @param {Object} [options] - Optional parameters for the speech synthesis.
|
|
43
|
-
* @param {string} [options.speaker] - The speaker's voice to use for the speech synthesis.
|
|
44
|
-
* @param {number} [options.speed] - The speed at which the speech should be synthesized.
|
|
45
|
-
* @returns {Promise<NodeJS.ReadableStream>} - A promise that resolves to a readable stream of the synthesized audio.
|
|
46
|
-
* @throws {Error} - Throws an error if the speech model is not configured or if the input text is empty.
|
|
47
|
-
*/
|
|
48
|
-
speak(input: string | NodeJS.ReadableStream, options?: {
|
|
49
|
-
speaker?: string;
|
|
50
|
-
speed?: number;
|
|
51
|
-
[key: string]: any;
|
|
52
|
-
}): Promise<NodeJS.ReadableStream>;
|
|
53
|
-
/**
|
|
54
|
-
* Checks if listening capabilities are enabled.
|
|
55
|
-
*
|
|
56
|
-
* @returns {Promise<{ enabled: boolean }>}
|
|
57
|
-
*/
|
|
58
|
-
getListener(): Promise<{
|
|
59
|
-
enabled: boolean;
|
|
60
|
-
}>;
|
|
61
|
-
/**
|
|
62
|
-
* Transcribes audio from a given stream using the configured listening model.
|
|
63
|
-
*
|
|
64
|
-
* @param {NodeJS.ReadableStream} audioStream - The audio stream to be transcribed.
|
|
65
|
-
* @param {Object} [options] - Optional parameters for the transcription.
|
|
66
|
-
* @param {string} [options.filetype] - The file type of the audio stream.
|
|
67
|
-
* Supported types include 'mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm'.
|
|
68
|
-
* @returns {Promise<string>} - A promise that resolves to the transcribed text.
|
|
69
|
-
* @throws {Error} - Throws an error if the listening model is not configured.
|
|
70
|
-
*/
|
|
71
|
-
listen(audioStream: NodeJS.ReadableStream, options?: {
|
|
72
|
-
filetype?: 'mp3' | 'mp4' | 'mpeg' | 'mpga' | 'm4a' | 'wav' | 'webm';
|
|
73
|
-
[key: string]: any;
|
|
74
|
-
}): Promise<string>;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export declare interface OpenAIVoiceConfig {
|
|
78
|
-
speech?: {
|
|
79
|
-
model: 'tts-1' | 'tts-1-hd';
|
|
80
|
-
apiKey?: string;
|
|
81
|
-
speaker?: OpenAIVoiceId;
|
|
82
|
-
};
|
|
83
|
-
listening?: {
|
|
84
|
-
model: 'whisper-1';
|
|
85
|
-
apiKey?: string;
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
declare type OpenAIVoiceId = 'alloy' | 'echo' | 'fable' | 'onyx' | 'nova' | 'shimmer' | 'ash' | 'coral' | 'sage';
|
|
90
|
-
|
|
91
|
-
export { }
|
package/dist/index.d.cts
DELETED