@mastra/mcp-docs-server 0.13.44 → 0.13.45-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.
Files changed (95) hide show
  1. package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +201 -1
  2. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +201 -1
  3. package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +253 -53
  4. package/.docs/organized/changelogs/%40mastra%2Fastra.md +201 -1
  5. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +201 -1
  6. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +201 -1
  7. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +201 -1
  8. package/.docs/organized/changelogs/%40mastra%2Fcloud.md +201 -1
  9. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +201 -1
  10. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +201 -1
  11. package/.docs/organized/changelogs/%40mastra%2Fcore.md +307 -107
  12. package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +201 -1
  13. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +201 -1
  14. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +201 -1
  15. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +201 -1
  16. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +201 -1
  17. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +201 -1
  18. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +201 -1
  19. package/.docs/organized/changelogs/%40mastra%2Fevals.md +201 -1
  20. package/.docs/organized/changelogs/%40mastra%2Flance.md +201 -1
  21. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +201 -1
  22. package/.docs/organized/changelogs/%40mastra%2Floggers.md +201 -1
  23. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +201 -1
  24. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +201 -1
  25. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +201 -1
  26. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +201 -1
  27. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +201 -1
  28. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +201 -1
  29. package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +201 -1
  30. package/.docs/organized/changelogs/%40mastra%2Fpg.md +201 -1
  31. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +201 -1
  32. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +201 -1
  33. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +201 -1
  34. package/.docs/organized/changelogs/%40mastra%2Frag.md +201 -1
  35. package/.docs/organized/changelogs/%40mastra%2Freact.md +182 -1
  36. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +36 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fserver.md +201 -1
  38. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +201 -1
  39. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +201 -1
  40. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +201 -1
  41. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +201 -1
  42. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +201 -1
  43. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +201 -1
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +201 -1
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +104 -1
  46. package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +49 -1
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +201 -1
  48. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +201 -1
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +201 -1
  50. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +201 -1
  51. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +201 -1
  52. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +201 -1
  53. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +201 -1
  54. package/.docs/organized/changelogs/create-mastra.md +201 -1
  55. package/.docs/organized/changelogs/mastra.md +201 -1
  56. package/.docs/raw/agents/adding-voice.mdx +49 -0
  57. package/.docs/raw/course/01-first-agent/05-running-playground.md +5 -5
  58. package/.docs/raw/course/01-first-agent/09-testing-your-agent.md +3 -3
  59. package/.docs/raw/course/01-first-agent/13-testing-your-tool.md +3 -3
  60. package/.docs/raw/course/01-first-agent/17-testing-memory.md +2 -2
  61. package/.docs/raw/course/04-workflows/07-using-playground.md +1 -1
  62. package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +23 -1
  63. package/.docs/raw/reference/client-js/memory.mdx +43 -0
  64. package/.docs/raw/reference/core/mastra-class.mdx +8 -0
  65. package/.docs/raw/reference/core/mastra-model-gateway.mdx +223 -0
  66. package/.docs/raw/reference/scorers/answer-relevancy.mdx +28 -98
  67. package/.docs/raw/reference/scorers/answer-similarity.mdx +12 -258
  68. package/.docs/raw/reference/scorers/bias.mdx +29 -87
  69. package/.docs/raw/reference/scorers/completeness.mdx +32 -91
  70. package/.docs/raw/reference/scorers/content-similarity.mdx +29 -99
  71. package/.docs/raw/reference/scorers/context-precision.mdx +28 -130
  72. package/.docs/raw/reference/scorers/faithfulness.mdx +28 -101
  73. package/.docs/raw/reference/scorers/hallucination.mdx +28 -103
  74. package/.docs/raw/reference/scorers/keyword-coverage.mdx +28 -107
  75. package/.docs/raw/reference/scorers/textual-difference.mdx +27 -100
  76. package/.docs/raw/reference/scorers/tone-consistency.mdx +25 -98
  77. package/.docs/raw/reference/scorers/toxicity.mdx +29 -92
  78. package/.docs/raw/reference/storage/cloudflare-d1.mdx +37 -0
  79. package/.docs/raw/reference/storage/lance.mdx +33 -0
  80. package/.docs/raw/reference/storage/libsql.mdx +37 -0
  81. package/.docs/raw/reference/storage/mongodb.mdx +39 -0
  82. package/.docs/raw/reference/storage/mssql.mdx +37 -0
  83. package/.docs/raw/reference/storage/postgresql.mdx +37 -0
  84. package/.docs/raw/reference/streaming/agents/stream.mdx +7 -0
  85. package/.docs/raw/reference/voice/composite-voice.mdx +71 -28
  86. package/.docs/raw/reference/voice/voice.listen.mdx +86 -52
  87. package/.docs/raw/reference/voice/voice.speak.mdx +75 -40
  88. package/.docs/raw/voice/overview.mdx +67 -0
  89. package/.docs/raw/workflows/control-flow.mdx +180 -0
  90. package/CHANGELOG.md +10 -0
  91. package/dist/{chunk-TUAHUTTB.js → chunk-VE65X75W.js} +24 -4
  92. package/dist/prepare-docs/package-changes.d.ts.map +1 -1
  93. package/dist/prepare-docs/prepare.js +1 -1
  94. package/dist/stdio.js +1 -1
  95. package/package.json +5 -5
