@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,310 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Voice-to-Voice Capabilities in Mastra | Mastra Docs
|
|
3
|
+
description: Overview of voice-to-voice capabilities in Mastra, including real-time interactions and event-driven architecture.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Voice-to-Voice Capabilities in Mastra
|
|
7
|
+
|
|
8
|
+
## Introduction
|
|
9
|
+
|
|
10
|
+
Voice-to-Voice in Mastra provides a standardized interface for real-time speech-to-speech interactions across multiple service providers. This section covers configuration, event-driven architecture, and implementation methods for creating conversational voice experiences. For integrating Voice-to-Voice capabilities with agents, refer to the [Adding Voice to Agents](../agents/adding-voice.mdx) documentation.
|
|
11
|
+
|
|
12
|
+
## Real-time Voice Interactions
|
|
13
|
+
|
|
14
|
+
Mastra's real-time voice system enables continuous bidirectional audio communication through an event-driven architecture. Unlike separate TTS and STT operations, real-time voice maintains an open connection that processes speech continuously in both directions.
|
|
15
|
+
|
|
16
|
+
### Example Implementation
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import { Agent } from "@mastra/core/agent";
|
|
20
|
+
import { OpenAIRealtimeVoice } from "@mastra/voice-openai-realtime";
|
|
21
|
+
|
|
22
|
+
const agent = new Agent({
|
|
23
|
+
name: 'Agent',
|
|
24
|
+
instructions: `You are a helpful assistant with real-time voice capabilities.`,
|
|
25
|
+
model: openai('gpt-4o'),
|
|
26
|
+
voice: new OpenAIRealtimeVoice(),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Connect to the voice service
|
|
30
|
+
await agent.voice.connect();
|
|
31
|
+
|
|
32
|
+
// Listen for agent audio responses
|
|
33
|
+
agent.voice.on('speaking', ({ audio }) => {
|
|
34
|
+
playAudio(audio);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Initiate the conversation
|
|
38
|
+
await agent.voice.speak('How can I help you today?');
|
|
39
|
+
|
|
40
|
+
// Send continuous audio from the microphone
|
|
41
|
+
const micStream = getMicrophoneStream();
|
|
42
|
+
await agent.voice.send(micStream);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Event-Driven Architecture
|
|
46
|
+
|
|
47
|
+
Mastra's voice-to-voice implementation is built on an event-driven architecture. Developers register event listeners to handle incoming audio progressively, allowing for more responsive interactions than waiting for complete audio responses.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## Configuration
|
|
51
|
+
|
|
52
|
+
When initializing a voice-to-voice provider, you can provide configuration options to customize its behavior:
|
|
53
|
+
|
|
54
|
+
### Constructor Options
|
|
55
|
+
|
|
56
|
+
- **`chatModel`**: Configuration for the OpenAI realtime model.
|
|
57
|
+
- **`apiKey`**: Your OpenAI API key. Falls back to the `OPENAI_API_KEY` environment variable.
|
|
58
|
+
- **`model`**: The model ID to use for real-time voice interactions (e.g., `gpt-4o-mini-realtime`).
|
|
59
|
+
- **`options`**: Additional options for the realtime client, such as session configuration.
|
|
60
|
+
|
|
61
|
+
- **`speaker`**: The default voice ID for speech synthesis. This allows you to specify which voice to use for the speech output.
|
|
62
|
+
|
|
63
|
+
### Example Configuration
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
const voice = new OpenAIRealtimeVoice({
|
|
67
|
+
chatModel: {
|
|
68
|
+
apiKey: 'your-openai-api-key',
|
|
69
|
+
model: 'gpt-4o-mini-realtime',
|
|
70
|
+
options: {
|
|
71
|
+
sessionConfig: {
|
|
72
|
+
turn_detection: {
|
|
73
|
+
type: 'server_vad',
|
|
74
|
+
threshold: 0.6,
|
|
75
|
+
silence_duration_ms: 1200,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
speaker: 'alloy', // Default voice
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// If using default settings the configuration can be simplified to:
|
|
84
|
+
const voice = new OpenAIRealtimeVoice();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Core Methods
|
|
88
|
+
|
|
89
|
+
The `OpenAIRealtimeVoice` class provides the following core methods for voice interactions:
|
|
90
|
+
|
|
91
|
+
### connect()
|
|
92
|
+
|
|
93
|
+
Establishes a connection to the OpenAI realtime service.
|
|
94
|
+
|
|
95
|
+
**Usage:**
|
|
96
|
+
```typescript
|
|
97
|
+
await voice.connect();
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Notes:**
|
|
101
|
+
- Must be called before using any other interaction methods
|
|
102
|
+
- Returns a Promise that resolves when the connection is established
|
|
103
|
+
|
|
104
|
+
### speak(text, options?)
|
|
105
|
+
|
|
106
|
+
Emits a speaking event using the configured voice model.
|
|
107
|
+
|
|
108
|
+
**Parameters:**
|
|
109
|
+
- `text`: String content to be spoken
|
|
110
|
+
- `options`: Optional configuration object
|
|
111
|
+
- `speaker`: Voice ID to use (overrides default)
|
|
112
|
+
- `properties`: Additional provider-specific properties
|
|
113
|
+
|
|
114
|
+
**Usage:**
|
|
115
|
+
```typescript
|
|
116
|
+
voice.speak('Hello, how can I help you today?', {
|
|
117
|
+
speaker: 'alloy'
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Notes:**
|
|
122
|
+
- Emits 'speaker' event rather than returning an audio stream
|
|
123
|
+
|
|
124
|
+
### listen(audioInput, options?)
|
|
125
|
+
|
|
126
|
+
Processes audio input for speech recognition.
|
|
127
|
+
|
|
128
|
+
**Parameters:**
|
|
129
|
+
- `audioInput`: Readable stream of audio data
|
|
130
|
+
- `options`: Optional configuration object
|
|
131
|
+
- `filetype`: Audio format (default: 'mp3')
|
|
132
|
+
- Additional provider-specific options
|
|
133
|
+
|
|
134
|
+
**Usage:**
|
|
135
|
+
```typescript
|
|
136
|
+
const audioData = getMicrophoneStream();
|
|
137
|
+
voice.listen(audioData, {
|
|
138
|
+
filetype: 'wav'
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Notes:**
|
|
143
|
+
- Emits 'writing' events with transcribed text
|
|
144
|
+
|
|
145
|
+
### send(audioStream)
|
|
146
|
+
|
|
147
|
+
Streams audio data in real-time for continuous processing.
|
|
148
|
+
|
|
149
|
+
**Parameters:**
|
|
150
|
+
- `audioStream`: Readable stream of audio data
|
|
151
|
+
|
|
152
|
+
**Usage:**
|
|
153
|
+
```typescript
|
|
154
|
+
const micStream = getMicrophoneStream();
|
|
155
|
+
await voice.send(micStream);
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Notes:**
|
|
159
|
+
- Used for continuous audio streaming scenarios like live microphone input
|
|
160
|
+
- Returns a Promise that resolves when the stream is accepted
|
|
161
|
+
|
|
162
|
+
### answer(params)
|
|
163
|
+
|
|
164
|
+
Sends a response to the OpenAI Realtime API.
|
|
165
|
+
|
|
166
|
+
**Parameters:**
|
|
167
|
+
- `params`: The parameters object
|
|
168
|
+
- `options`: Configuration options for the response
|
|
169
|
+
- `content`: Text content of the response
|
|
170
|
+
- `voice`: Voice ID to use for the response
|
|
171
|
+
|
|
172
|
+
**Usage:**
|
|
173
|
+
```typescript
|
|
174
|
+
await voice.answer({
|
|
175
|
+
options: {
|
|
176
|
+
content: "Hello, how can I help you today?",
|
|
177
|
+
voice: "alloy"
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Notes:**
|
|
183
|
+
- Triggers a response to the real-time session
|
|
184
|
+
- Returns a Promise that resolves when the response has been sent
|
|
185
|
+
|
|
186
|
+
## Utility Methods
|
|
187
|
+
|
|
188
|
+
### updateConfig(config)
|
|
189
|
+
|
|
190
|
+
Updates the session configuration for the voice instance.
|
|
191
|
+
|
|
192
|
+
**Parameters:**
|
|
193
|
+
- `config`: New session configuration object
|
|
194
|
+
|
|
195
|
+
**Usage:**
|
|
196
|
+
```typescript
|
|
197
|
+
voice.updateConfig({
|
|
198
|
+
turn_detection: {
|
|
199
|
+
type: 'server_vad',
|
|
200
|
+
threshold: 0.6,
|
|
201
|
+
silence_duration_ms: 1200,
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### addTools(tools)
|
|
207
|
+
|
|
208
|
+
Adds a set of tools to the voice instance.
|
|
209
|
+
|
|
210
|
+
**Parameters:**
|
|
211
|
+
- `tools`: Array of tool objects that the model can call
|
|
212
|
+
|
|
213
|
+
**Usage:**
|
|
214
|
+
```typescript
|
|
215
|
+
voice.addTools([
|
|
216
|
+
createTool({
|
|
217
|
+
id: "Get Weather Information",
|
|
218
|
+
inputSchema: z.object({
|
|
219
|
+
city: z.string(),
|
|
220
|
+
}),
|
|
221
|
+
description: `Fetches the current weather information for a given city`,
|
|
222
|
+
execute: async ({ city }) => {...},
|
|
223
|
+
})
|
|
224
|
+
]);
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### close()
|
|
228
|
+
|
|
229
|
+
Disconnects from the OpenAI realtime session and cleans up resources.
|
|
230
|
+
|
|
231
|
+
**Usage:**
|
|
232
|
+
```typescript
|
|
233
|
+
voice.close();
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**Notes:**
|
|
237
|
+
- Should be called when you're done with the voice instance to free resources
|
|
238
|
+
|
|
239
|
+
### on(event, callback)
|
|
240
|
+
|
|
241
|
+
Registers an event listener for voice events.
|
|
242
|
+
|
|
243
|
+
**Parameters:**
|
|
244
|
+
- `event`: Event name ('speaker', 'writing', or 'error')
|
|
245
|
+
- `callback`: Function to call when the event occurs
|
|
246
|
+
|
|
247
|
+
**Usage:**
|
|
248
|
+
```typescript
|
|
249
|
+
voice.on('speaker', (stream) => {
|
|
250
|
+
stream.pipe(speaker)
|
|
251
|
+
});
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### off(event, callback)
|
|
255
|
+
|
|
256
|
+
Removes a previously registered event listener.
|
|
257
|
+
|
|
258
|
+
**Parameters:**
|
|
259
|
+
- `event`: Event name
|
|
260
|
+
- `callback`: The callback function to remove
|
|
261
|
+
|
|
262
|
+
**Usage:**
|
|
263
|
+
```typescript
|
|
264
|
+
voice.off('speaking', callbackFunction);
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## Events
|
|
268
|
+
|
|
269
|
+
The `OpenAIRealtimeVoice` class emits the following events:
|
|
270
|
+
|
|
271
|
+
### speaker
|
|
272
|
+
|
|
273
|
+
Emitted when audio data is received from the model.
|
|
274
|
+
|
|
275
|
+
**Event payload:**
|
|
276
|
+
- `stream`: A stream of audio data as a readable stream
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
agent.voice.on('speaker', (stream) => {
|
|
280
|
+
stream.pipe(speaker)
|
|
281
|
+
});
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### writing
|
|
285
|
+
|
|
286
|
+
Emitted when transcribed text is available.
|
|
287
|
+
|
|
288
|
+
**Event payload:**
|
|
289
|
+
- `text`: The transcribed text
|
|
290
|
+
- `role`: The role of the speaker (user or assistant)
|
|
291
|
+
- `done`: Boolean indicating if this is the final transcription
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
agent.voice.on('writing', ({ text, role }) => {
|
|
295
|
+
console.log(`${role}: ${text}`); // Log who said what
|
|
296
|
+
});
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### error
|
|
300
|
+
|
|
301
|
+
Emitted when an error occurs.
|
|
302
|
+
|
|
303
|
+
**Event payload:**
|
|
304
|
+
- Error object with details about what went wrong
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
agent.voice.on('error', (error) => {
|
|
308
|
+
console.error('Voice error:', error);
|
|
309
|
+
});
|
|
310
|
+
```
|