assemblyai 4.5.0 → 4.6.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/CHANGELOG.md +7 -0
- package/dist/assemblyai.streaming.umd.js +29 -0
- package/dist/assemblyai.umd.js +30 -1
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/browser.mjs +30 -1
- package/dist/bun.mjs +30 -1
- package/dist/deno.mjs +30 -1
- package/dist/index.cjs +30 -1
- package/dist/index.mjs +30 -1
- package/dist/node.cjs +30 -1
- package/dist/node.mjs +30 -1
- package/dist/services/realtime/service.d.ts +60 -0
- package/dist/streaming.browser.mjs +29 -0
- package/dist/streaming.cjs +29 -0
- package/dist/streaming.mjs +29 -0
- package/dist/types/openapi.generated.d.ts +17 -8
- package/dist/workerd.mjs +30 -1
- package/package.json +27 -15
- package/src/services/realtime/service.ts +65 -0
- package/src/types/openapi.generated.ts +28 -9
package/dist/node.mjs
CHANGED
|
@@ -20,7 +20,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
20
20
|
defaultUserAgentString += navigator.userAgent;
|
|
21
21
|
}
|
|
22
22
|
const defaultUserAgent = {
|
|
23
|
-
sdk: { name: "JavaScript", version: "4.
|
|
23
|
+
sdk: { name: "JavaScript", version: "4.6.0" },
|
|
24
24
|
};
|
|
25
25
|
if (typeof process !== "undefined") {
|
|
26
26
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -190,7 +190,14 @@ class RealtimeError extends Error {
|
|
|
190
190
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
191
191
|
const forceEndOfUtteranceMessage = `{"force_end_utterance":true}`;
|
|
192
192
|
const terminateSessionMessage = `{"terminate_session":true}`;
|
|
193
|
+
/**
|
|
194
|
+
* RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
|
|
195
|
+
*/
|
|
193
196
|
class RealtimeTranscriber {
|
|
197
|
+
/**
|
|
198
|
+
* Create a new RealtimeTranscriber.
|
|
199
|
+
* @param params - Parameters to configure the RealtimeTranscriber
|
|
200
|
+
*/
|
|
194
201
|
constructor(params) {
|
|
195
202
|
this.listeners = {};
|
|
196
203
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
@@ -230,10 +237,19 @@ class RealtimeTranscriber {
|
|
|
230
237
|
url.search = searchParams.toString();
|
|
231
238
|
return url;
|
|
232
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Add a listener for an event.
|
|
242
|
+
* @param event - The event to listen for.
|
|
243
|
+
* @param listener - The function to call when the event is emitted.
|
|
244
|
+
*/
|
|
233
245
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
234
246
|
on(event, listener) {
|
|
235
247
|
this.listeners[event] = listener;
|
|
236
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Connect to the server and begin a new session.
|
|
251
|
+
* @returns A promise that resolves when the connection is established and the session begins.
|
|
252
|
+
*/
|
|
237
253
|
connect() {
|
|
238
254
|
return new Promise((resolve) => {
|
|
239
255
|
if (this.socket) {
|
|
@@ -312,9 +328,17 @@ class RealtimeTranscriber {
|
|
|
312
328
|
};
|
|
313
329
|
});
|
|
314
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* Send audio data to the server.
|
|
333
|
+
* @param audio - The audio data to send to the server.
|
|
334
|
+
*/
|
|
315
335
|
sendAudio(audio) {
|
|
316
336
|
this.send(audio);
|
|
317
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* Create a writable stream that can be used to send audio data to the server.
|
|
340
|
+
* @returns A writable stream that can be used to send audio data to the server.
|
|
341
|
+
*/
|
|
318
342
|
stream() {
|
|
319
343
|
return new WritableStream({
|
|
320
344
|
write: (chunk) => {
|
|
@@ -342,6 +366,11 @@ class RealtimeTranscriber {
|
|
|
342
366
|
}
|
|
343
367
|
this.socket.send(data);
|
|
344
368
|
}
|
|
369
|
+
/**
|
|
370
|
+
* Close the connection to the server.
|
|
371
|
+
* @param waitForSessionTermination - If true, the method will wait for the session to be terminated before closing the connection.
|
|
372
|
+
* While waiting for the session to be terminated, you will receive the final transcript and session information.
|
|
373
|
+
*/
|
|
345
374
|
async close(waitForSessionTermination = true) {
|
|
346
375
|
if (this.socket) {
|
|
347
376
|
if (this.socket.readyState === this.socket.OPEN) {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { RealtimeTranscriberParams, RealtimeTranscript, PartialTranscript, FinalTranscript, SessionBeginsEventData, AudioData, SessionInformation } from "../..";
|
|
2
|
+
/**
|
|
3
|
+
* RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
|
|
4
|
+
*/
|
|
2
5
|
export declare class RealtimeTranscriber {
|
|
3
6
|
private realtimeUrl;
|
|
4
7
|
private sampleRate;
|
|
@@ -11,17 +14,69 @@ export declare class RealtimeTranscriber {
|
|
|
11
14
|
private socket?;
|
|
12
15
|
private listeners;
|
|
13
16
|
private sessionTerminatedResolve?;
|
|
17
|
+
/**
|
|
18
|
+
* Create a new RealtimeTranscriber.
|
|
19
|
+
* @param params - Parameters to configure the RealtimeTranscriber
|
|
20
|
+
*/
|
|
14
21
|
constructor(params: RealtimeTranscriberParams);
|
|
15
22
|
private connectionUrl;
|
|
23
|
+
/**
|
|
24
|
+
* Listen for the open event which is emitted when the connection is established and the session begins.
|
|
25
|
+
* @param event - The open event.
|
|
26
|
+
* @param listener - The function to call when the event is emitted.
|
|
27
|
+
*/
|
|
16
28
|
on(event: "open", listener: (event: SessionBeginsEventData) => void): void;
|
|
29
|
+
/**
|
|
30
|
+
* Listen for the transcript event which is emitted when a partian or final transcript is received.
|
|
31
|
+
* @param event - The transcript event.
|
|
32
|
+
* @param listener - The function to call when the event is emitted.
|
|
33
|
+
*/
|
|
17
34
|
on(event: "transcript", listener: (transcript: RealtimeTranscript) => void): void;
|
|
35
|
+
/**
|
|
36
|
+
* Listen for the partial transcript event which is emitted when a partial transcript is received.
|
|
37
|
+
* @param event - The partial transcript event.
|
|
38
|
+
* @param listener - The function to call when the event is emitted.
|
|
39
|
+
*/
|
|
18
40
|
on(event: "transcript.partial", listener: (transcript: PartialTranscript) => void): void;
|
|
41
|
+
/**
|
|
42
|
+
* Listen for the final transcript event which is emitted when a final transcript is received.
|
|
43
|
+
* @param event - The final transcript event.
|
|
44
|
+
* @param listener - The function to call when the event is emitted.
|
|
45
|
+
*/
|
|
19
46
|
on(event: "transcript.final", listener: (transcript: FinalTranscript) => void): void;
|
|
47
|
+
/**
|
|
48
|
+
* Listen for the session information event which is emitted when session information is received.
|
|
49
|
+
* The session information is sent right before the session is terminated.
|
|
50
|
+
* @param event - The session information event.
|
|
51
|
+
* @param listener - The function to call when the event is emitted.
|
|
52
|
+
*/
|
|
20
53
|
on(event: "session_information", listener: (info: SessionInformation) => void): void;
|
|
54
|
+
/**
|
|
55
|
+
* Listen for the error event which is emitted when an error occurs.
|
|
56
|
+
* @param event - The error event.
|
|
57
|
+
* @param listener - The function to call when the event is emitted.
|
|
58
|
+
*/
|
|
21
59
|
on(event: "error", listener: (error: Error) => void): void;
|
|
60
|
+
/**
|
|
61
|
+
* Listen for the close event which is emitted when the connection is closed.
|
|
62
|
+
* @param event - The close event.
|
|
63
|
+
* @param listener - The function to call when the event is emitted.
|
|
64
|
+
*/
|
|
22
65
|
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
66
|
+
/**
|
|
67
|
+
* Connect to the server and begin a new session.
|
|
68
|
+
* @returns A promise that resolves when the connection is established and the session begins.
|
|
69
|
+
*/
|
|
23
70
|
connect(): Promise<SessionBeginsEventData>;
|
|
71
|
+
/**
|
|
72
|
+
* Send audio data to the server.
|
|
73
|
+
* @param audio - The audio data to send to the server.
|
|
74
|
+
*/
|
|
24
75
|
sendAudio(audio: AudioData): void;
|
|
76
|
+
/**
|
|
77
|
+
* Create a writable stream that can be used to send audio data to the server.
|
|
78
|
+
* @returns A writable stream that can be used to send audio data to the server.
|
|
79
|
+
*/
|
|
25
80
|
stream(): WritableStream<AudioData>;
|
|
26
81
|
/**
|
|
27
82
|
* Manually end an utterance
|
|
@@ -34,6 +89,11 @@ export declare class RealtimeTranscriber {
|
|
|
34
89
|
*/
|
|
35
90
|
configureEndUtteranceSilenceThreshold(threshold: number): void;
|
|
36
91
|
private send;
|
|
92
|
+
/**
|
|
93
|
+
* Close the connection to the server.
|
|
94
|
+
* @param waitForSessionTermination - If true, the method will wait for the session to be terminated before closing the connection.
|
|
95
|
+
* While waiting for the session to be terminated, you will receive the final transcript and session information.
|
|
96
|
+
*/
|
|
37
97
|
close(waitForSessionTermination?: boolean): Promise<void>;
|
|
38
98
|
}
|
|
39
99
|
/**
|
|
@@ -56,7 +56,14 @@ class RealtimeError extends Error {
|
|
|
56
56
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
57
57
|
const forceEndOfUtteranceMessage = `{"force_end_utterance":true}`;
|
|
58
58
|
const terminateSessionMessage = `{"terminate_session":true}`;
|
|
59
|
+
/**
|
|
60
|
+
* RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
|
|
61
|
+
*/
|
|
59
62
|
class RealtimeTranscriber {
|
|
63
|
+
/**
|
|
64
|
+
* Create a new RealtimeTranscriber.
|
|
65
|
+
* @param params - Parameters to configure the RealtimeTranscriber
|
|
66
|
+
*/
|
|
60
67
|
constructor(params) {
|
|
61
68
|
this.listeners = {};
|
|
62
69
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
@@ -96,10 +103,19 @@ class RealtimeTranscriber {
|
|
|
96
103
|
url.search = searchParams.toString();
|
|
97
104
|
return url;
|
|
98
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Add a listener for an event.
|
|
108
|
+
* @param event - The event to listen for.
|
|
109
|
+
* @param listener - The function to call when the event is emitted.
|
|
110
|
+
*/
|
|
99
111
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
112
|
on(event, listener) {
|
|
101
113
|
this.listeners[event] = listener;
|
|
102
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Connect to the server and begin a new session.
|
|
117
|
+
* @returns A promise that resolves when the connection is established and the session begins.
|
|
118
|
+
*/
|
|
103
119
|
connect() {
|
|
104
120
|
return new Promise((resolve) => {
|
|
105
121
|
if (this.socket) {
|
|
@@ -178,9 +194,17 @@ class RealtimeTranscriber {
|
|
|
178
194
|
};
|
|
179
195
|
});
|
|
180
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Send audio data to the server.
|
|
199
|
+
* @param audio - The audio data to send to the server.
|
|
200
|
+
*/
|
|
181
201
|
sendAudio(audio) {
|
|
182
202
|
this.send(audio);
|
|
183
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Create a writable stream that can be used to send audio data to the server.
|
|
206
|
+
* @returns A writable stream that can be used to send audio data to the server.
|
|
207
|
+
*/
|
|
184
208
|
stream() {
|
|
185
209
|
return new WritableStream({
|
|
186
210
|
write: (chunk) => {
|
|
@@ -208,6 +232,11 @@ class RealtimeTranscriber {
|
|
|
208
232
|
}
|
|
209
233
|
this.socket.send(data);
|
|
210
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Close the connection to the server.
|
|
237
|
+
* @param waitForSessionTermination - If true, the method will wait for the session to be terminated before closing the connection.
|
|
238
|
+
* While waiting for the session to be terminated, you will receive the final transcript and session information.
|
|
239
|
+
*/
|
|
211
240
|
async close(waitForSessionTermination = true) {
|
|
212
241
|
if (this.socket) {
|
|
213
242
|
if (this.socket.readyState === this.socket.OPEN) {
|
package/dist/streaming.cjs
CHANGED
|
@@ -86,7 +86,14 @@ class RealtimeError extends Error {
|
|
|
86
86
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
87
87
|
const forceEndOfUtteranceMessage = `{"force_end_utterance":true}`;
|
|
88
88
|
const terminateSessionMessage = `{"terminate_session":true}`;
|
|
89
|
+
/**
|
|
90
|
+
* RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
|
|
91
|
+
*/
|
|
89
92
|
class RealtimeTranscriber {
|
|
93
|
+
/**
|
|
94
|
+
* Create a new RealtimeTranscriber.
|
|
95
|
+
* @param params - Parameters to configure the RealtimeTranscriber
|
|
96
|
+
*/
|
|
90
97
|
constructor(params) {
|
|
91
98
|
var _a, _b;
|
|
92
99
|
this.listeners = {};
|
|
@@ -127,10 +134,19 @@ class RealtimeTranscriber {
|
|
|
127
134
|
url.search = searchParams.toString();
|
|
128
135
|
return url;
|
|
129
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Add a listener for an event.
|
|
139
|
+
* @param event - The event to listen for.
|
|
140
|
+
* @param listener - The function to call when the event is emitted.
|
|
141
|
+
*/
|
|
130
142
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
131
143
|
on(event, listener) {
|
|
132
144
|
this.listeners[event] = listener;
|
|
133
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Connect to the server and begin a new session.
|
|
148
|
+
* @returns A promise that resolves when the connection is established and the session begins.
|
|
149
|
+
*/
|
|
134
150
|
connect() {
|
|
135
151
|
return new Promise((resolve) => {
|
|
136
152
|
if (this.socket) {
|
|
@@ -212,9 +228,17 @@ class RealtimeTranscriber {
|
|
|
212
228
|
};
|
|
213
229
|
});
|
|
214
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Send audio data to the server.
|
|
233
|
+
* @param audio - The audio data to send to the server.
|
|
234
|
+
*/
|
|
215
235
|
sendAudio(audio) {
|
|
216
236
|
this.send(audio);
|
|
217
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Create a writable stream that can be used to send audio data to the server.
|
|
240
|
+
* @returns A writable stream that can be used to send audio data to the server.
|
|
241
|
+
*/
|
|
218
242
|
stream() {
|
|
219
243
|
return new WritableStream({
|
|
220
244
|
write: (chunk) => {
|
|
@@ -242,6 +266,11 @@ class RealtimeTranscriber {
|
|
|
242
266
|
}
|
|
243
267
|
this.socket.send(data);
|
|
244
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Close the connection to the server.
|
|
271
|
+
* @param waitForSessionTermination - If true, the method will wait for the session to be terminated before closing the connection.
|
|
272
|
+
* While waiting for the session to be terminated, you will receive the final transcript and session information.
|
|
273
|
+
*/
|
|
245
274
|
close() {
|
|
246
275
|
return __awaiter(this, arguments, void 0, function* (waitForSessionTermination = true) {
|
|
247
276
|
var _a;
|
package/dist/streaming.mjs
CHANGED
|
@@ -84,7 +84,14 @@ class RealtimeError extends Error {
|
|
|
84
84
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
85
85
|
const forceEndOfUtteranceMessage = `{"force_end_utterance":true}`;
|
|
86
86
|
const terminateSessionMessage = `{"terminate_session":true}`;
|
|
87
|
+
/**
|
|
88
|
+
* RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
|
|
89
|
+
*/
|
|
87
90
|
class RealtimeTranscriber {
|
|
91
|
+
/**
|
|
92
|
+
* Create a new RealtimeTranscriber.
|
|
93
|
+
* @param params - Parameters to configure the RealtimeTranscriber
|
|
94
|
+
*/
|
|
88
95
|
constructor(params) {
|
|
89
96
|
var _a, _b;
|
|
90
97
|
this.listeners = {};
|
|
@@ -125,10 +132,19 @@ class RealtimeTranscriber {
|
|
|
125
132
|
url.search = searchParams.toString();
|
|
126
133
|
return url;
|
|
127
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Add a listener for an event.
|
|
137
|
+
* @param event - The event to listen for.
|
|
138
|
+
* @param listener - The function to call when the event is emitted.
|
|
139
|
+
*/
|
|
128
140
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
129
141
|
on(event, listener) {
|
|
130
142
|
this.listeners[event] = listener;
|
|
131
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Connect to the server and begin a new session.
|
|
146
|
+
* @returns A promise that resolves when the connection is established and the session begins.
|
|
147
|
+
*/
|
|
132
148
|
connect() {
|
|
133
149
|
return new Promise((resolve) => {
|
|
134
150
|
if (this.socket) {
|
|
@@ -210,9 +226,17 @@ class RealtimeTranscriber {
|
|
|
210
226
|
};
|
|
211
227
|
});
|
|
212
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Send audio data to the server.
|
|
231
|
+
* @param audio - The audio data to send to the server.
|
|
232
|
+
*/
|
|
213
233
|
sendAudio(audio) {
|
|
214
234
|
this.send(audio);
|
|
215
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* Create a writable stream that can be used to send audio data to the server.
|
|
238
|
+
* @returns A writable stream that can be used to send audio data to the server.
|
|
239
|
+
*/
|
|
216
240
|
stream() {
|
|
217
241
|
return new WritableStream({
|
|
218
242
|
write: (chunk) => {
|
|
@@ -240,6 +264,11 @@ class RealtimeTranscriber {
|
|
|
240
264
|
}
|
|
241
265
|
this.socket.send(data);
|
|
242
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Close the connection to the server.
|
|
269
|
+
* @param waitForSessionTermination - If true, the method will wait for the session to be terminated before closing the connection.
|
|
270
|
+
* While waiting for the session to be terminated, you will receive the final transcript and session information.
|
|
271
|
+
*/
|
|
243
272
|
close() {
|
|
244
273
|
return __awaiter(this, arguments, void 0, function* (waitForSessionTermination = true) {
|
|
245
274
|
var _a;
|
|
@@ -562,7 +562,6 @@ export type LemurBaseParams = {
|
|
|
562
562
|
]>;
|
|
563
563
|
/**
|
|
564
564
|
* The model that is used for the final prompt after compression is performed.
|
|
565
|
-
* Defaults to "default".
|
|
566
565
|
*
|
|
567
566
|
* @defaultValue "default
|
|
568
567
|
*/
|
|
@@ -614,7 +613,7 @@ export type LemurBaseResponse = {
|
|
|
614
613
|
* The model that is used for the final prompt after compression is performed.
|
|
615
614
|
*
|
|
616
615
|
*/
|
|
617
|
-
export type LemurModel = "
|
|
616
|
+
export type LemurModel = "anthropic/claude-3-5-sonnet" | "anthropic/claude-3-opus" | "anthropic/claude-3-haiku" | "anthropic/claude-3-sonnet" | "anthropic/claude-2-1" | "anthropic/claude-2" | "default" | "anthropic/claude-instant-1-2" | "basic" | "assemblyai/mistral-7b";
|
|
618
617
|
/**
|
|
619
618
|
* @example
|
|
620
619
|
* ```js
|
|
@@ -1025,6 +1024,10 @@ export type RealtimeTemporaryTokenResponse = {
|
|
|
1025
1024
|
*/
|
|
1026
1025
|
token: string;
|
|
1027
1026
|
};
|
|
1027
|
+
/**
|
|
1028
|
+
* The notification when the redacted audio is ready.
|
|
1029
|
+
*/
|
|
1030
|
+
export type RedactedAudioNotification = RedactedAudioResponse;
|
|
1028
1031
|
/**
|
|
1029
1032
|
* @example
|
|
1030
1033
|
* ```js
|
|
@@ -2343,15 +2346,17 @@ export type Transcript = {
|
|
|
2343
2346
|
*/
|
|
2344
2347
|
webhook_auth: boolean;
|
|
2345
2348
|
/**
|
|
2346
|
-
* The header name
|
|
2349
|
+
* The header name to be sent with the transcript completed or failed webhook requests
|
|
2347
2350
|
*/
|
|
2348
2351
|
webhook_auth_header_name?: string | null;
|
|
2349
2352
|
/**
|
|
2350
|
-
* The status code we received from your server when delivering
|
|
2353
|
+
* The status code we received from your server when delivering the transcript completed or failed webhook request, if a webhook URL was provided
|
|
2351
2354
|
*/
|
|
2352
2355
|
webhook_status_code?: number | null;
|
|
2353
2356
|
/**
|
|
2354
|
-
* The URL to which we send
|
|
2357
|
+
* The URL to which we send webhook requests.
|
|
2358
|
+
* We sends two different types of webhook requests.
|
|
2359
|
+
* One request when a transcript is completed or failed, and one request when the redacted audio is ready if redact_pii_audio is enabled.
|
|
2355
2360
|
*/
|
|
2356
2361
|
webhook_url?: string | null;
|
|
2357
2362
|
/**
|
|
@@ -2660,17 +2665,17 @@ export type TranscriptOptionalParams = {
|
|
|
2660
2665
|
*/
|
|
2661
2666
|
topics?: string[];
|
|
2662
2667
|
/**
|
|
2663
|
-
* The header name
|
|
2668
|
+
* The header name to be sent with the transcript completed or failed webhook requests
|
|
2664
2669
|
* @defaultValue null
|
|
2665
2670
|
*/
|
|
2666
2671
|
webhook_auth_header_name?: string | null;
|
|
2667
2672
|
/**
|
|
2668
|
-
*
|
|
2673
|
+
* The header value to send back with the transcript completed or failed webhook requests for added security
|
|
2669
2674
|
* @defaultValue null
|
|
2670
2675
|
*/
|
|
2671
2676
|
webhook_auth_header_value?: string | null;
|
|
2672
2677
|
/**
|
|
2673
|
-
* The URL to which
|
|
2678
|
+
* The URL to which we send webhook requests. We sends two different types of webhook requests. One request when a transcript is completed or failed, and one request when the redacted audio is ready if redact_pii_audio is enabled.
|
|
2674
2679
|
*/
|
|
2675
2680
|
webhook_url?: string;
|
|
2676
2681
|
/**
|
|
@@ -3013,6 +3018,10 @@ export type TranscriptUtterance = {
|
|
|
3013
3018
|
*/
|
|
3014
3019
|
words: TranscriptWord[];
|
|
3015
3020
|
};
|
|
3021
|
+
/**
|
|
3022
|
+
* The notifications sent to the webhook URL.
|
|
3023
|
+
*/
|
|
3024
|
+
export type TranscriptWebhookNotification = TranscriptReadyNotification | RedactedAudioNotification;
|
|
3016
3025
|
/**
|
|
3017
3026
|
* @example
|
|
3018
3027
|
* ```js
|
package/dist/workerd.mjs
CHANGED
|
@@ -15,7 +15,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
15
15
|
defaultUserAgentString += navigator.userAgent;
|
|
16
16
|
}
|
|
17
17
|
const defaultUserAgent = {
|
|
18
|
-
sdk: { name: "JavaScript", version: "4.
|
|
18
|
+
sdk: { name: "JavaScript", version: "4.6.0" },
|
|
19
19
|
};
|
|
20
20
|
if (typeof process !== "undefined") {
|
|
21
21
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -191,7 +191,14 @@ class RealtimeError extends Error {
|
|
|
191
191
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
192
192
|
const forceEndOfUtteranceMessage = `{"force_end_utterance":true}`;
|
|
193
193
|
const terminateSessionMessage = `{"terminate_session":true}`;
|
|
194
|
+
/**
|
|
195
|
+
* RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
|
|
196
|
+
*/
|
|
194
197
|
class RealtimeTranscriber {
|
|
198
|
+
/**
|
|
199
|
+
* Create a new RealtimeTranscriber.
|
|
200
|
+
* @param params - Parameters to configure the RealtimeTranscriber
|
|
201
|
+
*/
|
|
195
202
|
constructor(params) {
|
|
196
203
|
this.listeners = {};
|
|
197
204
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
@@ -231,10 +238,19 @@ class RealtimeTranscriber {
|
|
|
231
238
|
url.search = searchParams.toString();
|
|
232
239
|
return url;
|
|
233
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Add a listener for an event.
|
|
243
|
+
* @param event - The event to listen for.
|
|
244
|
+
* @param listener - The function to call when the event is emitted.
|
|
245
|
+
*/
|
|
234
246
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
235
247
|
on(event, listener) {
|
|
236
248
|
this.listeners[event] = listener;
|
|
237
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* Connect to the server and begin a new session.
|
|
252
|
+
* @returns A promise that resolves when the connection is established and the session begins.
|
|
253
|
+
*/
|
|
238
254
|
connect() {
|
|
239
255
|
return new Promise((resolve) => {
|
|
240
256
|
if (this.socket) {
|
|
@@ -313,9 +329,17 @@ class RealtimeTranscriber {
|
|
|
313
329
|
};
|
|
314
330
|
});
|
|
315
331
|
}
|
|
332
|
+
/**
|
|
333
|
+
* Send audio data to the server.
|
|
334
|
+
* @param audio - The audio data to send to the server.
|
|
335
|
+
*/
|
|
316
336
|
sendAudio(audio) {
|
|
317
337
|
this.send(audio);
|
|
318
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* Create a writable stream that can be used to send audio data to the server.
|
|
341
|
+
* @returns A writable stream that can be used to send audio data to the server.
|
|
342
|
+
*/
|
|
319
343
|
stream() {
|
|
320
344
|
return new WritableStream({
|
|
321
345
|
write: (chunk) => {
|
|
@@ -343,6 +367,11 @@ class RealtimeTranscriber {
|
|
|
343
367
|
}
|
|
344
368
|
this.socket.send(data);
|
|
345
369
|
}
|
|
370
|
+
/**
|
|
371
|
+
* Close the connection to the server.
|
|
372
|
+
* @param waitForSessionTermination - If true, the method will wait for the session to be terminated before closing the connection.
|
|
373
|
+
* While waiting for the session to be terminated, you will receive the final transcript and session information.
|
|
374
|
+
*/
|
|
346
375
|
async close(waitForSessionTermination = true) {
|
|
347
376
|
if (this.socket) {
|
|
348
377
|
if (this.socket.readyState === this.socket.OPEN) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblyai",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "The AssemblyAI JavaScript SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription, as well as the latest LeMUR models.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18"
|
|
@@ -115,39 +115,51 @@
|
|
|
115
115
|
"docs"
|
|
116
116
|
],
|
|
117
117
|
"devDependencies": {
|
|
118
|
-
"@babel/preset-env": "^7.24.
|
|
119
|
-
"@babel/preset-typescript": "^7.24.
|
|
118
|
+
"@babel/preset-env": "^7.24.7",
|
|
119
|
+
"@babel/preset-typescript": "^7.24.7",
|
|
120
120
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
121
|
-
"@rollup/plugin-replace": "^5.0.
|
|
121
|
+
"@rollup/plugin-replace": "^5.0.7",
|
|
122
122
|
"@rollup/plugin-terser": "^0.4.4",
|
|
123
123
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
124
124
|
"@types/jest": "^29.5.12",
|
|
125
|
-
"@types/node": "^18.19.
|
|
125
|
+
"@types/node": "^18.19.38",
|
|
126
126
|
"@types/websocket": "^1.0.10",
|
|
127
127
|
"@types/ws": "^8.5.10",
|
|
128
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
128
|
+
"@typescript-eslint/eslint-plugin": "^7.13.1",
|
|
129
129
|
"dotenv": "^16.4.5",
|
|
130
130
|
"eslint": "^8.57.0",
|
|
131
|
-
"eslint-plugin-tsdoc": "^0.
|
|
131
|
+
"eslint-plugin-tsdoc": "^0.3.0",
|
|
132
132
|
"jest": "^29.7.0",
|
|
133
133
|
"jest-cli": "^29.7.0",
|
|
134
134
|
"jest-fetch-mock": "^3.0.3",
|
|
135
135
|
"jest-junit": "^16.0.0",
|
|
136
136
|
"jest-websocket-mock": "^2.5.0",
|
|
137
|
-
"jsr": "^0.12.4",
|
|
138
137
|
"mock-socket": "^9.3.1",
|
|
139
138
|
"openapi-typescript": "^6.7.5",
|
|
140
|
-
"prettier": "^3.2
|
|
141
|
-
"publint": "^0.2.
|
|
142
|
-
"rimraf": "^5.0.
|
|
143
|
-
"rollup": "^4.
|
|
144
|
-
"ts-jest": "^29.1.
|
|
145
|
-
"tslib": "^2.
|
|
139
|
+
"prettier": "^3.3.2",
|
|
140
|
+
"publint": "^0.2.8",
|
|
141
|
+
"rimraf": "^5.0.7",
|
|
142
|
+
"rollup": "^4.18.0",
|
|
143
|
+
"ts-jest": "^29.1.5",
|
|
144
|
+
"tslib": "^2.6.3",
|
|
146
145
|
"typedoc": "^0.25.13",
|
|
147
146
|
"typedoc-plugin-extras": "^3.0.0",
|
|
148
147
|
"typescript": "^5.4.5"
|
|
149
148
|
},
|
|
150
149
|
"dependencies": {
|
|
151
|
-
"ws": "^8.17.
|
|
150
|
+
"ws": "^8.17.1"
|
|
151
|
+
},
|
|
152
|
+
"pnpm": {
|
|
153
|
+
"packageExtensions": {
|
|
154
|
+
"ws": {
|
|
155
|
+
"peerDependencies": {
|
|
156
|
+
"@types/ws": "^8.5.10"
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
"overrides": {
|
|
161
|
+
"undici@<5.28.4": ">=5.28.4",
|
|
162
|
+
"braces@<3.0.3": ">=3.0.3"
|
|
163
|
+
}
|
|
152
164
|
}
|
|
153
165
|
}
|