@@ -72,3 +72,40 @@ The storage implementation handles schema creation and updates automatically. It
72
72
  - `mastra_traces`: Stores telemetry and tracing data
73
73
  - `mastra_scorers`: Stores scoring and evaluation data
74
74
  - `mastra_resources`: Stores resource working memory data
75
+
76
+ ### Initialization
77
+
78
+ When you pass storage to the Mastra class, `init()` is called automatically before any storage operation:
79
+
80
+ ```typescript copy
81
+ import { Mastra } from "@mastra/core";
82
+ import { LibSQLStore } from "@mastra/libsql";
83
+
84
+ const storage = new LibSQLStore({
85
+ url: "file:./storage.db",
86
+ });
87
+
88
+ const mastra = new Mastra({
89
+ storage, // init() is called automatically
90
+ });
91
+ ```
92
+
93
+ If you're using storage directly without Mastra, you must call `init()` explicitly to create the tables:
94
+
95
+ ```typescript copy
96
+ import { LibSQLStore } from "@mastra/libsql";
97
+
98
+ const storage = new LibSQLStore({
99
+ url: "file:./storage.db",
100
+ });
101
+
102
+ // Required when using storage directly
103
+ await storage.init();
104
+
105
+ // Now you can use the storage
106
+ await storage.getThread({ threadId: "..." });
107
+ ```
108
+
109
+ :::warning
110
+ If `init()` is not called, tables won't be created and storage operations will fail silently or throw errors.
111
+ :::
@@ -93,6 +93,45 @@ The storage implementation handles collection creation and management automatica
93
93
  - `mastra_scorers`: Stores scoring and evaluation data
94
94
  - `mastra_resources`: Stores resource working memory data
95
95
 
96
+ ### Initialization
97
+
98
+ When you pass storage to the Mastra class, `init()` is called automatically before any storage operation:
99
+
100
+ ```typescript copy
101
+ import { Mastra } from "@mastra/core";
102
+ import { MongoDBStore } from "@mastra/mongodb";
103
+
104
+ const storage = new MongoDBStore({
105
+ url: process.env.MONGODB_URL,
106
+ dbName: process.env.MONGODB_DATABASE,
107
+ });
108
+
109
+ const mastra = new Mastra({
110
+ storage, // init() is called automatically
111
+ });
112
+ ```
113
+
114
+ If you're using storage directly without Mastra, you must call `init()` explicitly to create the collections:
115
+
116
+ ```typescript copy
117
+ import { MongoDBStore } from "@mastra/mongodb";
118
+
119
+ const storage = new MongoDBStore({
120
+ url: process.env.MONGODB_URL,
121
+ dbName: process.env.MONGODB_DATABASE,
122
+ });
123
+
124
+ // Required when using storage directly
125
+ await storage.init();
126
+
127
+ // Now you can use the storage
128
+ await storage.getThread({ threadId: "..." });
129
+ ```
130
+
131
+ :::warning
132
+ If `init()` is not called, collections won't be created and storage operations will fail silently or throw errors.
133
+ :::
134
+
96
135
  ## Vector Search Capabilities
97
136
 
98
137
  MongoDB storage includes built-in vector search capabilities for AI applications:
@@ -96,6 +96,43 @@ The storage implementation handles schema creation and updates automatically. It
96
96
  - `mastra_scorers`: Stores scoring and evaluation data
97
97
  - `mastra_resources`: Stores resource working memory data
