assemblyai 4.29.0 → 4.32.1

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/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.29.0" },
18
+ sdk: { name: "JavaScript", version: "4.32.1" },
19
19
  };
20
20
  if (typeof process !== "undefined") {
21
21
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -220,8 +220,18 @@ const StreamingErrorType = {
220
220
  BadSchema: 4101,
221
221
  TooManyStreams: 4102,
222
222
  Reconnected: 4103,
223
+ ServerError: 3005,
224
+ InputValidationError: 3006,
225
+ AudioChunkDurationViolation: 3007,
226
+ MaxSessionDurationExceeded: 3008,
227
+ ConcurrencyLimitExceeded: 3009,
223
228
  };
224
229
  const StreamingErrorMessages = {
230
+ [StreamingErrorType.ServerError]: "Server error",
231
+ [StreamingErrorType.InputValidationError]: "Input validation error",
232
+ [StreamingErrorType.AudioChunkDurationViolation]: "Audio chunk duration violation",
233
+ [StreamingErrorType.MaxSessionDurationExceeded]: "Session expired: maximum session duration exceeded",
234
+ [StreamingErrorType.ConcurrencyLimitExceeded]: "Too many concurrent sessions",
225
235
  [StreamingErrorType.BadSampleRate]: "Sample rate must be a positive integer",
226
236
  [StreamingErrorType.AuthFailed]: "Not Authorized",
227
237
  [StreamingErrorType.InsufficientFunds]: "Insufficient funds",
@@ -804,12 +814,18 @@ class StreamingTranscriber {
804
814
  if (this.params.endOfTurnConfidenceThreshold) {
805
815
  searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
806
816
  }
807
- if (this.params.minTurnSilence) {
808
- searchParams.set("min_turn_silence", this.params.minTurnSilence.toString());
817
+ if (this.params.minEndOfTurnSilenceWhenConfident !== undefined) {
818
+ if (this.params.minTurnSilence !== undefined) {
819
+ console.warn("[Deprecation Warning] Both `minEndOfTurnSilenceWhenConfident` and `minTurnSilence` are set. Using `minTurnSilence`; `minEndOfTurnSilenceWhenConfident` is deprecated.");
820
+ }
821
+ else {
822
+ console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
823
+ }
809
824
  }
810
- else if (this.params.minEndOfTurnSilenceWhenConfident) {
811
- console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
812
- searchParams.set("min_end_of_turn_silence_when_confident", this.params.minEndOfTurnSilenceWhenConfident.toString());
825
+ const effectiveMinTurnSilence = this.params.minTurnSilence ??
826
+ this.params.minEndOfTurnSilenceWhenConfident;
827
+ if (effectiveMinTurnSilence !== undefined) {
828
+ searchParams.set("min_turn_silence", effectiveMinTurnSilence.toString());
813
829
  }
814
830
  if (this.params.maxTurnSilence) {
815
831
  searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
@@ -855,6 +871,12 @@ class StreamingTranscriber {
855
871
  if (this.params.maxSpeakers !== undefined) {
856
872
  searchParams.set("max_speakers", this.params.maxSpeakers.toString());
857
873
  }
874
+ if (this.params.noiseSuppressionModel) {
875
+ searchParams.set("noise_suppression_model", this.params.noiseSuppressionModel);
876
+ }
877
+ if (this.params.noiseSuppressionThreshold !== undefined) {
878
+ searchParams.set("noise_suppression_threshold", this.params.noiseSuppressionThreshold.toString());
879
+ }
858
880
  if (this.params.llmGateway !== undefined) {
859
881
  searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
860
882
  }
@@ -898,7 +920,12 @@ class StreamingTranscriber {
898
920
  this.socket.onmessage = ({ data }) => {
899
921
  const message = JSON.parse(data.toString());
900
922
  if ("error" in message) {
901
- this.listeners.error?.(new StreamingError(message.error));
923
+ const err = new StreamingError(message.error);
924
+ if ("error_code" in message) {
925
+ err.code =
926
+ message.error_code;
927
+ }
928
+ this.listeners.error?.(err);
902
929
  return;
903
930
  }
904
931
  switch (message.type) {
@@ -919,6 +946,12 @@ class StreamingTranscriber {
919
946
  this.listeners.llmGatewayResponse?.(message);
920
947
  break;
921
948
  }
949
+ case "Warning": {
950
+ const warning = message;
951
+ console.warn(`Streaming warning (code=${warning.warning_code}): ${warning.warning}`);
952
+ this.listeners.warning?.(warning);
953
+ break;
954
+ }
922
955
  case "Termination": {
923
956
  this.sessionTerminatedResolve?.();
924
957
  break;
@@ -942,9 +975,20 @@ class StreamingTranscriber {
942
975
  * @param config - The configuration parameters to update
943
976
  */
944
977
  updateConfiguration(config) {
978
+ const { min_end_of_turn_silence_when_confident, min_turn_silence, ...rest } = config;
979
+ if (min_end_of_turn_silence_when_confident !== undefined) {
980
+ if (min_turn_silence !== undefined) {
981
+ console.warn("[Deprecation Warning] Both `min_end_of_turn_silence_when_confident` and `min_turn_silence` are set. Using `min_turn_silence`; `min_end_of_turn_silence_when_confident` is deprecated.");
982
+ }
983
+ else {
984
+ console.warn("[Deprecation Warning] `min_end_of_turn_silence_when_confident` is deprecated and will be removed in a future release. Please use `min_turn_silence` instead.");
985
+ }
986
+ }
987
+ const effective = min_turn_silence ?? min_end_of_turn_silence_when_confident;
945
988
  const message = {
946
989
  type: "UpdateConfiguration",
947
- ...config,
990
+ ...rest,
991
+ ...(effective !== undefined ? { min_turn_silence: effective } : {}),
948
992
  };
949
993
  this.send(JSON.stringify(message));
950
994
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assemblyai",
3
- "version": "4.29.0",
3
+ "version": "4.32.1",
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"
@@ -16,6 +16,7 @@ import {
16
16
  LLMGatewayResponseEvent,
17
17
  StreamingUpdateConfiguration,
18
18
  StreamingForceEndpoint,
19
+ WarningEvent,
19
20
  } from "../..";
20
21
  import { StreamingError, StreamingErrorMessages } from "../../utils/errors";
21
22
  import { StreamingErrorTypeCodes } from "../../utils/errors/streaming";
@@ -86,19 +87,22 @@ export class StreamingTranscriber {
86
87
  );
87
88
  }
88
89
 
89
- if (this.params.minTurnSilence) {
90
- searchParams.set(
91
- "min_turn_silence",
92
- this.params.minTurnSilence.toString(),
93
- );
94
- } else if (this.params.minEndOfTurnSilenceWhenConfident) {
95
- console.warn(
96
- "[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.",
97
- );
98
- searchParams.set(
99
- "min_end_of_turn_silence_when_confident",
100
- this.params.minEndOfTurnSilenceWhenConfident.toString(),
101
- );
90
+ if (this.params.minEndOfTurnSilenceWhenConfident !== undefined) {
91
+ if (this.params.minTurnSilence !== undefined) {
92
+ console.warn(
93
+ "[Deprecation Warning] Both `minEndOfTurnSilenceWhenConfident` and `minTurnSilence` are set. Using `minTurnSilence`; `minEndOfTurnSilenceWhenConfident` is deprecated.",
94
+ );
95
+ } else {
96
+ console.warn(
97
+ "[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.",
98
+ );
99
+ }
100
+ }
101
+ const effectiveMinTurnSilence =
102
+ this.params.minTurnSilence ??
103
+ this.params.minEndOfTurnSilenceWhenConfident;
104
+ if (effectiveMinTurnSilence !== undefined) {
105
+ searchParams.set("min_turn_silence", effectiveMinTurnSilence.toString());
102
106
  }
103
107
 
104
108
  if (this.params.maxTurnSilence) {
@@ -176,6 +180,20 @@ export class StreamingTranscriber {
176
180
  searchParams.set("max_speakers", this.params.maxSpeakers.toString());
177
181
  }
178
182
 
183
+ if (this.params.noiseSuppressionModel) {
184
+ searchParams.set(
185
+ "noise_suppression_model",
186
+ this.params.noiseSuppressionModel,
187
+ );
188
+ }
189
+
190
+ if (this.params.noiseSuppressionThreshold !== undefined) {
191
+ searchParams.set(
192
+ "noise_suppression_threshold",
193
+ this.params.noiseSuppressionThreshold.toString(),
194
+ );
195
+ }
196
+
179
197
  if (this.params.llmGateway !== undefined) {
180
198
  searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
181
199
  }
@@ -191,6 +209,7 @@ export class StreamingTranscriber {
191
209
  event: "llmGatewayResponse",
192
210
  listener: (event: LLMGatewayResponseEvent) => void,
193
211
  ): void;
212
+ on(event: "warning", listener: (event: WarningEvent) => void): void;
194
213
  on(event: "error", listener: (error: Error) => void): void;
195
214
  on(event: "close", listener: (code: number, reason: string) => void): void;
196
215
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -243,7 +262,12 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
243
262
  const message = JSON.parse(data.toString()) as StreamingEventMessage;
244
263
 
245
264
  if ("error" in message) {
246
- this.listeners.error?.(new StreamingError(message.error));
265
+ const err = new StreamingError(message.error);
266
+ if ("error_code" in message) {
267
+ (err as StreamingError & { code?: number }).code =
268
+ message.error_code;
269
+ }
270
+ this.listeners.error?.(err);
247
271
  return;
248
272
  }
249
273
 
@@ -265,6 +289,14 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
265
289
  this.listeners.llmGatewayResponse?.(message);
266
290
  break;
267
291
  }
292
+ case "Warning": {
293
+ const warning = message as WarningEvent;
294
+ console.warn(
295
+ `Streaming warning (code=${warning.warning_code}): ${warning.warning}`,
296
+ );
297
+ this.listeners.warning?.(warning);
298
+ break;
299
+ }
268
300
  case "Termination": {
269
301
  this.sessionTerminatedResolve?.();
270
302
  break;
@@ -291,9 +323,28 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
291
323
  * @param config - The configuration parameters to update
292
324
  */
293
325
  updateConfiguration(config: Omit<StreamingUpdateConfiguration, "type">) {
326
+ const {
327
+ min_end_of_turn_silence_when_confident,
328
+ min_turn_silence,
329
+ ...rest
330
+ } = config;
331
+ if (min_end_of_turn_silence_when_confident !== undefined) {
332
+ if (min_turn_silence !== undefined) {
333
+ console.warn(
334
+ "[Deprecation Warning] Both `min_end_of_turn_silence_when_confident` and `min_turn_silence` are set. Using `min_turn_silence`; `min_end_of_turn_silence_when_confident` is deprecated.",
335
+ );
336
+ } else {
337
+ console.warn(
338
+ "[Deprecation Warning] `min_end_of_turn_silence_when_confident` is deprecated and will be removed in a future release. Please use `min_turn_silence` instead.",
339
+ );
340
+ }
341
+ }
342
+ const effective =
343
+ min_turn_silence ?? min_end_of_turn_silence_when_confident;
294
344
  const message: StreamingUpdateConfiguration = {
295
345
  type: "UpdateConfiguration",
296
- ...config,
346
+ ...rest,
347
+ ...(effective !== undefined ? { min_turn_silence: effective } : {}),
297
348
  };
298
349
  this.send(JSON.stringify(message));
299
350
  }
@@ -21,11 +21,18 @@ type OneOf<T extends any[]> = T extends [infer Only]
21
21
  */
22
22
  export type AudioIntelligenceModelStatus = "success" | "unavailable";
23
23
 
24
+ export interface TranscriptWarning {
25
+ /** The warning message. */
26
+ message: string;
27
+ }
28
+
24
29
  export interface TranscriptMetadata {
25
30
  /** The domain that was actually used for the transcription. */
26
31
  domain_used?: string | null;
27
32
  /** An optional warning message, if applicable. */
28
33
  warning?: string | null;
34
+ /** A list of warning objects, if applicable. */
35
+ warnings?: TranscriptWarning[] | null;
29
36
  }
30
37
 
31
38
  /**
@@ -2818,6 +2825,10 @@ export type Transcript = {
2818
2825
  * See {@link https://www.assemblyai.com/docs/models/pii-redaction | PII redaction } for more information.
2819
2826
  */
2820
2827
  redact_pii_policies?: PiiPolicy[] | null;
2828
+ /**
2829
+ * Whether the unredacted text, words, and utterances were also returned alongside the redacted fields. Only applies when `redact_pii` is enabled.
2830
+ */
2831
+ redact_pii_return_unredacted?: boolean | null;
2821
2832
  /**
2822
2833
  * The replacement logic for detected PII, can be "entity_type" or "hash". See {@link https://www.assemblyai.com/docs/models/pii-redaction | PII redaction } for more details.
2823
2834
  */
@@ -2910,6 +2921,18 @@ export type Transcript = {
2910
2921
  * The list of custom topics provided if custom topics is enabled
2911
2922
  */
2912
2923
  topics?: string[];
2924
+ /**
2925
+ * The unredacted transcript text. Returned only when `redact_pii_return_unredacted` was set with `redact_pii`.
2926
+ */
2927
+ unredacted_text?: string | null;
2928
+ /**
2929
+ * The unredacted list of utterances. Returned only when `redact_pii_return_unredacted` was set with `redact_pii` and channel/speaker modes are enabled.
2930
+ */
2931
+ unredacted_utterances?: TranscriptUtterance[] | null;
2932
+ /**
2933
+ * The unredacted list of individual words. Returned only when `redact_pii_return_unredacted` was set with `redact_pii`.
2934
+ */
2935
+ unredacted_words?: TranscriptWord[] | null;
2913
2936
  /**
2914
2937
  * When dual_channel or speaker_labels is enabled, a list of turn-by-turn utterance objects.
2915
2938
  * See {@link https://www.assemblyai.com/docs/models/speaker-diarization | Speaker diarization } for more information.
@@ -3389,6 +3412,11 @@ export type TranscriptOptionalParams = {
3389
3412
  * The list of PII Redaction policies to enable. See {@link https://www.assemblyai.com/docs/models/pii-redaction | PII redaction } for more details.
3390
3413
  */
3391
3414
  redact_pii_policies?: PiiPolicy[];
3415
+ /**
3416
+ * If `redact_pii` is enabled, also return the unredacted text, words, and utterances alongside the redacted fields.
3417
+ * @defaultValue false
3418
+ */
3419
+ redact_pii_return_unredacted?: boolean;
3392
3420
  /**
3393
3421
  * The replacement logic for detected PII, can be "entity_type" or "hash". See {@link https://www.assemblyai.com/docs/models/pii-redaction | PII redaction } for more details.
3394
3422
  * @defaultValue "hash"
@@ -36,6 +36,8 @@ export type StreamingTranscriberParams = {
36
36
  inactivityTimeout?: number;
37
37
  speakerLabels?: boolean;
38
38
  maxSpeakers?: number;
39
+ noiseSuppressionModel?: NoiseSuppressionModel;
40
+ noiseSuppressionThreshold?: number;
39
41
  llmGateway?: LLMGatewayConfig;
40
42
  };
41
43
 
@@ -45,6 +47,7 @@ export type StreamingEvents =
45
47
  | "turn"
46
48
  | "speechStarted"
47
49
  | "llmGatewayResponse"
50
+ | "warning"
48
51
  | "error";
49
52
 
50
53
  export type StreamingListeners = {
@@ -53,6 +56,7 @@ export type StreamingListeners = {
53
56
  turn?: (event: TurnEvent) => void;
54
57
  speechStarted?: (event: SpeechStartedEvent) => void;
55
58
  llmGatewayResponse?: (event: LLMGatewayResponseEvent) => void;
59
+ warning?: (event: WarningEvent) => void;
56
60
  error?: (error: Error) => void;
57
61
  };
58
62
 
@@ -65,6 +69,8 @@ export type StreamingSpeechModel =
65
69
 
66
70
  export type StreamingDomain = "medical-v1";
67
71
 
72
+ export type NoiseSuppressionModel = "near-field" | "far-field";
73
+
68
74
  export type StreamingTokenParams = {
69
75
  expires_in_seconds: number;
70
76
  max_session_duration_seconds?: number;
@@ -139,9 +145,17 @@ export type StreamingForceEndpoint = {
139
145
  };
140
146
 
141
147
  export type ErrorEvent = {
148
+ type: "Error";
149
+ error_code?: number;
142
150
  error: string;
143
151
  };
144
152
 
153
+ export type WarningEvent = {
154
+ type: "Warning";
155
+ warning_code: number;
156
+ warning: string;
157
+ };
158
+
145
159
  export type LLMGatewayResponseEvent = {
146
160
  type: "LLMGatewayResponse";
147
161
  turn_order: number;
@@ -155,7 +169,8 @@ export type StreamingEventMessage =
155
169
  | SpeechStartedEvent
156
170
  | TerminationEvent
157
171
  | LLMGatewayResponseEvent
158
- | ErrorEvent;
172
+ | ErrorEvent
173
+ | WarningEvent;
159
174
 
160
175
  export type StreamingOperationMessage =
161
176
  | StreamingUpdateConfiguration
@@ -15,12 +15,24 @@ const StreamingErrorType = {
15
15
  BadSchema: 4101,
16
16
  TooManyStreams: 4102,
17
17
  Reconnected: 4103,
18
+ ServerError: 3005,
19
+ InputValidationError: 3006,
20
+ AudioChunkDurationViolation: 3007,
21
+ MaxSessionDurationExceeded: 3008,
22
+ ConcurrencyLimitExceeded: 3009,
18
23
  } as const;
19
24
 
20
25
  type StreamingErrorTypeCodes =
21
26
  (typeof StreamingErrorType)[keyof typeof StreamingErrorType];
22
27
 
23
28
  const StreamingErrorMessages: Record<StreamingErrorTypeCodes, string> = {
29
+ [StreamingErrorType.ServerError]: "Server error",
30
+ [StreamingErrorType.InputValidationError]: "Input validation error",
31
+ [StreamingErrorType.AudioChunkDurationViolation]:
32
+ "Audio chunk duration violation",
33
+ [StreamingErrorType.MaxSessionDurationExceeded]:
34
+ "Session expired: maximum session duration exceeded",
35
+ [StreamingErrorType.ConcurrencyLimitExceeded]: "Too many concurrent sessions",
24
36
  [StreamingErrorType.BadSampleRate]: "Sample rate must be a positive integer",
25
37
  [StreamingErrorType.AuthFailed]: "Not Authorized",
26
38
  [StreamingErrorType.InsufficientFunds]: "Insufficient funds",