assemblyai 4.35.0 → 4.35.4
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 +16 -0
- package/README.md +7 -8
- package/dist/assemblyai.streaming.umd.js +18 -6
- package/dist/assemblyai.streaming.umd.min.js +1 -1
- package/dist/assemblyai.umd.js +18 -6
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/browser.mjs +18 -6
- package/dist/bun.mjs +18 -6
- package/dist/deno.mjs +18 -6
- package/dist/exports/streaming.d.ts +1 -1
- package/dist/index.cjs +18 -6
- package/dist/index.mjs +18 -6
- package/dist/node.cjs +18 -6
- package/dist/node.mjs +18 -6
- package/dist/streaming.browser.mjs +18 -6
- package/dist/streaming.cjs +17 -5
- package/dist/streaming.mjs +17 -5
- package/dist/types/asyncapi.generated.d.ts +1 -1
- package/dist/types/streaming/index.d.ts +24 -1
- package/dist/workerd.mjs +18 -6
- package/package.json +1 -1
- package/src/exports/streaming.ts +1 -1
- package/src/services/streaming/service.ts +27 -6
- package/src/types/asyncapi.generated.ts +1 -1
- package/src/types/streaming/index.ts +24 -1
|
@@ -87,7 +87,12 @@ export type StreamingTranscriberParams = {
|
|
|
87
87
|
* Milliseconds to wait between connection attempts. Defaults to 500.
|
|
88
88
|
*/
|
|
89
89
|
connectionRetryDelay?: number;
|
|
90
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Required for PCM encodings (and for dual-channel mode). May be omitted
|
|
92
|
+
* for Opus encodings (`opus`, `ogg_opus`) — the stream is self-describing
|
|
93
|
+
* and the server ignores the value.
|
|
94
|
+
*/
|
|
95
|
+
sampleRate?: number;
|
|
91
96
|
encoding?: AudioEncoding;
|
|
92
97
|
endOfTurnConfidenceThreshold?: number;
|
|
93
98
|
/**
|
|
@@ -104,7 +109,19 @@ export type StreamingTranscriberParams = {
|
|
|
104
109
|
prompt?: string;
|
|
105
110
|
agentContext?: string;
|
|
106
111
|
speechModel?: StreamingSpeechModel;
|
|
112
|
+
/**
|
|
113
|
+
* @deprecated Use `languageCodes` instead (pass a single-element array, e.g. `["es"]`,
|
|
114
|
+
* for the same behavior). Still supported for backward compatibility.
|
|
115
|
+
*/
|
|
107
116
|
languageCode?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Recommended way to select languages. Steers transcription toward a set of
|
|
119
|
+
* languages by biasing output toward them on a per-token basis while still
|
|
120
|
+
* allowing native code-switching among them. Pass the languages you expect
|
|
121
|
+
* (e.g. `["en", "es"]`), or a single-element array (e.g. `["es"]`) for a
|
|
122
|
+
* monolingual session. Universal-3.5 Pro Streaming only.
|
|
123
|
+
*/
|
|
124
|
+
languageCodes?: string[];
|
|
108
125
|
languageDetection?: boolean;
|
|
109
126
|
domain?: StreamingDomain;
|
|
110
127
|
inactivityTimeout?: number;
|
|
@@ -255,6 +272,12 @@ export type StreamingUpdateConfiguration = {
|
|
|
255
272
|
filter_profanity?: boolean;
|
|
256
273
|
interruption_delay?: number;
|
|
257
274
|
turn_left_pad_ms?: number;
|
|
275
|
+
/**
|
|
276
|
+
* Steer transcription toward a set of languages mid-stream. Pass an empty
|
|
277
|
+
* array (`[]`) to clear steering and restore the model's default
|
|
278
|
+
* multilingual code-switching. Universal-3.5 Pro Streaming only.
|
|
279
|
+
*/
|
|
280
|
+
language_codes?: string[];
|
|
258
281
|
};
|
|
259
282
|
export type StreamingForceEndpoint = {
|
|
260
283
|
type: "ForceEndpoint";
|
package/dist/workerd.mjs
CHANGED
|
@@ -28,7 +28,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
28
28
|
defaultUserAgentString += navigator.userAgent;
|
|
29
29
|
}
|
|
30
30
|
const defaultUserAgent = {
|
|
31
|
-
sdk: { name: "JavaScript", version: "4.35.
|
|
31
|
+
sdk: { name: "JavaScript", version: "4.35.4" },
|
|
32
32
|
};
|
|
33
33
|
if (typeof process !== "undefined") {
|
|
34
34
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -1036,6 +1036,10 @@ class StreamingTranscriber {
|
|
|
1036
1036
|
if (!(this.token || this.apiKey)) {
|
|
1037
1037
|
throw new Error("API key or temporary token is required.");
|
|
1038
1038
|
}
|
|
1039
|
+
const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
|
|
1040
|
+
if (params.sampleRate === undefined && (!isOpus || params.channels)) {
|
|
1041
|
+
throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus" or "ogg_opus" (the Opus stream is self-describing) and dual-channel mode is not used.');
|
|
1042
|
+
}
|
|
1039
1043
|
if (params.channels) {
|
|
1040
1044
|
if (params.channels.length !== 2) {
|
|
1041
1045
|
throw new Error("StreamingTranscriber.channels must have exactly 2 entries.");
|
|
@@ -1061,10 +1065,12 @@ class StreamingTranscriber {
|
|
|
1061
1065
|
"speaker-history") {
|
|
1062
1066
|
this.speakerHistory = new Map();
|
|
1063
1067
|
}
|
|
1064
|
-
// 20 ms VAD frames at the transcriber's target sample rate.
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
this.
|
|
1068
|
+
// 20 ms VAD frames at the transcriber's target sample rate. The
|
|
1069
|
+
// constructor check above guarantees sampleRate in dual-channel mode.
|
|
1070
|
+
const sampleRate = params.sampleRate;
|
|
1071
|
+
this.vadFrameSamples = Math.max(1, Math.round(sampleRate * 0.02));
|
|
1072
|
+
this.minChunkSamples = Math.max(1, Math.round(sampleRate * (MIN_CHUNK_MS / 1000)));
|
|
1073
|
+
this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(sampleRate * (MAX_CHUNK_MS / 1000)));
|
|
1068
1074
|
this.channelBuffers = new Map(names.map((n) => [n, []]));
|
|
1069
1075
|
this.channelSamplesReceived = new Map(names.map((n) => [n, 0]));
|
|
1070
1076
|
this.channelVadFloatBuffers = new Map(names.map((n) => [n, new Float32Array(this.vadFrameSamples)]));
|
|
@@ -1082,7 +1088,9 @@ class StreamingTranscriber {
|
|
|
1082
1088
|
if (this.token) {
|
|
1083
1089
|
searchParams.set("token", this.token);
|
|
1084
1090
|
}
|
|
1085
|
-
|
|
1091
|
+
if (this.params.sampleRate !== undefined) {
|
|
1092
|
+
searchParams.set("sample_rate", this.params.sampleRate.toString());
|
|
1093
|
+
}
|
|
1086
1094
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
1087
1095
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
1088
1096
|
}
|
|
@@ -1134,8 +1142,12 @@ class StreamingTranscriber {
|
|
|
1134
1142
|
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
1135
1143
|
}
|
|
1136
1144
|
if (this.params.languageCode !== undefined) {
|
|
1145
|
+
console.warn("[Deprecation Warning] `languageCode` is deprecated and will be removed in a future release. Please use `languageCodes` instead.");
|
|
1137
1146
|
searchParams.set("language_code", this.params.languageCode);
|
|
1138
1147
|
}
|
|
1148
|
+
if (this.params.languageCodes !== undefined) {
|
|
1149
|
+
searchParams.set("language_codes", JSON.stringify(this.params.languageCodes));
|
|
1150
|
+
}
|
|
1139
1151
|
if (this.params.languageDetection !== undefined) {
|
|
1140
1152
|
searchParams.set("language_detection", this.params.languageDetection.toString());
|
|
1141
1153
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblyai",
|
|
3
|
-
"version": "4.35.
|
|
3
|
+
"version": "4.35.4",
|
|
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"
|
package/src/exports/streaming.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "../types/asyncapi.generated";
|
|
2
2
|
export * from "../types/realtime";
|
|
3
3
|
export * from "../types/helpers";
|
|
4
|
-
export * from "../types/streaming
|
|
4
|
+
export * from "../types/streaming";
|
|
5
5
|
export * from "../services/realtime/service";
|
|
6
6
|
export * from "../services/streaming/service";
|
|
7
7
|
export * from "../services/streaming/factory";
|
|
@@ -164,6 +164,13 @@ export class StreamingTranscriber {
|
|
|
164
164
|
throw new Error("API key or temporary token is required.");
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
|
|
168
|
+
if (params.sampleRate === undefined && (!isOpus || params.channels)) {
|
|
169
|
+
throw new Error(
|
|
170
|
+
'`sampleRate` is required; it may only be omitted when `encoding` is "opus" or "ogg_opus" (the Opus stream is self-describing) and dual-channel mode is not used.',
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
167
174
|
if (params.channels) {
|
|
168
175
|
if (params.channels.length !== 2) {
|
|
169
176
|
throw new Error(
|
|
@@ -194,15 +201,17 @@ export class StreamingTranscriber {
|
|
|
194
201
|
) {
|
|
195
202
|
this.speakerHistory = new Map();
|
|
196
203
|
}
|
|
197
|
-
// 20 ms VAD frames at the transcriber's target sample rate.
|
|
198
|
-
|
|
204
|
+
// 20 ms VAD frames at the transcriber's target sample rate. The
|
|
205
|
+
// constructor check above guarantees sampleRate in dual-channel mode.
|
|
206
|
+
const sampleRate = params.sampleRate!;
|
|
207
|
+
this.vadFrameSamples = Math.max(1, Math.round(sampleRate * 0.02));
|
|
199
208
|
this.minChunkSamples = Math.max(
|
|
200
209
|
1,
|
|
201
|
-
Math.round(
|
|
210
|
+
Math.round(sampleRate * (MIN_CHUNK_MS / 1000)),
|
|
202
211
|
);
|
|
203
212
|
this.maxChunkSamples = Math.max(
|
|
204
213
|
this.minChunkSamples,
|
|
205
|
-
Math.round(
|
|
214
|
+
Math.round(sampleRate * (MAX_CHUNK_MS / 1000)),
|
|
206
215
|
);
|
|
207
216
|
this.channelBuffers = new Map(names.map((n) => [n, [] as number[]]));
|
|
208
217
|
this.channelSamplesReceived = new Map(names.map((n) => [n, 0]));
|
|
@@ -230,7 +239,9 @@ export class StreamingTranscriber {
|
|
|
230
239
|
searchParams.set("token", this.token);
|
|
231
240
|
}
|
|
232
241
|
|
|
233
|
-
|
|
242
|
+
if (this.params.sampleRate !== undefined) {
|
|
243
|
+
searchParams.set("sample_rate", this.params.sampleRate.toString());
|
|
244
|
+
}
|
|
234
245
|
|
|
235
246
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
236
247
|
searchParams.set(
|
|
@@ -313,9 +324,19 @@ export class StreamingTranscriber {
|
|
|
313
324
|
}
|
|
314
325
|
|
|
315
326
|
if (this.params.languageCode !== undefined) {
|
|
327
|
+
console.warn(
|
|
328
|
+
"[Deprecation Warning] `languageCode` is deprecated and will be removed in a future release. Please use `languageCodes` instead.",
|
|
329
|
+
);
|
|
316
330
|
searchParams.set("language_code", this.params.languageCode);
|
|
317
331
|
}
|
|
318
332
|
|
|
333
|
+
if (this.params.languageCodes !== undefined) {
|
|
334
|
+
searchParams.set(
|
|
335
|
+
"language_codes",
|
|
336
|
+
JSON.stringify(this.params.languageCodes),
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
319
340
|
if (this.params.languageDetection !== undefined) {
|
|
320
341
|
searchParams.set(
|
|
321
342
|
"language_detection",
|
|
@@ -743,7 +764,7 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
743
764
|
let vadIdx = this.channelVadBufferIdx!.get(name)!;
|
|
744
765
|
let received = this.channelSamplesReceived!.get(name)!;
|
|
745
766
|
const vad = this.channelVads!.get(name)!;
|
|
746
|
-
const sampleRate = this.params.sampleRate
|
|
767
|
+
const sampleRate = this.params.sampleRate!;
|
|
747
768
|
const frameSize = this.vadFrameSamples;
|
|
748
769
|
|
|
749
770
|
for (let i = 0; i < samples.length; i++) {
|
|
@@ -25,7 +25,7 @@ export type AudioData = ArrayBufferLike;
|
|
|
25
25
|
* The encoding of the audio data
|
|
26
26
|
* @defaultValue "pcm_s16"le
|
|
27
27
|
*/
|
|
28
|
-
export type AudioEncoding = "pcm_s16le" | "pcm_mulaw";
|
|
28
|
+
export type AudioEncoding = "pcm_s16le" | "pcm_mulaw" | "opus" | "ogg_opus";
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Configure the threshold for how long to wait before ending an utterance. Default is 700ms.
|
|
@@ -92,7 +92,12 @@ export type StreamingTranscriberParams = {
|
|
|
92
92
|
* Milliseconds to wait between connection attempts. Defaults to 500.
|
|
93
93
|
*/
|
|
94
94
|
connectionRetryDelay?: number;
|
|
95
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Required for PCM encodings (and for dual-channel mode). May be omitted
|
|
97
|
+
* for Opus encodings (`opus`, `ogg_opus`) — the stream is self-describing
|
|
98
|
+
* and the server ignores the value.
|
|
99
|
+
*/
|
|
100
|
+
sampleRate?: number;
|
|
96
101
|
encoding?: AudioEncoding;
|
|
97
102
|
endOfTurnConfidenceThreshold?: number;
|
|
98
103
|
/**
|
|
@@ -109,7 +114,19 @@ export type StreamingTranscriberParams = {
|
|
|
109
114
|
prompt?: string;
|
|
110
115
|
agentContext?: string;
|
|
111
116
|
speechModel?: StreamingSpeechModel;
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated Use `languageCodes` instead (pass a single-element array, e.g. `["es"]`,
|
|
119
|
+
* for the same behavior). Still supported for backward compatibility.
|
|
120
|
+
*/
|
|
112
121
|
languageCode?: string;
|
|
122
|
+
/**
|
|
123
|
+
* Recommended way to select languages. Steers transcription toward a set of
|
|
124
|
+
* languages by biasing output toward them on a per-token basis while still
|
|
125
|
+
* allowing native code-switching among them. Pass the languages you expect
|
|
126
|
+
* (e.g. `["en", "es"]`), or a single-element array (e.g. `["es"]`) for a
|
|
127
|
+
* monolingual session. Universal-3.5 Pro Streaming only.
|
|
128
|
+
*/
|
|
129
|
+
languageCodes?: string[];
|
|
113
130
|
languageDetection?: boolean;
|
|
114
131
|
domain?: StreamingDomain;
|
|
115
132
|
inactivityTimeout?: number;
|
|
@@ -359,6 +376,12 @@ export type StreamingUpdateConfiguration = {
|
|
|
359
376
|
filter_profanity?: boolean;
|
|
360
377
|
interruption_delay?: number;
|
|
361
378
|
turn_left_pad_ms?: number;
|
|
379
|
+
/**
|
|
380
|
+
* Steer transcription toward a set of languages mid-stream. Pass an empty
|
|
381
|
+
* array (`[]`) to clear steering and restore the model's default
|
|
382
|
+
* multilingual code-switching. Universal-3.5 Pro Streaming only.
|
|
383
|
+
*/
|
|
384
|
+
language_codes?: string[];
|
|
362
385
|
};
|
|
363
386
|
|
|
364
387
|
export type StreamingForceEndpoint = {
|