98
98
 
99
+ ### Initialization
100
+
101
+ When you pass storage to the Mastra class, `init()` is called automatically before any storage operation:
102
+
103
+ ```typescript copy
104
+ import { Mastra } from "@mastra/core";
105
+ import { MSSQLStore } from "@mastra/mssql";
106
+
107
+ const storage = new MSSQLStore({
108
+ connectionString: process.env.DATABASE_URL,
109
+ });
110
+
111
+ const mastra = new Mastra({
112
+ storage, // init() is called automatically
113
+ });
114
+ ```
115
+
116
+ If you're using storage directly without Mastra, you must call `init()` explicitly to create the tables:
117
+
118
+ ```typescript copy
119
+ import { MSSQLStore } from "@mastra/mssql";
120
+
121
+ const storage = new MSSQLStore({
122
+ connectionString: process.env.DATABASE_URL,
123
+ });
124
+
125
+ // Required when using storage directly
126
+ await storage.init();
127
+
128
+ // Now you can use the storage
129
+ await storage.getThread({ threadId: "..." });
130
+ ```
131
+
132
+ :::warning
133
+ If `init()` is not called, tables won't be created and storage operations will fail silently or throw errors.
134
+ :::
135
+
99
136
  ### Direct Database and Pool Access
100
137
 
101
138
  `MSSQLStore` exposes the mssql connection pool as public fields:
@@ -96,6 +96,43 @@ The storage implementation handles schema creation and updates automatically. It
96
96
  - `mastra_scorers`: Stores scoring and evaluation data
97
97
  - `mastra_resources`: Stores resource working memory data
98
98
 
99
+ ### Initialization
100
+
101
+ When you pass storage to the Mastra class, `init()` is called automatically before any storage operation:
102
+
103
+ ```typescript copy
104
+ import { Mastra } from "@mastra/core";
105
+ import { PostgresStore } from "@mastra/pg";
106
+
107
+ const storage = new PostgresStore({
108
+ connectionString: process.env.DATABASE_URL,
109
+ });
110
+
111
+ const mastra = new Mastra({
112
+ storage, // init() is called automatically
113
+ });
114
+ ```
115
+
116
+ If you're using storage directly without Mastra, you must call `init()` explicitly to create the tables:
117
+
118
+ ```typescript copy
119
+ import { PostgresStore } from "@mastra/pg";
120
+
121
+ const storage = new PostgresStore({
122
+ connectionString: process.env.DATABASE_URL,
123
+ });
124
+
125
+ // Required when using storage directly
126
+ await storage.init();
127
+
128
+ // Now you can use the storage
129
+ await storage.getThread({ threadId: "..." });
130
+ ```
131
+
132
+ :::warning
133
+ If `init()` is not called, tables won't be created and storage operations will fail silently or throw errors.
134
+ :::
135
+
99
136
  ### Direct Database and Pool Access
100
137
 
101
138
  `PostgresStore` exposes both the underlying database object and the pg-promise instance as public fields:
