@hazeljs/realtime 0.7.8 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -38
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -94,10 +94,12 @@ const ws = new WebSocket('ws://localhost:3000/realtime');
|
|
|
94
94
|
|
|
95
95
|
ws.onopen = () => {
|
|
96
96
|
// Optional: update session config
|
|
97
|
-
ws.send(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
ws.send(
|
|
98
|
+
JSON.stringify({
|
|
99
|
+
type: 'session.update',
|
|
100
|
+
session: { instructions: 'Be extra friendly!' },
|
|
101
|
+
})
|
|
102
|
+
);
|
|
101
103
|
};
|
|
102
104
|
|
|
103
105
|
ws.onmessage = (e) => {
|
|
@@ -110,10 +112,12 @@ ws.onmessage = (e) => {
|
|
|
110
112
|
};
|
|
111
113
|
|
|
112
114
|
// Send audio (base64 PCM 24kHz)
|
|
113
|
-
ws.send(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
ws.send(
|
|
116
|
+
JSON.stringify({
|
|
117
|
+
type: 'input_audio_buffer.append',
|
|
118
|
+
audio: base64PcmChunk,
|
|
119
|
+
})
|
|
120
|
+
);
|
|
117
121
|
```
|
|
118
122
|
|
|
119
123
|
---
|
|
@@ -122,22 +126,22 @@ ws.send(JSON.stringify({
|
|
|
122
126
|
|
|
123
127
|
### RealtimeModule.forRoot(options)
|
|
124
128
|
|
|
125
|
-
| Option
|
|
126
|
-
|
|
127
|
-
| `openaiApiKey`
|
|
128
|
-
| `path`
|
|
129
|
-
| `defaultSessionConfig` | RealtimeSessionConfig | Default session config
|
|
130
|
-
| `defaultProvider`
|
|
129
|
+
| Option | Type | Description |
|
|
130
|
+
| ---------------------- | --------------------- | -------------------------------------------- |
|
|
131
|
+
| `openaiApiKey` | string | OpenAI API key (or use `OPENAI_API_KEY` env) |
|
|
132
|
+
| `path` | string | WebSocket path (default: `/realtime`) |
|
|
133
|
+
| `defaultSessionConfig` | RealtimeSessionConfig | Default session config |
|
|
134
|
+
| `defaultProvider` | 'openai' \| 'gemini' | Provider (OpenAI supported first) |
|
|
131
135
|
|
|
132
136
|
### RealtimeSessionConfig
|
|
133
137
|
|
|
134
|
-
| Option
|
|
135
|
-
|
|
136
|
-
| `instructions`
|
|
137
|
-
| `voice`
|
|
138
|
-
| `outputModalities` | ('audio' \| 'text')[] | Output modes (default: ['audio', 'text'])
|
|
139
|
-
| `inputFormat`
|
|
140
|
-
| `turnDetection`
|
|
138
|
+
| Option | Type | Description |
|
|
139
|
+
| ------------------ | --------------------- | ------------------------------------------------------------------- |
|
|
140
|
+
| `instructions` | string | System prompt for the model |
|
|
141
|
+
| `voice` | OpenAIVoice | alloy, ash, ballad, coral, echo, sage, shimmer, verse, marin, cedar |
|
|
142
|
+
| `outputModalities` | ('audio' \| 'text')[] | Output modes (default: ['audio', 'text']) |
|
|
143
|
+
| `inputFormat` | RealtimeAudioFormat | PCM format (default: 24kHz) |
|
|
144
|
+
| `turnDetection` | boolean | Enable VAD (default: true) |
|
|
141
145
|
|
|
142
146
|
---
|
|
143
147
|
|
|
@@ -145,14 +149,14 @@ ws.send(JSON.stringify({
|
|
|
145
149
|
|
|
146
150
|
Send any [OpenAI Realtime client event](https://platform.openai.com/docs/api-reference/realtime-client-events) over the WebSocket:
|
|
147
151
|
|
|
148
|
-
| Event
|
|
149
|
-
|
|
150
|
-
| `session.update`
|
|
151
|
-
| `input_audio_buffer.append` | Send base64 PCM audio
|
|
152
|
+
| Event | Description |
|
|
153
|
+
| --------------------------- | --------------------------------- |
|
|
154
|
+
| `session.update` | Update session config |
|
|
155
|
+
| `input_audio_buffer.append` | Send base64 PCM audio |
|
|
152
156
|
| `input_audio_buffer.commit` | Commit buffer (when VAD disabled) |
|
|
153
|
-
| `input_audio_buffer.clear`
|
|
154
|
-
| `conversation.item.create`
|
|
155
|
-
| `response.create`
|
|
157
|
+
| `input_audio_buffer.clear` | Clear buffer |
|
|
158
|
+
| `conversation.item.create` | Add text message |
|
|
159
|
+
| `response.create` | Trigger model response |
|
|
156
160
|
|
|
157
161
|
---
|
|
158
162
|
|
|
@@ -160,14 +164,14 @@ Send any [OpenAI Realtime client event](https://platform.openai.com/docs/api-ref
|
|
|
160
164
|
|
|
161
165
|
You receive `{ event: 'realtime', data: <OpenAI server event> }`:
|
|
162
166
|
|
|
163
|
-
| Event
|
|
164
|
-
|
|
165
|
-
| `session.created` / `session.updated`
|
|
166
|
-
| `response.output_audio.delta`
|
|
167
|
-
| `response.output_audio.done`
|
|
168
|
-
| `response.output_text.delta` / `response.output_text.done` | Text stream
|
|
169
|
-
| `response.done`
|
|
170
|
-
| `input_audio_buffer.speech_started` / `speech_stopped`
|
|
167
|
+
| Event | Description |
|
|
168
|
+
| ---------------------------------------------------------- | -------------------- |
|
|
169
|
+
| `session.created` / `session.updated` | Session lifecycle |
|
|
170
|
+
| `response.output_audio.delta` | Audio chunk (base64) |
|
|
171
|
+
| `response.output_audio.done` | Audio complete |
|
|
172
|
+
| `response.output_text.delta` / `response.output_text.done` | Text stream |
|
|
173
|
+
| `response.done` | Response complete |
|
|
174
|
+
| `input_audio_buffer.speech_started` / `speech_stopped` | VAD events |
|
|
171
175
|
|
|
172
176
|
---
|
|
173
177
|
|
|
@@ -197,7 +201,10 @@ Encode/decode base64 for transport over WebSocket.
|
|
|
197
201
|
```typescript
|
|
198
202
|
class RealtimeGateway extends WebSocketGateway {
|
|
199
203
|
constructor(realtimeService: RealtimeService, options?: RealtimeGatewayOptions);
|
|
200
|
-
attachToServer(
|
|
204
|
+
attachToServer(
|
|
205
|
+
server: HttpServer,
|
|
206
|
+
options?: { path?: string; maxPayload?: number }
|
|
207
|
+
): WebSocketServer;
|
|
201
208
|
}
|
|
202
209
|
```
|
|
203
210
|
|
|
@@ -240,4 +247,4 @@ Apache 2.0 © [HazelJS](https://hazeljs.ai)
|
|
|
240
247
|
- [OpenAI Realtime API](https://platform.openai.com/docs/guides/realtime)
|
|
241
248
|
- [GitHub](https://github.com/hazel-js/hazeljs)
|
|
242
249
|
- [Issues](https://github.com/hazel-js/hazeljs/issues)
|
|
243
|
-
- [Discord](https://discord.
|
|
250
|
+
- [Discord](https://discord.gg/PxNBPzvQk7)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hazeljs/realtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Real-time voice AI for HazelJS - OpenAI Realtime API & Gemini Live integration for low-latency speech-to-speech",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"clean": "rm -rf dist"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@hazeljs/websocket": "^0.
|
|
18
|
+
"@hazeljs/websocket": "^0.8.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"@hazeljs/core": ">=0.2.0-beta.0"
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"url": "https://github.com/hazeljs/hazel-js/issues"
|
|
55
55
|
},
|
|
56
56
|
"homepage": "https://hazeljs.ai",
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "e0ed98ca074dd4f7472816d3c32ef576900dcca6"
|
|
58
58
|
}
|