@mastra/mcp-docs-server 0.0.0-commonjs-20250414101718
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/.docs/organized/changelogs/%40mastra%2Fastra.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +161 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +110 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +26 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +196 -0
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +250 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +250 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
- package/.docs/organized/changelogs/create-mastra.md +302 -0
- package/.docs/organized/changelogs/mastra.md +302 -0
- package/.docs/organized/code-examples/agent-network.md +282 -0
- package/.docs/organized/code-examples/agent.md +388 -0
- package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
- package/.docs/organized/code-examples/assistant-ui.md +37 -0
- package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
- package/.docs/organized/code-examples/client-side-tools.md +69 -0
- package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
- package/.docs/organized/code-examples/fireworks-r1.md +159 -0
- package/.docs/organized/code-examples/mcp-registry-registry.md +63 -0
- package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
- package/.docs/organized/code-examples/memory-with-context.md +167 -0
- package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
- package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
- package/.docs/organized/code-examples/memory-with-pg.md +224 -0
- package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
- package/.docs/organized/code-examples/quick-start.md +129 -0
- package/.docs/organized/code-examples/stock-price-tool.md +124 -0
- package/.docs/organized/code-examples/weather-agent.md +353 -0
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
- package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
- package/.docs/raw/agents/adding-tools.mdx +317 -0
- package/.docs/raw/agents/adding-voice.mdx +175 -0
- package/.docs/raw/agents/agent-memory.mdx +62 -0
- package/.docs/raw/agents/mcp-guide.mdx +215 -0
- package/.docs/raw/agents/overview.mdx +303 -0
- package/.docs/raw/community/discord.mdx +12 -0
- package/.docs/raw/community/licensing.mdx +63 -0
- package/.docs/raw/deployment/client.mdx +120 -0
- package/.docs/raw/deployment/deployment.mdx +127 -0
- package/.docs/raw/deployment/server.mdx +282 -0
- package/.docs/raw/evals/custom-eval.mdx +22 -0
- package/.docs/raw/evals/overview.mdx +95 -0
- package/.docs/raw/evals/running-in-ci.mdx +81 -0
- package/.docs/raw/evals/textual-evals.mdx +54 -0
- package/.docs/raw/faq/index.mdx +63 -0
- package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
- package/.docs/raw/frameworks/next-js.mdx +238 -0
- package/.docs/raw/getting-started/installation.mdx +442 -0
- package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
- package/.docs/raw/getting-started/project-structure.mdx +80 -0
- package/.docs/raw/index.mdx +22 -0
- package/.docs/raw/integrations/index.mdx +213 -0
- package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
- package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
- package/.docs/raw/local-dev/mastra-dev.mdx +108 -0
- package/.docs/raw/memory/memory-processors.mdx +131 -0
- package/.docs/raw/memory/overview.mdx +119 -0
- package/.docs/raw/memory/semantic-recall.mdx +122 -0
- package/.docs/raw/memory/working-memory.mdx +87 -0
- package/.docs/raw/observability/logging.mdx +38 -0
- package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
- package/.docs/raw/observability/tracing.mdx +115 -0
- package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
- package/.docs/raw/rag/overview.mdx +85 -0
- package/.docs/raw/rag/retrieval.mdx +365 -0
- package/.docs/raw/rag/vector-databases.mdx +340 -0
- package/.docs/raw/reference/agents/createTool.mdx +229 -0
- package/.docs/raw/reference/agents/generate.mdx +334 -0
- package/.docs/raw/reference/agents/getAgent.mdx +54 -0
- package/.docs/raw/reference/agents/stream.mdx +369 -0
- package/.docs/raw/reference/cli/build.mdx +55 -0
- package/.docs/raw/reference/cli/dev.mdx +134 -0
- package/.docs/raw/reference/cli/init.mdx +43 -0
- package/.docs/raw/reference/client-js/agents.mdx +107 -0
- package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
- package/.docs/raw/reference/client-js/logs.mdx +24 -0
- package/.docs/raw/reference/client-js/memory.mdx +97 -0
- package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
- package/.docs/raw/reference/client-js/tools.mdx +44 -0
- package/.docs/raw/reference/client-js/vectors.mdx +79 -0
- package/.docs/raw/reference/client-js/workflows.mdx +136 -0
- package/.docs/raw/reference/core/mastra-class.mdx +232 -0
- package/.docs/raw/reference/deployer/cloudflare.mdx +207 -0
- package/.docs/raw/reference/deployer/deployer.mdx +159 -0
- package/.docs/raw/reference/deployer/netlify.mdx +109 -0
- package/.docs/raw/reference/deployer/vercel.mdx +117 -0
- package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
- package/.docs/raw/reference/evals/bias.mdx +186 -0
- package/.docs/raw/reference/evals/completeness.mdx +174 -0
- package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
- package/.docs/raw/reference/evals/context-position.mdx +190 -0
- package/.docs/raw/reference/evals/context-precision.mdx +189 -0
- package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
- package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
- package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
- package/.docs/raw/reference/evals/hallucination.mdx +219 -0
- package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
- package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
- package/.docs/raw/reference/evals/summarization.mdx +205 -0
- package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
- package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
- package/.docs/raw/reference/evals/toxicity.mdx +165 -0
- package/.docs/raw/reference/index.mdx +12 -0
- package/.docs/raw/reference/memory/Memory.mdx +212 -0
- package/.docs/raw/reference/memory/createThread.mdx +95 -0
- package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
- package/.docs/raw/reference/memory/query.mdx +167 -0
- package/.docs/raw/reference/networks/agent-network.mdx +159 -0
- package/.docs/raw/reference/observability/create-logger.mdx +106 -0
- package/.docs/raw/reference/observability/logger.mdx +55 -0
- package/.docs/raw/reference/observability/otel-config.mdx +120 -0
- package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
- package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
- package/.docs/raw/reference/observability/providers/index.mdx +16 -0
- package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
- package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
- package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
- package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
- package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
- package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
- package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
- package/.docs/raw/reference/rag/astra.mdx +258 -0
- package/.docs/raw/reference/rag/chroma.mdx +281 -0
- package/.docs/raw/reference/rag/chunk.mdx +235 -0
- package/.docs/raw/reference/rag/document.mdx +127 -0
- package/.docs/raw/reference/rag/embeddings.mdx +160 -0
- package/.docs/raw/reference/rag/extract-params.mdx +226 -0
- package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
- package/.docs/raw/reference/rag/libsql.mdx +357 -0
- package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
- package/.docs/raw/reference/rag/pg.mdx +477 -0
- package/.docs/raw/reference/rag/pinecone.mdx +281 -0
- package/.docs/raw/reference/rag/qdrant.mdx +236 -0
- package/.docs/raw/reference/rag/rerank.mdx +212 -0
- package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
- package/.docs/raw/reference/rag/upstash.mdx +247 -0
- package/.docs/raw/reference/rag/vectorize.mdx +298 -0
- package/.docs/raw/reference/storage/libsql.mdx +74 -0
- package/.docs/raw/reference/storage/postgresql.mdx +48 -0
- package/.docs/raw/reference/storage/upstash.mdx +86 -0
- package/.docs/raw/reference/tools/client.mdx +207 -0
- package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
- package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
- package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
- package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
- package/.docs/raw/reference/voice/deepgram.mdx +164 -0
- package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
- package/.docs/raw/reference/voice/google.mdx +198 -0
- package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
- package/.docs/raw/reference/voice/murf.mdx +251 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
- package/.docs/raw/reference/voice/openai.mdx +168 -0
- package/.docs/raw/reference/voice/playai.mdx +159 -0
- package/.docs/raw/reference/voice/sarvam.mdx +260 -0
- package/.docs/raw/reference/voice/speechify.mdx +145 -0
- package/.docs/raw/reference/voice/voice.answer.mdx +122 -0
- package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
- package/.docs/raw/reference/voice/voice.listen.mdx +195 -0
- package/.docs/raw/reference/voice/voice.on.mdx +189 -0
- package/.docs/raw/reference/voice/voice.send.mdx +118 -0
- package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
- package/.docs/raw/reference/workflows/after.mdx +88 -0
- package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
- package/.docs/raw/reference/workflows/commit.mdx +37 -0
- package/.docs/raw/reference/workflows/createRun.mdx +77 -0
- package/.docs/raw/reference/workflows/else.mdx +72 -0
- package/.docs/raw/reference/workflows/events.mdx +305 -0
- package/.docs/raw/reference/workflows/execute.mdx +110 -0
- package/.docs/raw/reference/workflows/if.mdx +107 -0
- package/.docs/raw/reference/workflows/resume.mdx +155 -0
- package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
- package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
- package/.docs/raw/reference/workflows/start.mdx +84 -0
- package/.docs/raw/reference/workflows/step-class.mdx +100 -0
- package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
- package/.docs/raw/reference/workflows/step-function.mdx +92 -0
- package/.docs/raw/reference/workflows/step-options.mdx +69 -0
- package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
- package/.docs/raw/reference/workflows/suspend.mdx +70 -0
- package/.docs/raw/reference/workflows/then.mdx +74 -0
- package/.docs/raw/reference/workflows/until.mdx +165 -0
- package/.docs/raw/reference/workflows/watch.mdx +118 -0
- package/.docs/raw/reference/workflows/while.mdx +168 -0
- package/.docs/raw/reference/workflows/workflow.mdx +233 -0
- package/.docs/raw/storage/overview.mdx +378 -0
- package/.docs/raw/voice/overview.mdx +135 -0
- package/.docs/raw/voice/speech-to-text.mdx +45 -0
- package/.docs/raw/voice/text-to-speech.mdx +52 -0
- package/.docs/raw/voice/voice-to-voice.mdx +310 -0
- package/.docs/raw/workflows/control-flow.mdx +778 -0
- package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
- package/.docs/raw/workflows/error-handling.mdx +183 -0
- package/.docs/raw/workflows/nested-workflows.mdx +352 -0
- package/.docs/raw/workflows/overview.mdx +203 -0
- package/.docs/raw/workflows/steps.mdx +108 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
- package/.docs/raw/workflows/variables.mdx +313 -0
- package/LICENSE.md +46 -0
- package/README.md +129 -0
- package/dist/_tsup-dts-rollup.d.ts +149 -0
- package/dist/chunk-QWYMT5LP.js +194 -0
- package/dist/prepare-docs/prepare.d.ts +1 -0
- package/dist/prepare-docs/prepare.js +1 -0
- package/dist/stdio.d.ts +1 -0
- package/dist/stdio.js +518 -0
- package/package.json +60 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: voice.connect() | Voice Providers | Mastra Docs"
|
|
3
|
+
description: "Documentation for the connect() method available in real-time voice providers, which establishes a connection for speech-to-speech communication."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# voice.connect()
|
|
7
|
+
|
|
8
|
+
The `connect()` method establishes a WebSocket or WebRTC connection for real-time speech-to-speech communication. This method must be called before using other real-time features like `send()` or `answer()`.
|
|
9
|
+
|
|
10
|
+
## Usage Example
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { OpenAIRealtimeVoice } from "@mastra/voice-openai-realtime";
|
|
14
|
+
import Speaker from "@mastra/node-speaker";
|
|
15
|
+
|
|
16
|
+
const speaker = new Speaker({
|
|
17
|
+
sampleRate: 24100, // Audio sample rate in Hz - standard for high-quality audio on MacBook Pro
|
|
18
|
+
channels: 1, // Mono audio output (as opposed to stereo which would be 2)
|
|
19
|
+
bitDepth: 16, // Bit depth for audio quality - CD quality standard (16-bit resolution)
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Initialize a real-time voice provider
|
|
23
|
+
const voice = new OpenAIRealtimeVoice({
|
|
24
|
+
realtimeConfig: {
|
|
25
|
+
model: "gpt-4o-mini-realtime",
|
|
26
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
27
|
+
options: {
|
|
28
|
+
sessionConfig: {
|
|
29
|
+
turn_detection: {
|
|
30
|
+
type: "server_vad",
|
|
31
|
+
threshold: 0.6,
|
|
32
|
+
silence_duration_ms: 1200,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
speaker: "alloy", // Default voice
|
|
38
|
+
});
|
|
39
|
+
// Connect to the real-time service
|
|
40
|
+
await voice.connect();
|
|
41
|
+
// Now you can use real-time features
|
|
42
|
+
voice.on("speaker", (stream) => {
|
|
43
|
+
stream.pipe(speaker);
|
|
44
|
+
});
|
|
45
|
+
// With connection options
|
|
46
|
+
await voice.connect({
|
|
47
|
+
timeout: 10000, // 10 seconds timeout
|
|
48
|
+
reconnect: true,
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## Parameters
|
|
54
|
+
|
|
55
|
+
<PropertiesTable
|
|
56
|
+
content={[
|
|
57
|
+
{
|
|
58
|
+
name: "options",
|
|
59
|
+
type: "Record<string, unknown>",
|
|
60
|
+
description: "Provider-specific connection options",
|
|
61
|
+
isOptional: true,
|
|
62
|
+
}
|
|
63
|
+
]}
|
|
64
|
+
/>
|
|
65
|
+
|
|
66
|
+
## Return Value
|
|
67
|
+
|
|
68
|
+
Returns a `Promise<void>` that resolves when the connection is successfully established.
|
|
69
|
+
|
|
70
|
+
## Provider-Specific Options
|
|
71
|
+
|
|
72
|
+
Each real-time voice provider may support different options for the `connect()` method:
|
|
73
|
+
|
|
74
|
+
### OpenAI Realtime
|
|
75
|
+
|
|
76
|
+
<PropertiesTable
|
|
77
|
+
content={[
|
|
78
|
+
{
|
|
79
|
+
name: "options.timeout",
|
|
80
|
+
type: "number",
|
|
81
|
+
description: "Connection timeout in milliseconds",
|
|
82
|
+
isOptional: true,
|
|
83
|
+
defaultValue: "30000",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "options.reconnect",
|
|
87
|
+
type: "boolean",
|
|
88
|
+
description: "Whether to automatically reconnect on connection loss",
|
|
89
|
+
isOptional: true,
|
|
90
|
+
defaultValue: "false",
|
|
91
|
+
}
|
|
92
|
+
]}
|
|
93
|
+
/>
|
|
94
|
+
|
|
95
|
+
## Using with CompositeVoice
|
|
96
|
+
|
|
97
|
+
When using `CompositeVoice`, the `connect()` method delegates to the configured real-time provider:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { CompositeVoice } from "@mastra/core/voice";
|
|
101
|
+
import { OpenAIRealtimeVoice } from "@mastra/voice-openai-realtime";
|
|
102
|
+
const realtimeVoice = new OpenAIRealtimeVoice();
|
|
103
|
+
const voice = new CompositeVoice({
|
|
104
|
+
realtimeProvider: realtimeVoice,
|
|
105
|
+
});
|
|
106
|
+
// This will use the OpenAIRealtimeVoice provider
|
|
107
|
+
await voice.connect();
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Notes
|
|
111
|
+
|
|
112
|
+
- This method is only implemented by real-time voice providers that support speech-to-speech capabilities
|
|
113
|
+
- If called on a voice provider that doesn't support this functionality, it will log a warning and resolve immediately
|
|
114
|
+
- The connection must be established before using other real-time methods like `send()` or `answer()`
|
|
115
|
+
- When you're done with the voice instance, call `close()` to properly clean up resources
|
|
116
|
+
- Some providers may automatically reconnect on connection loss, depending on their implementation
|
|
117
|
+
- Connection errors will typically be thrown as exceptions that should be caught and handled
|
|
118
|
+
|
|
119
|
+
## Related Methods
|
|
120
|
+
|
|
121
|
+
- [voice.send()](./voice.send) - Sends audio data to the voice provider
|
|
122
|
+
- [voice.answer()](./voice.answer) - Triggers the voice provider to respond
|
|
123
|
+
- [voice.close()](./voice.close) - Disconnects from the real-time service
|
|
124
|
+
- [voice.on()](./voice.on) - Registers an event listener for voice events
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: voice.listen() | Voice Providers | Mastra Docs"
|
|
3
|
+
description: "Documentation for the listen() method available in all Mastra voice providers, which converts speech to text."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# voice.listen()
|
|
7
|
+
|
|
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
|
+
|
|
10
|
+
## Usage Example
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { OpenAIVoice } from "@mastra/voice-openai";
|
|
14
|
+
import { createReadStream } from "fs";
|
|
15
|
+
import path from "path";
|
|
16
|
+
|
|
17
|
+
// Initialize a voice provider
|
|
18
|
+
const voice = new OpenAIVoice({
|
|
19
|
+
listeningModel: {
|
|
20
|
+
name: "whisper-1",
|
|
21
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Basic usage with a file stream
|
|
26
|
+
const audioFilePath = path.join(process.cwd(), "audio.mp3");
|
|
27
|
+
const audioStream = createReadStream(audioFilePath);
|
|
28
|
+
const transcript = await voice.listen(audioStream, {
|
|
29
|
+
filetype: "mp3",
|
|
30
|
+
});
|
|
31
|
+
console.log("Transcribed text:", transcript);
|
|
32
|
+
|
|
33
|
+
// Using a microphone stream
|
|
34
|
+
const microphoneStream = getMicrophoneStream(); // Assume this function gets audio input
|
|
35
|
+
const transcription = await voice.listen(microphoneStream);
|
|
36
|
+
|
|
37
|
+
// With provider-specific options
|
|
38
|
+
const transcriptWithOptions = await voice.listen(audioStream, {
|
|
39
|
+
language: "en",
|
|
40
|
+
prompt: "This is a conversation about artificial intelligence.",
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Parameters
|
|
45
|
+
|
|
46
|
+
<PropertiesTable
|
|
47
|
+
content={[
|
|
48
|
+
{
|
|
49
|
+
name: "audioStream",
|
|
50
|
+
type: "NodeJS.ReadableStream",
|
|
51
|
+
description: "Audio stream to transcribe. This can be a file stream or a microphone stream.",
|
|
52
|
+
isOptional: false,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "options",
|
|
56
|
+
type: "object",
|
|
57
|
+
description: "Provider-specific options for speech recognition",
|
|
58
|
+
isOptional: true,
|
|
59
|
+
}
|
|
60
|
+
]}
|
|
61
|
+
/>
|
|
62
|
+
|
|
63
|
+
## Return Value
|
|
64
|
+
|
|
65
|
+
Returns one of the following:
|
|
66
|
+
- `Promise<string>`: A promise that resolves to the transcribed text
|
|
67
|
+
- `Promise<NodeJS.ReadableStream>`: A promise that resolves to a stream of transcribed text (for streaming transcription)
|
|
68
|
+
- `Promise<void>`: For real-time providers that emit 'writing' events instead of returning text directly
|
|
69
|
+
|
|
70
|
+
## Provider-Specific Options
|
|
71
|
+
|
|
72
|
+
Each voice provider may support additional options specific to their implementation. Here are some examples:
|
|
73
|
+
|
|
74
|
+
### OpenAI
|
|
75
|
+
|
|
76
|
+
<PropertiesTable
|
|
77
|
+
content={[
|
|
78
|
+
{
|
|
79
|
+
name: "options.filetype",
|
|
80
|
+
type: "string",
|
|
81
|
+
description: "Audio file format (e.g., 'mp3', 'wav', 'm4a')",
|
|
82
|
+
isOptional: true,
|
|
83
|
+
defaultValue: "'mp3'",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "options.prompt",
|
|
87
|
+
type: "string",
|
|
88
|
+
description: "Text to guide the model's transcription",
|
|
89
|
+
isOptional: true,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "options.language",
|
|
93
|
+
type: "string",
|
|
94
|
+
description: "Language code (e.g., 'en', 'fr', 'de')",
|
|
95
|
+
isOptional: true,
|
|
96
|
+
}
|
|
97
|
+
]}
|
|
98
|
+
/>
|
|
99
|
+
|
|
100
|
+
### Google
|
|
101
|
+
|
|
102
|
+
<PropertiesTable
|
|
103
|
+
content={[
|
|
104
|
+
{
|
|
105
|
+
name: "options.stream",
|
|
106
|
+
type: "boolean",
|
|
107
|
+
description: "Whether to use streaming recognition",
|
|
108
|
+
isOptional: true,
|
|
109
|
+
defaultValue: "false",
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "options.config",
|
|
113
|
+
type: "object",
|
|
114
|
+
description: "Recognition configuration from Google Cloud Speech-to-Text API",
|
|
115
|
+
isOptional: true,
|
|
116
|
+
defaultValue: "{ encoding: 'LINEAR16', languageCode: 'en-US' }",
|
|
117
|
+
}
|
|
118
|
+
]}
|
|
119
|
+
/>
|
|
120
|
+
|
|
121
|
+
### Deepgram
|
|
122
|
+
|
|
123
|
+
<PropertiesTable
|
|
124
|
+
content={[
|
|
125
|
+
{
|
|
126
|
+
name: "options.model",
|
|
127
|
+
type: "string",
|
|
128
|
+
description: "Deepgram model to use for transcription",
|
|
129
|
+
isOptional: true,
|
|
130
|
+
defaultValue: "'nova-2'",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: "options.language",
|
|
134
|
+
type: "string",
|
|
135
|
+
description: "Language code for transcription",
|
|
136
|
+
isOptional: true,
|
|
137
|
+
defaultValue: "'en'",
|
|
138
|
+
}
|
|
139
|
+
]}
|
|
140
|
+
/>
|
|
141
|
+
|
|
142
|
+
## Realtime Voice Providers
|
|
143
|
+
|
|
144
|
+
When using realtime voice providers like `OpenAIRealtimeVoice`, the `listen()` method behaves differently:
|
|
145
|
+
|
|
146
|
+
- Instead of returning transcribed text, it emits 'writing' events with the transcribed text
|
|
147
|
+
- You need to register an event listener to receive the transcription
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { OpenAIRealtimeVoice } from "@mastra/voice-openai-realtime";
|
|
151
|
+
const voice = new OpenAIRealtimeVoice();
|
|
152
|
+
await voice.connect();
|
|
153
|
+
|
|
154
|
+
// Register event listener for transcription
|
|
155
|
+
voice.on("writing", ({ text, role }) => {
|
|
156
|
+
console.log(`${role}: ${text}`);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// This will emit 'writing' events instead of returning text
|
|
160
|
+
const microphoneStream = getMicrophoneStream();
|
|
161
|
+
await voice.listen(microphoneStream);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Using with CompositeVoice
|
|
165
|
+
|
|
166
|
+
When using `CompositeVoice`, the `listen()` method delegates to the configured listening provider:
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { CompositeVoice } from "@mastra/core/voice";
|
|
170
|
+
import { OpenAIVoice } from "@mastra/voice-openai";
|
|
171
|
+
import { PlayAIVoice } from "@mastra/voice-playai";
|
|
172
|
+
|
|
173
|
+
const voice = new CompositeVoice({
|
|
174
|
+
listenProvider: new OpenAIVoice(),
|
|
175
|
+
speakProvider: new PlayAIVoice(),
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// This will use the OpenAIVoice provider
|
|
179
|
+
const transcript = await voice.listen(audioStream);
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Notes
|
|
183
|
+
|
|
184
|
+
- Not all voice providers support speech-to-text functionality (e.g., PlayAI, Speechify)
|
|
185
|
+
- The behavior of `listen()` may vary slightly between providers, but all implementations follow the same basic interface
|
|
186
|
+
- When using a realtime voice provider, the method might not return text directly but instead emit a 'writing' event
|
|
187
|
+
- The audio format supported depends on the provider. Common formats include MP3, WAV, and M4A
|
|
188
|
+
- Some providers support streaming transcription, where text is returned as it's transcribed
|
|
189
|
+
- For best performance, consider closing or ending the audio stream when you're done with it
|
|
190
|
+
|
|
191
|
+
## Related Methods
|
|
192
|
+
|
|
193
|
+
- [voice.speak()](./voice.speak) - Converts text to speech
|
|
194
|
+
- [voice.send()](./voice.send) - Sends audio data to the voice provider in real-time
|
|
195
|
+
- [voice.on()](./voice.on) - Registers an event listener for voice events
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: voice.on() | Voice Providers | Mastra Docs"
|
|
3
|
+
description: "Documentation for the on() method available in voice providers, which registers event listeners for voice events."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# voice.on()
|
|
7
|
+
|
|
8
|
+
The `on()` method registers event listeners for various voice events. This is particularly important for real-time voice providers, where events are used to communicate transcribed text, audio responses, and other state changes.
|
|
9
|
+
|
|
10
|
+
## Usage Example
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { OpenAIRealtimeVoice } from "@mastra/voice-openai-realtime";
|
|
14
|
+
import Speaker from "@mastra/node-speaker";
|
|
15
|
+
import chalk from "chalk";
|
|
16
|
+
|
|
17
|
+
const speaker = new Speaker({
|
|
18
|
+
sampleRate: 24100, // Audio sample rate in Hz - standard for high-quality audio on MacBook Pro
|
|
19
|
+
channels: 1, // Mono audio output (as opposed to stereo which would be 2)
|
|
20
|
+
bitDepth: 16, // Bit depth for audio quality - CD quality standard (16-bit resolution)
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Initialize a real-time voice provider
|
|
24
|
+
const voice = new OpenAIRealtimeVoice({
|
|
25
|
+
realtimeConfig: {
|
|
26
|
+
model: "gpt-4o-mini-realtime",
|
|
27
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Connect to the real-time service
|
|
32
|
+
await voice.connect();
|
|
33
|
+
|
|
34
|
+
// Register event listener for transcribed text
|
|
35
|
+
voice.on("writing", ({ text, role }) => {
|
|
36
|
+
if (ev.role === 'user') {
|
|
37
|
+
process.stdout.write(chalk.green(ev.text));
|
|
38
|
+
} else {
|
|
39
|
+
process.stdout.write(chalk.blue(ev.text));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Register event listener for speaker responses
|
|
44
|
+
voice.on("speaking", (stream) => {
|
|
45
|
+
// Stream the audio to node speaker
|
|
46
|
+
stream.pipe(speaker)
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Register event listener for errors
|
|
50
|
+
voice.on("error", ({ message, code, details }) => {
|
|
51
|
+
console.error(`Error ${code}: ${message}`, details);
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Parameters
|
|
56
|
+
|
|
57
|
+
<PropertiesTable
|
|
58
|
+
content={[
|
|
59
|
+
{
|
|
60
|
+
name: "event",
|
|
61
|
+
type: "string",
|
|
62
|
+
description: "Name of the event to listen for (e.g., 'speaking', 'writing', 'error')",
|
|
63
|
+
isOptional: false,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "callback",
|
|
67
|
+
type: "function",
|
|
68
|
+
description: "Callback function that will be called when the event occurs",
|
|
69
|
+
isOptional: false,
|
|
70
|
+
}
|
|
71
|
+
]}
|
|
72
|
+
/>
|
|
73
|
+
|
|
74
|
+
## Return Value
|
|
75
|
+
|
|
76
|
+
This method does not return a value.
|
|
77
|
+
|
|
78
|
+
## Standard Events
|
|
79
|
+
|
|
80
|
+
All voice providers that implement event handling support these standard events:
|
|
81
|
+
|
|
82
|
+
<PropertiesTable
|
|
83
|
+
content={[
|
|
84
|
+
{
|
|
85
|
+
name: "speaking",
|
|
86
|
+
type: "event",
|
|
87
|
+
description: "Emitted when audio data is available. The callback receives { audio } where audio is typically an Int16Array or Buffer.",
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "speaker",
|
|
91
|
+
type: "event",
|
|
92
|
+
description: "Emitted when a new audio response is ready to be streamed. The callback receives a buffer that can be piped into node-speaker."
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "writing",
|
|
96
|
+
type: "event",
|
|
97
|
+
description: "Emitted when text is transcribed or generated. The callback receives { text, role } where role is either 'user' or 'assistant'.",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "error",
|
|
101
|
+
type: "event",
|
|
102
|
+
description: "Emitted when an error occurs. The callback receives { message, code, details } with information about the error.",
|
|
103
|
+
}
|
|
104
|
+
]}
|
|
105
|
+
/>
|
|
106
|
+
|
|
107
|
+
## Provider-Specific Events
|
|
108
|
+
|
|
109
|
+
Different voice providers may emit additional events specific to their implementation:
|
|
110
|
+
|
|
111
|
+
### OpenAI Realtime
|
|
112
|
+
|
|
113
|
+
OpenAI Realtime events are prefixed with `openAIRealtime:` and include:
|
|
114
|
+
|
|
115
|
+
<PropertiesTable
|
|
116
|
+
content={[
|
|
117
|
+
{
|
|
118
|
+
name: "openAIRealtime:conversation.created",
|
|
119
|
+
type: "event",
|
|
120
|
+
description: "Emitted when a new conversation is created.",
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: "openAIRealtime:conversation.interrupted",
|
|
124
|
+
type: "event",
|
|
125
|
+
description: "Emitted when a conversation is interrupted.",
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: "openAIRealtime:conversation.updated",
|
|
129
|
+
type: "event",
|
|
130
|
+
description: "Emitted when a conversation is updated.",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: "openAIRealtime:conversation.item.appended",
|
|
134
|
+
type: "event",
|
|
135
|
+
description: "Emitted when an item is appended to the conversation.",
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "openAIRealtime:conversation.item.completed",
|
|
139
|
+
type: "event",
|
|
140
|
+
description: "Emitted when an item in the conversation is completed.",
|
|
141
|
+
}
|
|
142
|
+
]}
|
|
143
|
+
/>
|
|
144
|
+
|
|
145
|
+
## Using with CompositeVoice
|
|
146
|
+
|
|
147
|
+
When using `CompositeVoice`, the `on()` method delegates to the configured real-time provider:
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { CompositeVoice } from "@mastra/core/voice";
|
|
151
|
+
import { OpenAIRealtimeVoice } from "@mastra/voice-openai-realtime";
|
|
152
|
+
import Speaker from "@mastra/node-speaker";
|
|
153
|
+
|
|
154
|
+
const speaker = new Speaker({
|
|
155
|
+
sampleRate: 24100, // Audio sample rate in Hz - standard for high-quality audio on MacBook Pro
|
|
156
|
+
channels: 1, // Mono audio output (as opposed to stereo which would be 2)
|
|
157
|
+
bitDepth: 16, // Bit depth for audio quality - CD quality standard (16-bit resolution)
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const realtimeVoice = new OpenAIRealtimeVoice();
|
|
161
|
+
const voice = new CompositeVoice({
|
|
162
|
+
realtimeProvider: realtimeVoice,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Connect to the real-time service
|
|
166
|
+
await voice.connect();
|
|
167
|
+
|
|
168
|
+
// This will register the event listener with the OpenAIRealtimeVoice provider
|
|
169
|
+
voice.on("speaker", (stream) => {
|
|
170
|
+
stream.pipe(speaker)
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Notes
|
|
175
|
+
|
|
176
|
+
- This method is primarily used with real-time voice providers that support event-based communication
|
|
177
|
+
- If called on a voice provider that doesn't support events, it will log a warning and do nothing
|
|
178
|
+
- Event listeners should be registered before calling methods that might emit events
|
|
179
|
+
- To remove an event listener, use the `off()` method with the same event name and callback function
|
|
180
|
+
- Multiple listeners can be registered for the same event
|
|
181
|
+
- The callback function will receive different data depending on the event type
|
|
182
|
+
- For best performance, consider removing event listeners when they are no longer needed
|
|
183
|
+
|
|
184
|
+
## Related Methods
|
|
185
|
+
|
|
186
|
+
- [voice.off()](./voice.off) - Removes an event listener
|
|
187
|
+
- [voice.connect()](./voice.connect) - Establishes a connection to the real-time service
|
|
188
|
+
- [voice.send()](./voice.send) - Sends audio data to the voice provider
|
|
189
|
+
- [voice.answer()](./voice.answer) - Triggers the voice provider to respond
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: voice.send() | Voice Providers | Mastra Docs"
|
|
3
|
+
description: "Documentation for the send() method available in real-time voice providers, which streams audio data for continuous processing."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# voice.send()
|
|
7
|
+
|
|
8
|
+
The `send()` method streams audio data in real-time to voice providers for continuous processing. This method is essential for real-time speech-to-speech conversations, allowing you to send microphone input directly to the AI service.
|
|
9
|
+
|
|
10
|
+
## Usage Example
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { OpenAIRealtimeVoice } from "@mastra/voice-openai-realtime";
|
|
14
|
+
import Speaker from "@mastra/node-speaker";
|
|
15
|
+
|
|
16
|
+
const speaker = new Speaker({
|
|
17
|
+
sampleRate: 24100, // Audio sample rate in Hz - standard for high-quality audio on MacBook Pro
|
|
18
|
+
channels: 1, // Mono audio output (as opposed to stereo which would be 2)
|
|
19
|
+
bitDepth: 16, // Bit depth for audio quality - CD quality standard (16-bit resolution)
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
// Initialize a real-time voice provider
|
|
24
|
+
const voice = new OpenAIRealtimeVoice({
|
|
25
|
+
realtimeConfig: {
|
|
26
|
+
model: "gpt-4o-mini-realtime",
|
|
27
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Connect to the real-time service
|
|
32
|
+
await voice.connect();
|
|
33
|
+
|
|
34
|
+
// Set up event listeners for responses
|
|
35
|
+
voice.on("writing", ({ text, role }) => {
|
|
36
|
+
console.log(`${role}: ${text}`);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
voice.on("speaker", (stream) => {
|
|
40
|
+
stream.pipe(speaker)
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Get microphone stream (implementation depends on your environment)
|
|
44
|
+
const microphoneStream = getMicrophoneStream();
|
|
45
|
+
|
|
46
|
+
// Send audio data to the voice provider
|
|
47
|
+
await voice.send(microphoneStream);
|
|
48
|
+
|
|
49
|
+
// You can also send audio data as Int16Array
|
|
50
|
+
const audioBuffer = getAudioBuffer(); // Assume this returns Int16Array
|
|
51
|
+
await voice.send(audioBuffer);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Parameters
|
|
55
|
+
|
|
56
|
+
<PropertiesTable
|
|
57
|
+
content={[
|
|
58
|
+
{
|
|
59
|
+
name: "audioData",
|
|
60
|
+
type: "NodeJS.ReadableStream | Int16Array",
|
|
61
|
+
description: "Audio data to send to the voice provider. Can be a readable stream (like a microphone stream) or an Int16Array of audio samples.",
|
|
62
|
+
isOptional: false,
|
|
63
|
+
}
|
|
64
|
+
]}
|
|
65
|
+
/>
|
|
66
|
+
|
|
67
|
+
## Return Value
|
|
68
|
+
|
|
69
|
+
Returns a `Promise<void>` that resolves when the audio data has been accepted by the voice provider.
|
|
70
|
+
|
|
71
|
+
## Provider-Specific Behavior
|
|
72
|
+
|
|
73
|
+
Different real-time voice providers may handle the audio data in different ways:
|
|
74
|
+
|
|
75
|
+
### OpenAI Realtime
|
|
76
|
+
|
|
77
|
+
- Accepts both NodeJS.ReadableStream and Int16Array formats
|
|
78
|
+
- Audio should be in PCM format, 16-bit, mono, 16kHz sample rate
|
|
79
|
+
- Automatically handles voice activity detection (VAD) to determine when the user has finished speaking
|
|
80
|
+
- Emits 'writing' events with transcribed text as it processes the audio
|
|
81
|
+
|
|
82
|
+
## Using with CompositeVoice
|
|
83
|
+
|
|
84
|
+
When using `CompositeVoice`, the `send()` method delegates to the configured real-time provider:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { CompositeVoice } from "@mastra/core/voice";
|
|
88
|
+
import { OpenAIRealtimeVoice } from "@mastra/voice-openai-realtime";
|
|
89
|
+
|
|
90
|
+
const realtimeVoice = new OpenAIRealtimeVoice();
|
|
91
|
+
const voice = new CompositeVoice({
|
|
92
|
+
realtimeProvider: realtimeVoice,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Connect to the real-time service
|
|
96
|
+
await voice.connect();
|
|
97
|
+
|
|
98
|
+
// This will use the OpenAIRealtimeVoice provider
|
|
99
|
+
const microphoneStream = getMicrophoneStream();
|
|
100
|
+
await voice.send(microphoneStream);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Notes
|
|
104
|
+
|
|
105
|
+
- This method is only implemented by real-time voice providers that support speech-to-speech capabilities
|
|
106
|
+
- If called on a voice provider that doesn't support this functionality, it will log a warning and resolve immediately
|
|
107
|
+
- You must call `connect()` before using `send()` to establish the WebSocket connection
|
|
108
|
+
- The audio format requirements depend on the specific voice provider
|
|
109
|
+
- For continuous conversation, you typically call `send()` to transmit user audio, then `answer()` to trigger the AI response
|
|
110
|
+
- The provider will typically emit 'writing' events with transcribed text as it processes the audio
|
|
111
|
+
- When the AI responds, the provider will emit 'speaking' events with the audio response
|
|
112
|
+
|
|
113
|
+
## Related Methods
|
|
114
|
+
|
|
115
|
+
- [voice.connect()](./voice.connect) - Establishes a connection to the real-time service
|
|
116
|
+
- [voice.answer()](./voice.answer) - Triggers the voice provider to respond
|
|
117
|
+
- [voice.listen()](./voice.listen) - Converts speech to text (non-streaming)
|
|
118
|
+
- [voice.on()](./voice.on) - Registers an event listener for voice events
|