@@ -254,6 +254,13 @@ const aiSdkStream = await agent.stream("message for agent", {
254
254
  description:
255
255
  "Overrides the output processors set on the agent. Output processors that can modify or validate messages from the agent before they are returned to the user. Must implement either (or both) of the `processOutputResult` and `processOutputStream` functions.",
256
256
  },
257
+ {
258
+ name: "includeRawChunks",
259
+ type: "boolean",
260
+ isOptional: true,
261
+ description:
262
+ "Whether to include raw chunks in the stream output (not available on all model providers).",
263
+ },
257
264
  {
258
265
  name: "inputProcessors",
259
266
  type: "Processor[]",
@@ -7,31 +7,7 @@ description: "Documentation for the CompositeVoice class, which enables combinin
7
7
 
8
8
  The CompositeVoice class allows you to combine different voice providers for text-to-speech and speech-to-text operations. This is particularly useful when you want to use the best provider for each operation - for example, using OpenAI for speech-to-text and PlayAI for text-to-speech.
9
9
 
10
- CompositeVoice is used internally by the Agent class to provide flexible voice capabilities.
11
-
12
- ## Usage Example
13
-
14
- ```typescript
15
- import { CompositeVoice } from "@mastra/core/voice";
16
- import { OpenAIVoice } from "@mastra/voice-openai";
17
- import { PlayAIVoice } from "@mastra/voice-playai";
18
-
19
- // Create voice providers
20
- const openai = new OpenAIVoice();
21
- const playai = new PlayAIVoice();
22
-
23
- // Use OpenAI for listening (speech-to-text) and PlayAI for speaking (text-to-speech)
24
- const voice = new CompositeVoice({
25
- input: openai,
26
- output: playai,
27
- });
28
-
29
- // Convert speech to text using OpenAI
30
- const text = await voice.listen(audioStream);
31
-
32
- // Convert text to speech using PlayAI
33
- const audio = await voice.speak("Hello, world!");
34
- ```
10
+ CompositeVoice supports both Mastra voice providers and AI SDK model providers
35
11
 
36
12
  ## Constructor Parameters
37
13
 
@@ -45,14 +21,20 @@ const audio = await voice.speak("Hello, world!");
45
21
  },
46
22
  {
47
23
  name: "config.input",
48
- type: "MastraVoice",
49
- description: "Voice provider to use for speech-to-text operations",
24
+ type: "MastraVoice | TranscriptionModel",
25
+ description: "Voice provider or AI SDK transcription model to use for speech-to-text operations. AI SDK models are automatically wrapped.",
50
26
  isOptional: true,
51
27
  },
52
28
  {
53
29
  name: "config.output",
30
+ type: "MastraVoice | SpeechModel",
31
+ description: "Voice provider or AI SDK speech model to use for text-to-speech operations. AI SDK models are automatically wrapped.",
32
+ isOptional: true,
33
+ },
34
+ {
35
+ name: "config.realtime",
54
36
  type: "MastraVoice",
55
- description: "Voice provider to use for text-to-speech operations",
37
+ description: "Voice provider to use for real-time speech-to-speech operations",
56
38
  isOptional: true,
57
39
  },
58
40
  ]}
@@ -142,3 +124,64 @@ Notes:
142
124
  - If no speaking provider is configured, returns an empty array
143
125
  - Each voice object will have at least a voiceId property
144
126
  - Additional voice properties depend on the speaking provider
127
+
128
+ ## Usage Examples
129
+
130
+ ### Using Mastra Voice Providers
131
+
132
+ ```typescript
133
+ import { CompositeVoice } from "@mastra/core/voice";
134
+ import { OpenAIVoice } from "@mastra/voice-openai";
135
+ import { PlayAIVoice } from "@mastra/voice-playai";
136
+
137
+ // Create voice providers
138
+ const openai = new OpenAIVoice();
139
+ const playai = new PlayAIVoice();
140
+
141
+ // Use OpenAI for listening (speech-to-text) and PlayAI for speaking (text-to-speech)
142
+ const voice = new CompositeVoice({
143
+ input: openai,
144
+ output: playai,
145
+ });
146
+
147
+ // Convert speech to text using OpenAI
148
+ const text = await voice.listen(audioStream);
149
+
150
+ // Convert text to speech using PlayAI
151
+ const audio = await voice.speak("Hello, world!");
152
+ ```
153
+
154
+ ### Using AI SDK Model Providers
155
+
156
+ You can pass AI SDK transcription and speech models directly to CompositeVoice:
157
+
158
+ ```typescript
159
+ import { CompositeVoice } from "@mastra/core/voice";
160
+ import { openai } from "@ai-sdk/openai";
161
+ import { elevenlabs } from "@ai-sdk/elevenlabs";
162
+
163
+ // Use AI SDK models directly - they will be auto-wrapped
164
+ const voice = new CompositeVoice({
165
+ input: openai.transcription('whisper-1'), // AI SDK transcription
166
+ output: elevenlabs.speech('eleven_turbo_v2'), // AI SDK speech
167
+ });
168
+
169
+ // Works the same way as with Mastra providers
170
+ const text = await voice.listen(audioStream);
171
+ const audio = await voice.speak("Hello from AI SDK!");
172
+ ```
173
+
174
+ ### Mix and Match
175
+
176
+ You can combine Mastra providers with AI SDK models:
177
+
178
+ ```typescript
179
+ import { CompositeVoice } from "@mastra/core/voice";
180
+ import { PlayAIVoice } from "@mastra/voice-playai";
181
+ import { groq } from "@ai-sdk/groq";
182
+
183
+ const voice = new CompositeVoice({
184
+ input: groq.transcription('whisper-large-v3'), // AI SDK for STT
185
+ output: new PlayAIVoice(), // Mastra for TTS
186
+ });
187
+ ```
@@ -7,41 +7,6 @@ description: "Documentation for the listen() method available in all Mastra voic
7
7
 
