@mastra/voice-murf 0.12.0 → 0.12.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @mastra/voice-murf
2
2
 
3
+ ## 0.12.1-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Replaced ky HTTP client with native fetch and built-in retry logic, removing the external dependency ([#16960](https://github.com/mastra-ai/mastra/pull/16960))
8
+
9
+ - Updated dependencies [[`ac442a4`](https://github.com/mastra-ai/mastra/commit/ac442a42fda0354ac2bcea772bf6691cb3e9dbb3), [`1e5c067`](https://github.com/mastra-ai/mastra/commit/1e5c067d2e20a781af670578180d1ee249806d41), [`008baaf`](https://github.com/mastra-ai/mastra/commit/008baafd8d851f831407045aebead5a2e3342eff), [`8116436`](https://github.com/mastra-ai/mastra/commit/81164363eb225d774e41ff27da6a5ea611406688), [`c27c4b9`](https://github.com/mastra-ai/mastra/commit/c27c4b9f137df5414fca4e45896aceccff6b0ed5), [`08b3b59`](https://github.com/mastra-ai/mastra/commit/08b3b590dd960dee6c9a6e39272f8927d803db6e)]:
10
+ - @mastra/core@1.37.0-alpha.3
11
+
3
12
  ## 0.12.0
4
13
 
5
14
  ### Minor Changes
package/LICENSE.md CHANGED
@@ -1,3 +1,18 @@
1
+ Portions of this software are licensed as follows:
2
+
3
+ - All content that resides under any directory named "ee/" within this
4
+ repository, including but not limited to:
5
+ - `packages/core/src/auth/ee/`
6
+ - `packages/server/src/server/auth/ee/`
7
+ is licensed under the license defined in `ee/LICENSE`.
8
+
9
+ - All third-party components incorporated into the Mastra Software are
10
+ licensed under the original license provided by the owner of the
11
+ applicable component.
12
+
13
+ - Content outside of the above-mentioned directories or restrictions is
14
+ available under the "Apache License 2.0" as defined below.
15
+
1
16
  # Apache License 2.0
2
17
 
3
18
  Copyright (c) 2025 Kepler Software, Inc.
@@ -1,33 +1,27 @@
1
1
  ---
2
- name: mastra-voice-murf-docs
3
- description: Documentation for @mastra/voice-murf. Includes links to type definitions and readable implementation code in dist/.
2
+ name: mastra-voice-murf
3
+ description: Documentation for @mastra/voice-murf. Use when working with @mastra/voice-murf APIs, configuration, or implementation.
4
+ metadata:
5
+ package: "@mastra/voice-murf"
6
+ version: "0.12.1-alpha.0"
4
7
  ---
5
8
 
6
- # @mastra/voice-murf Documentation
9
+ ## When to use
7
10
 
8
- > **Version**: 0.12.0
9
- > **Package**: @mastra/voice-murf
11
+ Use this skill whenever you are working with @mastra/voice-murf to obtain the domain-specific knowledge.
10
12
 
11
- ## Quick Navigation
13
+ ## How to use
12
14
 
13
- Use SOURCE_MAP.json to find any export:
15
+ Read the individual reference documents for detailed explanations and code examples.
14
16
 
15
- ```bash
16
- cat docs/SOURCE_MAP.json
17
- ```
17
+ ### Docs
18
18
 
19
- Each export maps to:
20
- - **types**: `.d.ts` file with JSDoc and API signatures
21
- - **implementation**: `.js` chunk file with readable source
22
- - **docs**: Conceptual documentation in `docs/`
19
+ - [Voice](references/docs-agents-adding-voice.md) - Learn how to add voice capabilities to your Mastra agents for text-to-speech and speech-to-text interactions.
20
+ - [Voice in Mastra](references/docs-voice-overview.md) - Overview of voice capabilities in Mastra, including text-to-speech, speech-to-text, and real-time speech-to-speech interactions.
23
21
 
24
- ## Top Exports
22
+ ### Reference
25
23
 
24
+ - [Reference: Murf](references/reference-voice-murf.md) - Documentation for the Murf voice implementation, providing text-to-speech capabilities.
26
25
 
27
26
 
28
- See SOURCE_MAP.json for the complete list.
29
-
30
- ## Available Topics
31
-
32
- - [Agents](agents/) - 1 file(s)
33
- - [Voice](voice/) - 2 file(s)
27
+ Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.12.0",
2
+ "version": "0.12.1-alpha.0",
3
3
  "package": "@mastra/voice-murf",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -0,0 +1,350 @@
1
+ # Voice
2
+
3
+ Mastra agents can be enhanced with voice capabilities, allowing them to speak responses and listen to user input. You can configure an agent to use either a single voice provider or combine multiple providers for different operations.
4
+
5
+ ## Basic usage
6
+
7
+ The simplest way to add voice to an agent is to use a single provider for both speaking and listening:
8
+
9
+ ```typescript
10
+ import { createReadStream } from 'fs'
11
+ import path from 'path'
12
+ import { Agent } from '@mastra/core/agent'
13
+ import { OpenAIVoice } from '@mastra/voice-openai'
14
+
15
+ // Initialize the voice provider with default settings
16
+ const voice = new OpenAIVoice()
17
+
18
+ // Create an agent with voice capabilities
19
+ export const agent = new Agent({
20
+ id: 'voice-agent',
21
+ name: 'Voice Agent',
22
+ instructions: `You are a helpful assistant with both STT and TTS capabilities.`,
23
+ model: 'openai/gpt-5.4',
24
+ voice,
25
+ })
26
+
27
+ // The agent can now use voice for interaction
28
+ const audioStream = await agent.voice.speak("Hello, I'm your AI assistant!", {
29
+ filetype: 'm4a',
30
+ })
31
+
32
+ playAudio(audioStream!)
33
+
34
+ try {
35
+ const transcription = await agent.voice.listen(audioStream)
36
+ console.log(transcription)
37
+ } catch (error) {
38
+ console.error('Error transcribing audio:', error)
39
+ }
40
+ ```
41
+
42
+ ## Working with audio streams
43
+
44
+ The `speak()` and `listen()` methods work with Node.js streams. Here's how to save and load audio files:
45
+
46
+ ### Saving Speech Output
47
+
48
+ The `speak` method returns a stream that you can pipe to a file or speaker.
49
+
50
+ ```typescript
51
+ import { createWriteStream } from 'fs'
52
+ import path from 'path'
53
+
54
+ // Generate speech and save to file
55
+ const audio = await agent.voice.speak('Hello, World!')
56
+ const filePath = path.join(process.cwd(), 'agent.mp3')
57
+ const writer = createWriteStream(filePath)
58
+
59
+ audio.pipe(writer)
60
+
61
+ await new Promise<void>((resolve, reject) => {
62
+ writer.on('finish', () => resolve())
63
+ writer.on('error', reject)
64
+ })
65
+ ```
66
+
67
+ ### Transcribing Audio Input
68
+
69
+ The `listen` method expects a stream of audio data from a microphone or file.
70
+
71
+ ```typescript
72
+ import { createReadStream } from 'fs'
73
+ import path from 'path'
74
+
75
+ // Read audio file and transcribe
76
+ const audioFilePath = path.join(process.cwd(), '/agent.m4a')
77
+ const audioStream = createReadStream(audioFilePath)
78
+
79
+ try {
80
+ console.log('Transcribing audio file...')
81
+ const transcription = await agent.voice.listen(audioStream, {
82
+ filetype: 'm4a',
83
+ })
84
+ console.log('Transcription:', transcription)
85
+ } catch (error) {
86
+ console.error('Error transcribing audio:', error)
87
+ }
88
+ ```
89
+
90
+ ## Speech-to-speech voice interactions
91
+
92
+ For more dynamic and interactive voice experiences, you can use real-time voice providers that support speech-to-speech capabilities:
93
+
94
+ ```typescript
95
+ import { Agent } from '@mastra/core/agent'
96
+ import { getMicrophoneStream } from '@mastra/node-audio'
97
+ import { OpenAIRealtimeVoice } from '@mastra/voice-openai-realtime'
98
+ import { search, calculate } from '../tools'
99
+
100
+ // Initialize the realtime voice provider
101
+ const voice = new OpenAIRealtimeVoice({
102
+ apiKey: process.env.OPENAI_API_KEY,
103
+ model: 'gpt-5.1-realtime',
104
+ speaker: 'alloy',
105
+ })
106
+
107
+ // Create an agent with speech-to-speech voice capabilities
108
+ export const agent = new Agent({
109
+ id: 'speech-to-speech-agent',
110
+ name: 'Speech-to-Speech Agent',
111
+ instructions: `You are a helpful assistant with speech-to-speech capabilities.`,
112
+ model: 'openai/gpt-5.4',
113
+ tools: {
114
+ // Tools configured on Agent are passed to voice provider
115
+ search,
116
+ calculate,
117
+ },
118
+ voice,
119
+ })
120
+
121
+ // Establish a WebSocket connection
122
+ await agent.voice.connect()
123
+
124
+ // Start a conversation
125
+ agent.voice.speak("Hello, I'm your AI assistant!")
126
+
127
+ // Stream audio from a microphone
128
+ const microphoneStream = getMicrophoneStream()
129
+ agent.voice.send(microphoneStream)
130
+
131
+ // When done with the conversation
132
+ agent.voice.close()
133
+ ```
134
+
135
+ ### Event System
136
+
137
+ The realtime voice provider emits several events you can listen for:
138
+
139
+ ```typescript
140
+ // Listen for speech audio data sent from voice provider
141
+ agent.voice.on('speaking', ({ audio }) => {
142
+ // audio contains ReadableStream or Int16Array audio data
143
+ })
144
+
145
+ // Listen for transcribed text sent from both voice provider and user
146
+ agent.voice.on('writing', ({ text, role }) => {
147
+ console.log(`${role} said: ${text}`)
148
+ })
149
+
150
+ // Listen for errors
151
+ agent.voice.on('error', error => {
152
+ console.error('Voice error:', error)
153
+ })
154
+ ```
155
+
156
+ ## Examples
157
+
158
+ ### End-to-end voice interaction
159
+
160
+ This example demonstrates a voice interaction between two agents. The hybrid voice agent, which uses multiple providers, speaks a question, which is saved as an audio file. The unified voice agent listens to that file, processes the question, generates a response, and speaks it back. Both audio outputs are saved to the `audio` directory.
161
+
162
+ The following files are created:
163
+
164
+ - **hybrid-question.mp3** – Hybrid agent's spoken question.
165
+ - **unified-response.mp3** – Unified agent's spoken response.
166
+
167
+ ```typescript
168
+ import 'dotenv/config'
169
+
170
+ import path from 'path'
171
+ import { createReadStream } from 'fs'
172
+ import { Agent } from '@mastra/core/agent'
173
+ import { CompositeVoice } from '@mastra/core/voice'
174
+ import { OpenAIVoice } from '@mastra/voice-openai'
175
+ import { Mastra } from '@mastra/core'
176
+
177
+ // Saves an audio stream to a file in the audio directory, creating the directory if it doesn't exist.
178
+ export const saveAudioToFile = async (
179
+ audio: NodeJS.ReadableStream,
180
+ filename: string,
181
+ ): Promise<void> => {
182
+ const audioDir = path.join(process.cwd(), 'audio')
183
+ const filePath = path.join(audioDir, filename)
184
+
185
+ await fs.promises.mkdir(audioDir, { recursive: true })
186
+
187
+ const writer = createWriteStream(filePath)
188
+ audio.pipe(writer)
189
+ return new Promise((resolve, reject) => {
190
+ writer.on('finish', resolve)
191
+ writer.on('error', reject)
192
+ })
193
+ }
194
+
195
+ // Saves an audio stream to a file in the audio directory, creating the directory if it doesn't exist.
196
+ export const convertToText = async (input: string | NodeJS.ReadableStream): Promise<string> => {
197
+ if (typeof input === 'string') {
198
+ return input
199
+ }
200
+
201
+ const chunks: Buffer[] = []
202
+ return new Promise((resolve, reject) => {
203
+ inputData.on('data', chunk => chunks.push(Buffer.from(chunk)))
204
+ inputData.on('error', reject)
205
+ inputData.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')))
206
+ })
207
+ }
208
+
209
+ export const hybridVoiceAgent = new Agent({
210
+ id: 'hybrid-voice-agent',
211
+ name: 'Hybrid Voice Agent',
212
+ model: 'openai/gpt-5.4',
213
+ instructions: 'You can speak and listen using different providers.',
214
+ voice: new CompositeVoice({
215
+ input: new OpenAIVoice(),
216
+ output: new OpenAIVoice(),
217
+ }),
218
+ })
219
+
220
+ export const unifiedVoiceAgent = new Agent({
221
+ id: 'unified-voice-agent',
222
+ name: 'Unified Voice Agent',
223
+ instructions: 'You are an agent with both STT and TTS capabilities.',
224
+ model: 'openai/gpt-5.4',
225
+ voice: new OpenAIVoice(),
226
+ })
227
+
228
+ export const mastra = new Mastra({
229
+ agents: { hybridVoiceAgent, unifiedVoiceAgent },
230
+ })
231
+
232
+ const hybridVoiceAgent = mastra.getAgent('hybridVoiceAgent')
233
+ const unifiedVoiceAgent = mastra.getAgent('unifiedVoiceAgent')
234
+
235
+ const question = 'What is the meaning of life in one sentence?'
236
+
237
+ const hybridSpoken = await hybridVoiceAgent.voice.speak(question)
238
+
239
+ await saveAudioToFile(hybridSpoken!, 'hybrid-question.mp3')
240
+
241
+ const audioStream = createReadStream(path.join(process.cwd(), 'audio', 'hybrid-question.mp3'))
242
+ const unifiedHeard = await unifiedVoiceAgent.voice.listen(audioStream)
243
+
244
+ const inputText = await convertToText(unifiedHeard!)
245
+
246
+ const unifiedResponse = await unifiedVoiceAgent.generate(inputText)
247
+ const unifiedSpoken = await unifiedVoiceAgent.voice.speak(unifiedResponse.text)
248
+
249
+ await saveAudioToFile(unifiedSpoken!, 'unified-response.mp3')
250
+ ```
251
+
252
+ ### Using Multiple Providers
253
+
254
+ For more flexibility, you can use different providers for speaking and listening using the CompositeVoice class:
255
+
256
+ ```typescript
257
+ import { Agent } from '@mastra/core/agent'
258
+ import { CompositeVoice } from '@mastra/core/voice'
259
+ import { OpenAIVoice } from '@mastra/voice-openai'
260
+ import { PlayAIVoice } from '@mastra/voice-playai'
261
+
262
+ export const agent = new Agent({
263
+ id: 'voice-agent',
264
+ name: 'Voice Agent',
265
+ instructions: `You are a helpful assistant with both STT and TTS capabilities.`,
266
+ model: 'openai/gpt-5.4',
267
+
268
+ // Create a composite voice using OpenAI for listening and PlayAI for speaking
269
+ voice: new CompositeVoice({
270
+ input: new OpenAIVoice(),
271
+ output: new PlayAIVoice(),
272
+ }),
273
+ })
274
+ ```
275
+
276
+ ### Using AI SDK
277
+
278
+ Mastra supports using AI SDK's transcription and speech models directly in `CompositeVoice`, giving you access to a wide range of providers through the AI SDK ecosystem:
279
+
280
+ ```typescript
281
+ import { Agent } from '@mastra/core/agent'
282
+ import { CompositeVoice } from '@mastra/core/voice'
283
+ import { openai } from '@ai-sdk/openai'
284
+ import { elevenlabs } from '@ai-sdk/elevenlabs'
285
+ import { groq } from '@ai-sdk/groq'
286
+
287
+ export const agent = new Agent({
288
+ id: 'aisdk-voice-agent',
289
+ name: 'AI SDK Voice Agent',
290
+ instructions: `You are a helpful assistant with voice capabilities.`,
291
+ model: 'openai/gpt-5.4',
292
+
293
+ // Pass AI SDK models directly to CompositeVoice
294
+ voice: new CompositeVoice({
295
+ input: openai.transcription('whisper-1'), // AI SDK transcription model
296
+ output: elevenlabs.speech('eleven_turbo_v2'), // AI SDK speech model
297
+ }),
298
+ })
299
+
300
+ // Use voice capabilities as usual
301
+ const audioStream = await agent.voice.speak('Hello!')
302
+ const transcribedText = await agent.voice.listen(audioStream)
303
+ ```
304
+
305
+ #### Mix and Match Providers
306
+
307
+ You can mix AI SDK models with Mastra voice providers:
308
+
309
+ ```typescript
310
+ import { CompositeVoice } from '@mastra/core/voice'
311
+ import { PlayAIVoice } from '@mastra/voice-playai'
312
+ import { openai } from '@ai-sdk/openai'
313
+
314
+ // Use AI SDK for transcription and Mastra provider for speech
315
+ const voice = new CompositeVoice({
316
+ input: openai.transcription('whisper-1'), // AI SDK
317
+ output: new PlayAIVoice(), // Mastra provider
318
+ })
319
+ ```
320
+
321
+ For the complete list of supported AI SDK providers and their capabilities:
322
+
323
+ - [Transcription](https://ai-sdk.dev/docs/providers/openai/transcription)
324
+ - [Speech](https://ai-sdk.dev/docs/providers/elevenlabs/speech)
325
+
326
+ ## Supported voice providers
327
+
328
+ Mastra supports multiple voice providers for text-to-speech (TTS) and speech-to-text (STT) capabilities:
329
+
330
+ | Provider | Package | Features | Reference |
331
+ | --------------- | ------------------------------- | ----------------------------------------- | ------------------------------------------------------------------ |
332
+ | OpenAI | `@mastra/voice-openai` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/openai) |
333
+ | OpenAI Realtime | `@mastra/voice-openai-realtime` | Realtime speech-to-speech | [Documentation](https://mastra.ai/reference/voice/openai-realtime) |
334
+ | AWS Nova Sonic | `@mastra/voice-aws-nova-sonic` | Realtime speech-to-speech via AWS Bedrock | [Documentation](https://mastra.ai/reference/voice/aws-nova-sonic) |
335
+ | ElevenLabs | `@mastra/voice-elevenlabs` | High-quality TTS | [Documentation](https://mastra.ai/reference/voice/elevenlabs) |
336
+ | PlayAI | `@mastra/voice-playai` | TTS | [Documentation](https://mastra.ai/reference/voice/playai) |
337
+ | Google | `@mastra/voice-google` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/google) |
338
+ | Deepgram | `@mastra/voice-deepgram` | STT | [Documentation](https://mastra.ai/reference/voice/deepgram) |
339
+ | Murf | `@mastra/voice-murf` | TTS | [Documentation](https://mastra.ai/reference/voice/murf) |
340
+ | Speechify | `@mastra/voice-speechify` | TTS | [Documentation](https://mastra.ai/reference/voice/speechify) |
341
+ | Sarvam | `@mastra/voice-sarvam` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/sarvam) |
342
+ | Azure | `@mastra/voice-azure` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/mastra-voice) |
343
+ | Cloudflare | `@mastra/voice-cloudflare` | TTS | [Documentation](https://mastra.ai/reference/voice/mastra-voice) |
344
+
345
+ ## Next steps
346
+
347
+ - [Voice API Reference](https://mastra.ai/reference/voice/mastra-voice): Detailed API documentation for voice capabilities
348
+ - [Text to Speech Examples](https://github.com/mastra-ai/voice-examples/tree/main/text-to-speech): Interactive story generator and other TTS implementations
349
+ - [Speech to Text Examples](https://github.com/mastra-ai/voice-examples/tree/main/speech-to-text): Voice memo app and other STT implementations
350
+ - [Speech to Speech Examples](https://github.com/mastra-ai/voice-examples/tree/main/speech-to-speech): Real-time voice conversation with call analysis