assemblyai 4.4.0 → 4.5.0-beta.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 +14 -2
- package/dist/assemblyai.umd.js +15 -24
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/browser.mjs +614 -0
- package/dist/bun.mjs +9 -10
- package/dist/deno.mjs +9 -10
- package/dist/index.cjs +10 -10
- package/dist/index.mjs +10 -10
- package/dist/node.cjs +9 -10
- package/dist/node.mjs +9 -10
- package/dist/polyfills/websocket/browser.d.ts +3 -0
- package/dist/polyfills/websocket/default.d.ts +3 -0
- package/dist/polyfills/websocket/index.d.ts +27 -0
- package/dist/services/realtime/service.d.ts +0 -1
- package/dist/types/realtime/index.d.ts +4 -2
- package/package.json +8 -12
- package/src/polyfills/websocket/browser.ts +18 -0
- package/src/polyfills/websocket/default.ts +8 -0
- package/src/polyfills/websocket/index.ts +41 -0
- package/src/services/realtime/service.ts +18 -20
- package/src/types/realtime/index.ts +4 -2
- package/src/polyfills/ws/browser.mjs +0 -15
- package/src/polyfills/ws/index.cjs +0 -1
- package/src/polyfills/ws/index.d.ts +0 -2
- package/src/polyfills/ws/index.mjs +0 -2
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { WritableStream } from "#streams";
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
PolyfillWebSocket,
|
|
4
|
+
factory as polyfillWebSocketFactory,
|
|
5
|
+
} from "#websocket";
|
|
3
6
|
import { ErrorEvent, MessageEvent, CloseEvent } from "ws";
|
|
4
7
|
import {
|
|
5
8
|
RealtimeEvents,
|
|
@@ -50,10 +53,9 @@ export class RealtimeTranscriber {
|
|
|
50
53
|
private apiKey?: string;
|
|
51
54
|
private token?: string;
|
|
52
55
|
private endUtteranceSilenceThreshold?: number;
|
|
53
|
-
private enableExtraSessionInformation?: boolean;
|
|
54
56
|
private disablePartialTranscripts?: boolean;
|
|
55
57
|
|
|
56
|
-
private socket?:
|
|
58
|
+
private socket?: PolyfillWebSocket;
|
|
57
59
|
private listeners: RealtimeListeners = {};
|
|
58
60
|
private sessionTerminatedResolve?: () => void;
|
|
59
61
|
|
|
@@ -63,7 +65,6 @@ export class RealtimeTranscriber {
|
|
|
63
65
|
this.wordBoost = params.wordBoost;
|
|
64
66
|
this.encoding = params.encoding;
|
|
65
67
|
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
66
|
-
this.enableExtraSessionInformation = params.enableExtraSessionInformation;
|
|
67
68
|
this.disablePartialTranscripts = params.disablePartialTranscripts;
|
|
68
69
|
if ("token" in params && params.token) this.token = params.token;
|
|
69
70
|
if ("apiKey" in params && params.apiKey) this.apiKey = params.apiKey;
|
|
@@ -91,12 +92,9 @@ export class RealtimeTranscriber {
|
|
|
91
92
|
if (this.encoding) {
|
|
92
93
|
searchParams.set("encoding", this.encoding);
|
|
93
94
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
this.enableExtraSessionInformation.toString(),
|
|
98
|
-
);
|
|
99
|
-
}
|
|
95
|
+
|
|
96
|
+
searchParams.set("enable_extra_session_information", "true");
|
|
97
|
+
|
|
100
98
|
if (this.disablePartialTranscripts) {
|
|
101
99
|
searchParams.set(
|
|
102
100
|
"disable_partial_transcripts",
|
|
@@ -141,15 +139,15 @@ export class RealtimeTranscriber {
|
|
|
141
139
|
const url = this.connectionUrl();
|
|
142
140
|
|
|
143
141
|
if (this.token) {
|
|
144
|
-
this.socket =
|
|
142
|
+
this.socket = polyfillWebSocketFactory(url.toString());
|
|
145
143
|
} else {
|
|
146
|
-
this.socket =
|
|
144
|
+
this.socket = polyfillWebSocketFactory(url.toString(), {
|
|
147
145
|
headers: { Authorization: this.apiKey },
|
|
148
146
|
});
|
|
149
147
|
}
|
|
150
|
-
this.socket
|
|
148
|
+
this.socket!.binaryType = "arraybuffer";
|
|
151
149
|
|
|
152
|
-
this.socket
|
|
150
|
+
this.socket!.onopen = () => {
|
|
153
151
|
if (
|
|
154
152
|
this.endUtteranceSilenceThreshold === undefined ||
|
|
155
153
|
this.endUtteranceSilenceThreshold === null
|
|
@@ -161,7 +159,7 @@ export class RealtimeTranscriber {
|
|
|
161
159
|
);
|
|
162
160
|
};
|
|
163
161
|
|
|
164
|
-
this.socket
|
|
162
|
+
this.socket!.onclose = ({ code, reason }: CloseEvent) => {
|
|
165
163
|
if (!reason) {
|
|
166
164
|
if (code in RealtimeErrorType) {
|
|
167
165
|
reason = RealtimeErrorMessages[code as RealtimeErrorType];
|
|
@@ -170,12 +168,12 @@ export class RealtimeTranscriber {
|
|
|
170
168
|
this.listeners.close?.(code, reason);
|
|
171
169
|
};
|
|
172
170
|
|
|
173
|
-
this.socket
|
|
171
|
+
this.socket!.onerror = (event: ErrorEvent) => {
|
|
174
172
|
if (event.error) this.listeners.error?.(event.error as Error);
|
|
175
173
|
else this.listeners.error?.(new Error(event.message));
|
|
176
174
|
};
|
|
177
175
|
|
|
178
|
-
this.socket
|
|
176
|
+
this.socket!.onmessage = ({ data }: MessageEvent) => {
|
|
179
177
|
const message = JSON.parse(data.toString()) as RealtimeMessage;
|
|
180
178
|
if ("error" in message) {
|
|
181
179
|
this.listeners.error?.(new RealtimeError(message.error));
|
|
@@ -247,7 +245,7 @@ export class RealtimeTranscriber {
|
|
|
247
245
|
}
|
|
248
246
|
|
|
249
247
|
private send(data: BufferLike) {
|
|
250
|
-
if (!this.socket || this.socket.readyState !==
|
|
248
|
+
if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
|
|
251
249
|
throw new Error("Socket is not open for communication");
|
|
252
250
|
}
|
|
253
251
|
this.socket.send(data);
|
|
@@ -255,7 +253,7 @@ export class RealtimeTranscriber {
|
|
|
255
253
|
|
|
256
254
|
async close(waitForSessionTermination = true) {
|
|
257
255
|
if (this.socket) {
|
|
258
|
-
if (this.socket.readyState ===
|
|
256
|
+
if (this.socket.readyState === this.socket.OPEN) {
|
|
259
257
|
if (waitForSessionTermination) {
|
|
260
258
|
const sessionTerminatedPromise = new Promise<void>((resolve) => {
|
|
261
259
|
this.sessionTerminatedResolve = resolve;
|
|
@@ -266,7 +264,7 @@ export class RealtimeTranscriber {
|
|
|
266
264
|
this.socket.send(terminateSessionMessage);
|
|
267
265
|
}
|
|
268
266
|
}
|
|
269
|
-
if (
|
|
267
|
+
if (this.socket?.removeAllListeners) this.socket.removeAllListeners();
|
|
270
268
|
this.socket.close();
|
|
271
269
|
}
|
|
272
270
|
|
|
@@ -37,7 +37,8 @@ type CreateRealtimeTranscriberParams = {
|
|
|
37
37
|
/**
|
|
38
38
|
* Enable extra session information.
|
|
39
39
|
* Set to `true` to receive the `session_information` message before the session ends. Defaults to `false`.
|
|
40
|
-
* @defaultValue
|
|
40
|
+
* @defaultValue true
|
|
41
|
+
* @deprecated This parameter is now ignored and will be removed. Session information will always be sent.
|
|
41
42
|
*/
|
|
42
43
|
enableExtraSessionInformation?: boolean;
|
|
43
44
|
} & (
|
|
@@ -91,7 +92,8 @@ type RealtimeTranscriberParams = {
|
|
|
91
92
|
/**
|
|
92
93
|
* Enable extra session information.
|
|
93
94
|
* Set to `true` to receive the `session_information` message before the session ends. Defaults to `false`.
|
|
94
|
-
* @defaultValue
|
|
95
|
+
* @defaultValue true
|
|
96
|
+
* @deprecated This parameter is now ignored and will be removed. Session information will always be sent.
|
|
95
97
|
*/
|
|
96
98
|
enableExtraSessionInformation?: boolean;
|
|
97
99
|
} & (
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
var ws = null;
|
|
2
|
-
|
|
3
|
-
if (typeof WebSocket !== "undefined") {
|
|
4
|
-
ws = WebSocket;
|
|
5
|
-
} else if (typeof MozWebSocket !== "undefined") {
|
|
6
|
-
ws = MozWebSocket;
|
|
7
|
-
} else if (typeof global !== "undefined") {
|
|
8
|
-
ws = global.WebSocket || global.MozWebSocket;
|
|
9
|
-
} else if (typeof window !== "undefined") {
|
|
10
|
-
ws = window.WebSocket || window.MozWebSocket;
|
|
11
|
-
} else if (typeof self !== "undefined") {
|
|
12
|
-
ws = self.WebSocket || self.MozWebSocket;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default ws;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("ws");
|