8
8
  The `listen()` method is a core function available in all Mastra voice providers that converts speech to text. It takes an audio stream as input and returns the transcribed text.
9
9
 
10
- ## Usage Example
11
-
12
- ```typescript
13
- import { OpenAIVoice } from "@mastra/voice-openai";
14
- import { getMicrophoneStream } from "@mastra/node-audio";
15
- import { createReadStream } from "fs";
16
- import path from "path";
17
-
18
- // Initialize a voice provider
19
- const voice = new OpenAIVoice({
20
- listeningModel: {
21
- name: "whisper-1",
22
- apiKey: process.env.OPENAI_API_KEY,
23
- },
24
- });
25
-
26
- // Basic usage with a file stream
27
- const audioFilePath = path.join(process.cwd(), "audio.mp3");
28
- const audioStream = createReadStream(audioFilePath);
29
- const transcript = await voice.listen(audioStream, {
30
- filetype: "mp3",
31
- });
32
- console.log("Transcribed text:", transcript);
33
-
34
- // Using a microphone stream
35
- const microphoneStream = getMicrophoneStream(); // Assume this function gets audio input
36
- const transcription = await voice.listen(microphoneStream);
37
-
38
- // With provider-specific options
39
- const transcriptWithOptions = await voice.listen(audioStream, {
40
- language: "en",
41
- prompt: "This is a conversation about artificial intelligence.",
42
- });
43
- ```
44
-
45
10
  ## Parameters
46
11
 
47
12
  <PropertiesTable
@@ -143,30 +108,42 @@ Each voice provider may support additional options specific to their implementat
143
108
  ]}
144
109
  />
145
110
 
146
- ## Realtime Voice Providers
147
-
148
- When using realtime voice providers like `OpenAIRealtimeVoice`, the `listen()` method behaves differently:
149
-
150
- - Instead of returning transcribed text, it emits 'writing' events with the transcribed text
151
- - You need to register an event listener to receive the transcription
111
+ ## Usage Example
152
112
 
153
113
  ```typescript
154
- import { OpenAIRealtimeVoice } from "@mastra/voice-openai-realtime";
114
+ import { OpenAIVoice } from "@mastra/voice-openai";
155
115
  import { getMicrophoneStream } from "@mastra/node-audio";
116
+ import { createReadStream } from "fs";
117
+ import path from "path";
156
118
 
157
- const voice = new OpenAIRealtimeVoice();
158
- await voice.connect();
119
+ // Initialize a voice provider
120
+ const voice = new OpenAIVoice({
121
+ listeningModel: {
122
+ name: "whisper-1",
123
+ apiKey: process.env.OPENAI_API_KEY,
124
+ },
125
+ });
159
126
 
160
- // Register event listener for transcription
161
- voice.on("writing", ({ text, role }) => {
162
- console.log(`${role}: ${text}`);
127
+ // Basic usage with a file stream
128
+ const audioFilePath = path.join(process.cwd(), "audio.mp3");
129
+ const audioStream = createReadStream(audioFilePath);
130
+ const transcript = await voice.listen(audioStream, {
131
+ filetype: "mp3",
163
132
  });
133
+ console.log("Transcribed text:", transcript);
164
134
 
165
- // This will emit 'writing' events instead of returning text
166
- const microphoneStream = getMicrophoneStream();
167
- await voice.listen(microphoneStream);
135
+ // Using a microphone stream
136
+ const microphoneStream = getMicrophoneStream(); // Assume this function gets audio input
137
+ const transcription = await voice.listen(microphoneStream);
138
+
139
+ // With provider-specific options
140
+ const transcriptWithOptions = await voice.listen(audioStream, {
141
+ language: "en",
142
+ prompt: "This is a conversation about artificial intelligence.",
143
+ });
168
144
  ```
169
145
 
146
+
170
147
  ## Using with CompositeVoice
171
148
 
172
149
  When using `CompositeVoice`, the `listen()` method delegates to the configured listening provider:
@@ -177,14 +154,70 @@ import { OpenAIVoice } from "@mastra/voice-openai";
177
154
  import { PlayAIVoice } from "@mastra/voice-playai";
