@mastra/voice-openai-realtime 0.13.9 → 0.13.10
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/README.md
CHANGED
|
@@ -61,30 +61,10 @@ await voice.send(microphoneStream);
|
|
|
61
61
|
voice.close();
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
## Connection failures
|
|
65
|
-
|
|
66
|
-
`connect()` waits for both the WebSocket to open and the server to create a session. It rejects if the connection fails, the server reports an error during the handshake, or the socket closes before the session is ready. A silent handshake times out after 15,000 milliseconds by default.
|
|
67
|
-
|
|
68
|
-
Use `connectTimeoutMs` to configure the handshake deadline. The value must be a positive, finite number no greater than 2,147,483,647 milliseconds. Catch connection failures directly; an `error` event listener does not replace handling the rejected promise.
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
const voice = new OpenAIRealtimeVoice({
|
|
72
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
73
|
-
connectTimeoutMs: 30_000,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
await voice.connect();
|
|
78
|
-
} catch (error) {
|
|
79
|
-
console.error('Could not connect to the realtime service:', error);
|
|
80
|
-
}
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
A failed handshake closes its socket and clears its pending waits. You can retry with `connect()` on the same instance. The deadline only applies to connection setup, not to an established session.
|
|
84
|
-
|
|
85
64
|
## Documentation
|
|
86
65
|
|
|
87
66
|
- [@mastra/voice-openai-realtime documentation](https://mastra.ai/integrations/voice/openai)
|
|
67
|
+
- [Reference documentation](https://mastra.ai/reference/voice/voice.connect)
|
|
88
68
|
|
|
89
69
|
## Changelog
|
|
90
70
|
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-voice-openai-realtime
|
|
|
3
3
|
description: Documentation for @mastra/voice-openai-realtime. Use when working with @mastra/voice-openai-realtime APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/voice-openai-realtime"
|
|
6
|
-
version: "0.13.
|
|
6
|
+
version: "0.13.10"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -13,27 +13,14 @@ import { OpenAIRealtimeVoice } from '@mastra/voice-openai-realtime'
|
|
|
13
13
|
import Speaker from '@mastra/node-speaker'
|
|
14
14
|
|
|
15
15
|
const speaker = new Speaker({
|
|
16
|
-
sampleRate:
|
|
17
|
-
channels: 1,
|
|
18
|
-
bitDepth: 16,
|
|
16
|
+
sampleRate: 24000,
|
|
17
|
+
channels: 1,
|
|
18
|
+
bitDepth: 16,
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
-
// Initialize a real-time voice provider
|
|
22
21
|
const voice = new OpenAIRealtimeVoice({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
26
|
-
options: {
|
|
27
|
-
sessionConfig: {
|
|
28
|
-
turn_detection: {
|
|
29
|
-
type: 'server_vad',
|
|
30
|
-
threshold: 0.6,
|
|
31
|
-
silence_duration_ms: 1200,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
speaker: 'alloy', // Default voice
|
|
22
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
23
|
+
speaker: 'alloy',
|
|
37
24
|
})
|
|
38
25
|
// Connect to the real-time service
|
|
39
26
|
await voice.connect()
|
|
@@ -41,11 +28,6 @@ await voice.connect()
|
|
|
41
28
|
voice.on('speaker', stream => {
|
|
42
29
|
stream.pipe(speaker)
|
|
43
30
|
})
|
|
44
|
-
// With connection options
|
|
45
|
-
await voice.connect({
|
|
46
|
-
timeout: 10000, // 10 seconds timeout
|
|
47
|
-
reconnect: true,
|
|
48
|
-
})
|
|
49
31
|
```
|
|
50
32
|
|
|
51
33
|
## Parameters
|
|
@@ -58,19 +40,46 @@ Returns a `Promise<void>` that resolves when the connection is successfully esta
|
|
|
58
40
|
|
|
59
41
|
## Provider-specific options
|
|
60
42
|
|
|
61
|
-
|
|
43
|
+
Connection configuration depends on the real-time voice provider.
|
|
62
44
|
|
|
63
45
|
### OpenAI Realtime
|
|
64
46
|
|
|
65
|
-
|
|
47
|
+
`connect()` accepts an optional `requestContext` for tool execution:
|
|
48
|
+
|
|
49
|
+
**options.requestContext** (`RequestContext`): Runtime context passed to tools called during the session.
|
|
50
|
+
|
|
51
|
+
See [Request context](https://mastra.ai/docs/server/request-context) for how to populate runtime values.
|
|
52
|
+
|
|
53
|
+
Set `connectTimeoutMs` in the `OpenAIRealtimeVoice` constructor, not in the `connect()` call:
|
|
54
|
+
|
|
55
|
+
**connectTimeoutMs** (`number`): Connection handshake deadline in milliseconds. Must be a positive, finite number no greater than 2,147,483,647. Applies only to connection setup, not to an established session. (Default: `15000`)
|
|
56
|
+
|
|
57
|
+
## Connection failures
|
|
58
|
+
|
|
59
|
+
For OpenAI Realtime, `connect()` waits for both the WebSocket to open and the server to create a session. It rejects if the connection fails, the server reports an error during the handshake, or the socket closes before the session is ready. A silent handshake times out after 15,000 milliseconds by default.
|
|
60
|
+
|
|
61
|
+
Catch connection failures directly. An `error` event listener doesn't replace handling the rejected promise:
|
|
66
62
|
|
|
67
|
-
|
|
63
|
+
```typescript
|
|
64
|
+
import { OpenAIRealtimeVoice } from '@mastra/voice-openai-realtime'
|
|
65
|
+
|
|
66
|
+
const voice = new OpenAIRealtimeVoice({
|
|
67
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
68
|
+
connectTimeoutMs: 30_000,
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
await voice.connect()
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error('Could not connect to the realtime service:', error)
|
|
75
|
+
}
|
|
76
|
+
```
|
|
68
77
|
|
|
69
|
-
|
|
78
|
+
A failed handshake closes its socket and clears its pending waits. You can retry with `connect()` on the same instance.
|
|
70
79
|
|
|
71
80
|
## Using with `CompositeVoice`
|
|
72
81
|
|
|
73
|
-
When using `CompositeVoice`, the `connect()` method
|
|
82
|
+
When using `CompositeVoice`, the `connect()` method forwards its options to the configured real-time provider. It throws if no real-time provider is configured:
|
|
74
83
|
|
|
75
84
|
```typescript
|
|
76
85
|
import { CompositeVoice } from '@mastra/core/voice'
|
|
@@ -86,7 +95,7 @@ await voice.connect()
|
|
|
86
95
|
## Notes
|
|
87
96
|
|
|
88
97
|
- This method is only implemented by real-time voice providers that support speech-to-speech capabilities
|
|
89
|
-
-
|
|
98
|
+
- Providers that inherit the base `connect()` implementation log a debug message and resolve without establishing a connection
|
|
90
99
|
- The connection must be established before using other real-time methods like `send()` or `answer()`
|
|
91
100
|
- When you're done with the voice instance, call `close()` to properly clean up resources
|
|
92
101
|
- Some providers may automatically reconnect on connection loss, depending on their implementation
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/voice-openai-realtime",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.10",
|
|
4
4
|
"description": "Mastra OpenAI Realtime API integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"typescript": "^7.0.2",
|
|
39
39
|
"vitest": "4.1.10",
|
|
40
40
|
"zod": "^4.4.3",
|
|
41
|
-
"@internal/lint": "0.0.
|
|
42
|
-
"@internal/types-builder": "0.0.
|
|
43
|
-
"@internal/voice": "0.0.
|
|
41
|
+
"@internal/lint": "0.0.132",
|
|
42
|
+
"@internal/types-builder": "0.0.107",
|
|
43
|
+
"@internal/voice": "0.0.30"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"zod": "^3.25.0 || ^4.0.0"
|