178
155
 
179
156
  const voice = new CompositeVoice({
180
- listenProvider: new OpenAIVoice(),
181
- speakProvider: new PlayAIVoice(),
157
+ input: new OpenAIVoice(),
158
+ output: new PlayAIVoice(),
182
159
  });
183
160
 
184
161
  // This will use the OpenAIVoice provider
185
162
  const transcript = await voice.listen(audioStream);
186
163
  ```
187
164
 
165
+ ### Using AI SDK Model Providers
166
+
167
+ You can also use AI SDK transcription models directly with `CompositeVoice`:
168
+
169
+ ```typescript
170
+ import { CompositeVoice } from "@mastra/core/voice";
171
+ import { openai } from "@ai-sdk/openai";
172
+ import { groq } from "@ai-sdk/groq";
173
+
174
+ // Use AI SDK transcription models
175
+ const voice = new CompositeVoice({
176
+ input: openai.transcription('whisper-1'), // AI SDK model
177
+ output: new PlayAIVoice(), // Mastra provider
178
+ });
179
+
180
+ // Works the same way
181
+ const transcript = await voice.listen(audioStream);
182
+
183
+ // Provider-specific options can be passed through
184
+ const transcriptWithOptions = await voice.listen(audioStream, {
185
+ providerOptions: {
186
+ openai: {
187
+ language: 'en',
188
+ prompt: 'This is about AI',
189
+ }
190
+ }
191
+ });
192
+ ```
193
+
194
+ See the [CompositeVoice reference](/reference/voice/composite-voice) for more details on AI SDK integration.
195
+
196
+
197
+ ## Realtime Voice Providers
198
+
199
+ When using realtime voice providers like `OpenAIRealtimeVoice`, the `listen()` method behaves differently:
200
+
201
+ - Instead of returning transcribed text, it emits 'writing' events with the transcribed text
202
+ - You need to register an event listener to receive the transcription
203
+
204
+ ```typescript
205
+ import { OpenAIRealtimeVoice } from "@mastra/voice-openai-realtime";
206
+ import { getMicrophoneStream } from "@mastra/node-audio";
207
+
208
+ const voice = new OpenAIRealtimeVoice();
209
+ await voice.connect();
210
+
211
+ // Register event listener for transcription
212
+ voice.on("writing", ({ text, role }) => {
213
+ console.log(`${role}: ${text}`);
214
+ });
215
+
216
+ // This will emit 'writing' events instead of returning text
217
+ const microphoneStream = getMicrophoneStream();
218
+ await voice.listen(microphoneStream);
219
+ ```
220
+
188
221
  ## Notes
189
222
 
190
223
  - Not all voice providers support speech-to-text functionality (e.g., PlayAI, Speechify)
@@ -194,6 +227,7 @@ const transcript = await voice.listen(audioStream);
194
227
  - Some providers support streaming transcription, where text is returned as it's transcribed
195
228
  - For best performance, consider closing or ending the audio stream when you're done with it
196
229
 
230
+
197
231
  ## Related Methods
198
232
 
199
233
  - [voice.speak()](./voice.speak) - Converts text to speech
@@ -7,31 +7,6 @@ description: "Documentation for the speak() method available in all Mastra voice
7
7
 
8
8
  The `speak()` method is a core function available in all Mastra voice providers that converts text to speech. It takes text input and returns an audio stream that can be played or saved.
9
9
 
10
- ## Usage Example
11
-
12
- ```typescript
13
- import { OpenAIVoice } from "@mastra/voice-openai";
14
- // Initialize a voice provider
15
- const voice = new OpenAIVoice({
16
- speaker: "alloy", // Default voice
17
- });
18
- // Basic usage with default settings
19
- const audioStream = await voice.speak("Hello, world!");
20
- // Using a different voice for this specific request
21
- const audioStreamWithDifferentVoice = await voice.speak("Hello again!", {
22
- speaker: "nova",
23
- });
24
- // Using provider-specific options
25
- const audioStreamWithOptions = await voice.speak("Hello with options!", {
26
- speaker: "echo",
27
- speed: 1.2, // OpenAI-specific option
28
- });
29
- // Using a text stream as input
30
- import { Readable } from "stream";
31
- const textStream = Readable.from(["Hello", " from", " a", " stream!"]);
32
- const audioStreamFromTextStream = await voice.speak(textStream);
33
- ```
34
-
35
10
  ## Parameters
36
11
 
37
12
  <PropertiesTable
@@ -153,6 +128,81 @@ Each voice provider may support additional options specific to their implementat
153
128
  ]}
154
129
  />
155
130
 
131
+ ## Usage Example
132
+
133
+ ```typescript
134
+ import { OpenAIVoice } from "@mastra/voice-openai";
135
+ // Initialize a voice provider
136
+ const voice = new OpenAIVoice({
137
+ speaker: "alloy", // Default voice
138
+ });
139
+ // Basic usage with default settings
140
+ const audioStream = await voice.speak("Hello, world!");
141
+ // Using a different voice for this specific request
142
+ const audioStreamWithDifferentVoice = await voice.speak("Hello again!", {
143
+ speaker: "nova",
144
+ });
145
+ // Using provider-specific options
146
+ const audioStreamWithOptions = await voice.speak("Hello with options!", {
147
+ speaker: "echo",
148
+ speed: 1.2, // OpenAI-specific option
149
+ });
150
+ // Using a text stream as input
151
+ import { Readable } from "stream";
152
+ const textStream = Readable.from(["Hello", " from", " a", " stream!"]);
153
+ const audioStreamFromTextStream = await voice.speak(textStream);
154
+ ```
155
+
156
+ ## Using with CompositeVoice
157
+
158
+ When using `CompositeVoice`, the `speak()` method delegates to the configured speaking provider:
159
+
160
+ ```typescript
161
+ import { CompositeVoice } from "@mastra/core/voice";
162
+ import { OpenAIVoice } from "@mastra/voice-openai";
163
+ import { PlayAIVoice } from "@mastra/voice-playai";
164
+
165
+ const voice = new CompositeVoice({
166
+ output: new PlayAIVoice(),
167
+ input: new OpenAIVoice(),
168
+ });
169
+
170
+ // This will use the PlayAIVoice provider
171
+ const audioStream = await voice.speak("Hello, world!");
172
+ ```
173
+
174
+ ### Using AI SDK Model Providers
175
+
176
+ You can also use AI SDK speech models directly with `CompositeVoice`:
177
+
178
+ ```typescript
179
+ import { CompositeVoice } from "@mastra/core/voice";
180
+ import { openai } from "@ai-sdk/openai";
181
+ import { elevenlabs } from "@ai-sdk/elevenlabs";
182
+
183
+ // Use AI SDK speech models
184
+ const voice = new CompositeVoice({
185
+ output: elevenlabs.speech('eleven_turbo_v2'), // AI SDK model
186
+ input: openai.transcription('whisper-1'), // AI SDK model
187
+ });
188
+
189
+ // Works the same way
190
+ const audioStream = await voice.speak("Hello from AI SDK!");
191
+
192
+ // Provider-specific options can be passed through
193
+ const audioWithOptions = await voice.speak("Hello with options!", {
194
+ speaker: 'Rachel', // ElevenLabs voice
195
+ providerOptions: {
196
+ elevenlabs: {
197
+ stability: 0.5,
198
+ similarity_boost: 0.75,
199
+ }
200
+ }
201
+ });
202
+ ```
203
+
204
+ See the [CompositeVoice reference](/reference/voice/composite-voice) for more details on AI SDK integration.
205
+
156
206
  ## Realtime Voice Providers
157
207
 
158
208
  When using realtime voice providers like `OpenAIRealtimeVoice`, the `speak()` method behaves differently:
@@ -181,21 +231,6 @@ voice.on("speaker", (stream) => {
181
231
  await voice.speak("Hello, this is realtime speech!");
182
232
  ```
183
233
 
184
- ## Using with CompositeVoice
185
-
186
- When using `CompositeVoice`, the `speak()` method delegates to the configured speaking provider:
187
-
188
- ```typescript
189
- import { CompositeVoice } from "@mastra/core/voice";
190
- import { OpenAIVoice } from "@mastra/voice-openai";
191
- import { PlayAIVoice } from "@mastra/voice-playai";
192
- const voice = new CompositeVoice({
193
- speakProvider: new PlayAIVoice(),
194
- listenProvider: new OpenAIVoice(),
195
- });
196
- // This will use the PlayAIVoice provider
197
- const audioStream = await voice.speak("Hello, world!");
198
- ```
199
234
 
200
235
  ## Notes
201
236