assemblyai 4.30.0 → 4.33.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 +9 -0
- package/dist/assemblyai.umd.js +81 -11
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/browser.mjs +80 -8
- package/dist/bun.mjs +80 -8
- package/dist/deno.mjs +80 -8
- package/dist/index.cjs +81 -11
- package/dist/index.mjs +81 -11
- package/dist/node.cjs +80 -8
- package/dist/node.mjs +80 -8
- package/dist/services/streaming/service.d.ts +2 -1
- package/dist/types/openapi.generated.d.ts +21 -0
- package/dist/types/streaming/index.d.ts +25 -2
- package/dist/utils/errors/streaming.d.ts +5 -0
- package/dist/workerd.mjs +80 -8
- package/package.json +1 -1
- package/src/services/streaming/service.ts +120 -15
- package/src/types/openapi.generated.ts +21 -0
- package/src/types/streaming/index.ts +77 -1
- package/src/utils/errors/streaming.ts +12 -0
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.33.0" },
|
|
24
24
|
};
|
|
25
25
|
if (typeof process !== "undefined") {
|
|
26
26
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -219,8 +219,18 @@ const StreamingErrorType = {
|
|
|
219
219
|
BadSchema: 4101,
|
|
220
220
|
TooManyStreams: 4102,
|
|
221
221
|
Reconnected: 4103,
|
|
222
|
+
ServerError: 3005,
|
|
223
|
+
InputValidationError: 3006,
|
|
224
|
+
AudioChunkDurationViolation: 3007,
|
|
225
|
+
MaxSessionDurationExceeded: 3008,
|
|
226
|
+
ConcurrencyLimitExceeded: 3009,
|
|
222
227
|
};
|
|
223
228
|
const StreamingErrorMessages = {
|
|
229
|
+
[StreamingErrorType.ServerError]: "Server error",
|
|
230
|
+
[StreamingErrorType.InputValidationError]: "Input validation error",
|
|
231
|
+
[StreamingErrorType.AudioChunkDurationViolation]: "Audio chunk duration violation",
|
|
232
|
+
[StreamingErrorType.MaxSessionDurationExceeded]: "Session expired: maximum session duration exceeded",
|
|
233
|
+
[StreamingErrorType.ConcurrencyLimitExceeded]: "Too many concurrent sessions",
|
|
224
234
|
[StreamingErrorType.BadSampleRate]: "Sample rate must be a positive integer",
|
|
225
235
|
[StreamingErrorType.AuthFailed]: "Not Authorized",
|
|
226
236
|
[StreamingErrorType.InsufficientFunds]: "Insufficient funds",
|
|
@@ -799,12 +809,18 @@ class StreamingTranscriber {
|
|
|
799
809
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
800
810
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
801
811
|
}
|
|
802
|
-
if (this.params.
|
|
803
|
-
|
|
812
|
+
if (this.params.minEndOfTurnSilenceWhenConfident !== undefined) {
|
|
813
|
+
if (this.params.minTurnSilence !== undefined) {
|
|
814
|
+
console.warn("[Deprecation Warning] Both `minEndOfTurnSilenceWhenConfident` and `minTurnSilence` are set. Using `minTurnSilence`; `minEndOfTurnSilenceWhenConfident` is deprecated.");
|
|
815
|
+
}
|
|
816
|
+
else {
|
|
817
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
818
|
+
}
|
|
804
819
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
820
|
+
const effectiveMinTurnSilence = this.params.minTurnSilence ??
|
|
821
|
+
this.params.minEndOfTurnSilenceWhenConfident;
|
|
822
|
+
if (effectiveMinTurnSilence !== undefined) {
|
|
823
|
+
searchParams.set("min_turn_silence", effectiveMinTurnSilence.toString());
|
|
808
824
|
}
|
|
809
825
|
if (this.params.maxTurnSilence) {
|
|
810
826
|
searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
|
|
@@ -850,6 +866,40 @@ class StreamingTranscriber {
|
|
|
850
866
|
if (this.params.maxSpeakers !== undefined) {
|
|
851
867
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
852
868
|
}
|
|
869
|
+
if (this.params.voiceFocus) {
|
|
870
|
+
searchParams.set("voice_focus", this.params.voiceFocus);
|
|
871
|
+
}
|
|
872
|
+
if (this.params.voiceFocusThreshold !== undefined) {
|
|
873
|
+
searchParams.set("voice_focus_threshold", this.params.voiceFocusThreshold.toString());
|
|
874
|
+
}
|
|
875
|
+
if (this.params.continuousPartials !== undefined) {
|
|
876
|
+
searchParams.set("continuous_partials", this.params.continuousPartials.toString());
|
|
877
|
+
}
|
|
878
|
+
if (this.params.customerSupportAudioCapture) {
|
|
879
|
+
console.warn("`customerSupportAudioCapture=true` will record session audio. Only enable this when explicitly coordinating with AssemblyAI support.");
|
|
880
|
+
searchParams.set("customer_support_audio_capture", this.params.customerSupportAudioCapture.toString());
|
|
881
|
+
}
|
|
882
|
+
if (this.params.webhookUrl) {
|
|
883
|
+
searchParams.set("webhook_url", this.params.webhookUrl);
|
|
884
|
+
}
|
|
885
|
+
if (this.params.webhookAuthHeaderName) {
|
|
886
|
+
searchParams.set("webhook_auth_header_name", this.params.webhookAuthHeaderName);
|
|
887
|
+
}
|
|
888
|
+
if (this.params.webhookAuthHeaderValue) {
|
|
889
|
+
searchParams.set("webhook_auth_header_value", this.params.webhookAuthHeaderValue);
|
|
890
|
+
}
|
|
891
|
+
if (this.params.includePartialTurns !== undefined) {
|
|
892
|
+
searchParams.set("include_partial_turns", this.params.includePartialTurns.toString());
|
|
893
|
+
}
|
|
894
|
+
if (this.params.redactPii !== undefined) {
|
|
895
|
+
searchParams.set("redact_pii", this.params.redactPii.toString());
|
|
896
|
+
}
|
|
897
|
+
if (this.params.redactPiiPolicies !== undefined) {
|
|
898
|
+
searchParams.set("redact_pii_policies", JSON.stringify(this.params.redactPiiPolicies));
|
|
899
|
+
}
|
|
900
|
+
if (this.params.redactPiiSub !== undefined) {
|
|
901
|
+
searchParams.set("redact_pii_sub", this.params.redactPiiSub);
|
|
902
|
+
}
|
|
853
903
|
if (this.params.llmGateway !== undefined) {
|
|
854
904
|
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
855
905
|
}
|
|
@@ -893,7 +943,12 @@ class StreamingTranscriber {
|
|
|
893
943
|
this.socket.onmessage = ({ data }) => {
|
|
894
944
|
const message = JSON.parse(data.toString());
|
|
895
945
|
if ("error" in message) {
|
|
896
|
-
|
|
946
|
+
const err = new StreamingError(message.error);
|
|
947
|
+
if ("error_code" in message) {
|
|
948
|
+
err.code =
|
|
949
|
+
message.error_code;
|
|
950
|
+
}
|
|
951
|
+
this.listeners.error?.(err);
|
|
897
952
|
return;
|
|
898
953
|
}
|
|
899
954
|
switch (message.type) {
|
|
@@ -914,6 +969,12 @@ class StreamingTranscriber {
|
|
|
914
969
|
this.listeners.llmGatewayResponse?.(message);
|
|
915
970
|
break;
|
|
916
971
|
}
|
|
972
|
+
case "Warning": {
|
|
973
|
+
const warning = message;
|
|
974
|
+
console.warn(`Streaming warning (code=${warning.warning_code}): ${warning.warning}`);
|
|
975
|
+
this.listeners.warning?.(warning);
|
|
976
|
+
break;
|
|
977
|
+
}
|
|
917
978
|
case "Termination": {
|
|
918
979
|
this.sessionTerminatedResolve?.();
|
|
919
980
|
break;
|
|
@@ -937,9 +998,20 @@ class StreamingTranscriber {
|
|
|
937
998
|
* @param config - The configuration parameters to update
|
|
938
999
|
*/
|
|
939
1000
|
updateConfiguration(config) {
|
|
1001
|
+
const { min_end_of_turn_silence_when_confident, min_turn_silence, ...rest } = config;
|
|
1002
|
+
if (min_end_of_turn_silence_when_confident !== undefined) {
|
|
1003
|
+
if (min_turn_silence !== undefined) {
|
|
1004
|
+
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.");
|
|
1005
|
+
}
|
|
1006
|
+
else {
|
|
1007
|
+
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.");
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
const effective = min_turn_silence ?? min_end_of_turn_silence_when_confident;
|
|
940
1011
|
const message = {
|
|
941
1012
|
type: "UpdateConfiguration",
|
|
942
|
-
...
|
|
1013
|
+
...rest,
|
|
1014
|
+
...(effective !== undefined ? { min_turn_silence: effective } : {}),
|
|
943
1015
|
};
|
|
944
1016
|
this.send(JSON.stringify(message));
|
|
945
1017
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StreamingTranscriberParams, AudioData, BeginEvent, TurnEvent, LLMGatewayResponseEvent, StreamingUpdateConfiguration } from "../..";
|
|
1
|
+
import { StreamingTranscriberParams, AudioData, BeginEvent, TurnEvent, LLMGatewayResponseEvent, StreamingUpdateConfiguration, WarningEvent } from "../..";
|
|
2
2
|
export declare class StreamingTranscriber {
|
|
3
3
|
private apiKey?;
|
|
4
4
|
private token?;
|
|
@@ -11,6 +11,7 @@ export declare class StreamingTranscriber {
|
|
|
11
11
|
on(event: "open", listener: (event: BeginEvent) => void): void;
|
|
12
12
|
on(event: "turn", listener: (event: TurnEvent) => void): void;
|
|
13
13
|
on(event: "llmGatewayResponse", listener: (event: LLMGatewayResponseEvent) => void): void;
|
|
14
|
+
on(event: "warning", listener: (event: WarningEvent) => void): void;
|
|
14
15
|
on(event: "error", listener: (error: Error) => void): void;
|
|
15
16
|
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
16
17
|
connect(): Promise<BeginEvent>;
|
|
@@ -2634,6 +2634,10 @@ export type Transcript = {
|
|
|
2634
2634
|
* See {@link https://www.assemblyai.com/docs/models/pii-redaction | PII redaction } for more information.
|
|
2635
2635
|
*/
|
|
2636
2636
|
redact_pii_policies?: PiiPolicy[] | null;
|
|
2637
|
+
/**
|
|
2638
|
+
* Whether the unredacted text, words, and utterances were also returned alongside the redacted fields. Only applies when `redact_pii` is enabled.
|
|
2639
|
+
*/
|
|
2640
|
+
redact_pii_return_unredacted?: boolean | null;
|
|
2637
2641
|
/**
|
|
2638
2642
|
* 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.
|
|
2639
2643
|
*/
|
|
@@ -2723,6 +2727,18 @@ export type Transcript = {
|
|
|
2723
2727
|
* The list of custom topics provided if custom topics is enabled
|
|
2724
2728
|
*/
|
|
2725
2729
|
topics?: string[];
|
|
2730
|
+
/**
|
|
2731
|
+
* The unredacted transcript text. Returned only when `redact_pii_return_unredacted` was set with `redact_pii`.
|
|
2732
|
+
*/
|
|
2733
|
+
unredacted_text?: string | null;
|
|
2734
|
+
/**
|
|
2735
|
+
* The unredacted list of utterances. Returned only when `redact_pii_return_unredacted` was set with `redact_pii` and channel/speaker modes are enabled.
|
|
2736
|
+
*/
|
|
2737
|
+
unredacted_utterances?: TranscriptUtterance[] | null;
|
|
2738
|
+
/**
|
|
2739
|
+
* The unredacted list of individual words. Returned only when `redact_pii_return_unredacted` was set with `redact_pii`.
|
|
2740
|
+
*/
|
|
2741
|
+
unredacted_words?: TranscriptWord[] | null;
|
|
2726
2742
|
/**
|
|
2727
2743
|
* When dual_channel or speaker_labels is enabled, a list of turn-by-turn utterance objects.
|
|
2728
2744
|
* See {@link https://www.assemblyai.com/docs/models/speaker-diarization | Speaker diarization } for more information.
|
|
@@ -3093,6 +3109,11 @@ export type TranscriptOptionalParams = {
|
|
|
3093
3109
|
* The list of PII Redaction policies to enable. See {@link https://www.assemblyai.com/docs/models/pii-redaction | PII redaction } for more details.
|
|
3094
3110
|
*/
|
|
3095
3111
|
redact_pii_policies?: PiiPolicy[];
|
|
3112
|
+
/**
|
|
3113
|
+
* If `redact_pii` is enabled, also return the unredacted text, words, and utterances alongside the redacted fields.
|
|
3114
|
+
* @defaultValue false
|
|
3115
|
+
*/
|
|
3116
|
+
redact_pii_return_unredacted?: boolean;
|
|
3096
3117
|
/**
|
|
3097
3118
|
* 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.
|
|
3098
3119
|
* @defaultValue "hash"
|
|
@@ -33,19 +33,34 @@ export type StreamingTranscriberParams = {
|
|
|
33
33
|
inactivityTimeout?: number;
|
|
34
34
|
speakerLabels?: boolean;
|
|
35
35
|
maxSpeakers?: number;
|
|
36
|
+
voiceFocus?: VoiceFocusModel;
|
|
37
|
+
voiceFocusThreshold?: number;
|
|
38
|
+
continuousPartials?: boolean;
|
|
39
|
+
customerSupportAudioCapture?: boolean;
|
|
40
|
+
includePartialTurns?: boolean;
|
|
41
|
+
redactPii?: boolean;
|
|
42
|
+
redactPiiPolicies?: StreamingPiiPolicy[];
|
|
43
|
+
redactPiiSub?: StreamingPiiSubstitution;
|
|
36
44
|
llmGateway?: LLMGatewayConfig;
|
|
45
|
+
webhookUrl?: string;
|
|
46
|
+
webhookAuthHeaderName?: string;
|
|
47
|
+
webhookAuthHeaderValue?: string;
|
|
37
48
|
};
|
|
38
|
-
export type StreamingEvents = "open" | "close" | "turn" | "speechStarted" | "llmGatewayResponse" | "error";
|
|
49
|
+
export type StreamingEvents = "open" | "close" | "turn" | "speechStarted" | "llmGatewayResponse" | "warning" | "error";
|
|
39
50
|
export type StreamingListeners = {
|
|
40
51
|
open?: (event: BeginEvent) => void;
|
|
41
52
|
close?: (code: number, reason: string) => void;
|
|
42
53
|
turn?: (event: TurnEvent) => void;
|
|
43
54
|
speechStarted?: (event: SpeechStartedEvent) => void;
|
|
44
55
|
llmGatewayResponse?: (event: LLMGatewayResponseEvent) => void;
|
|
56
|
+
warning?: (event: WarningEvent) => void;
|
|
45
57
|
error?: (error: Error) => void;
|
|
46
58
|
};
|
|
47
59
|
export type StreamingSpeechModel = "universal-streaming-english" | "universal-streaming-multilingual" | "u3-rt-pro" | "whisper-rt" | "u3-pro";
|
|
48
60
|
export type StreamingDomain = "medical-v1";
|
|
61
|
+
export type VoiceFocusModel = "near-field" | "far-field";
|
|
62
|
+
export type StreamingPiiSubstitution = "hash" | "entity_name";
|
|
63
|
+
export type StreamingPiiPolicy = "account_number" | "banking_information" | "blood_type" | "credit_card_number" | "credit_card_expiration" | "credit_card_cvv" | "date" | "date_interval" | "date_of_birth" | "drivers_license" | "drug" | "duration" | "email_address" | "event" | "filename" | "gender_sexuality" | "gender" | "healthcare_number" | "injury" | "ip_address" | "language" | "location" | "marital_status" | "medical_condition" | "medical_process" | "money_amount" | "nationality" | "number_sequence" | "passport_number" | "password" | "person_age" | "person_name" | "phone_number" | "physical_attribute" | "political_affiliation" | "occupation" | "organization" | "organization_medical_facility" | "religion" | "sexuality" | "statistics" | "time" | "url" | "us_social_security_number" | "username" | "vehicle_id" | "zodiac_sign";
|
|
49
64
|
export type StreamingTokenParams = {
|
|
50
65
|
expires_in_seconds: number;
|
|
51
66
|
max_session_duration_seconds?: number;
|
|
@@ -81,6 +96,7 @@ export type StreamingWord = {
|
|
|
81
96
|
confidence: number;
|
|
82
97
|
text: string;
|
|
83
98
|
word_is_final: boolean;
|
|
99
|
+
speaker?: string;
|
|
84
100
|
};
|
|
85
101
|
export type TerminationEvent = {
|
|
86
102
|
type: "Termination";
|
|
@@ -109,13 +125,20 @@ export type StreamingForceEndpoint = {
|
|
|
109
125
|
type: "ForceEndpoint";
|
|
110
126
|
};
|
|
111
127
|
export type ErrorEvent = {
|
|
128
|
+
type: "Error";
|
|
129
|
+
error_code?: number;
|
|
112
130
|
error: string;
|
|
113
131
|
};
|
|
132
|
+
export type WarningEvent = {
|
|
133
|
+
type: "Warning";
|
|
134
|
+
warning_code: number;
|
|
135
|
+
warning: string;
|
|
136
|
+
};
|
|
114
137
|
export type LLMGatewayResponseEvent = {
|
|
115
138
|
type: "LLMGatewayResponse";
|
|
116
139
|
turn_order: number;
|
|
117
140
|
transcript: string;
|
|
118
141
|
data: unknown;
|
|
119
142
|
};
|
|
120
|
-
export type StreamingEventMessage = BeginEvent | TurnEvent | SpeechStartedEvent | TerminationEvent | LLMGatewayResponseEvent | ErrorEvent;
|
|
143
|
+
export type StreamingEventMessage = BeginEvent | TurnEvent | SpeechStartedEvent | TerminationEvent | LLMGatewayResponseEvent | ErrorEvent | WarningEvent;
|
|
121
144
|
export type StreamingOperationMessage = StreamingUpdateConfiguration | StreamingForceEndpoint | StreamingTerminateSession;
|
|
@@ -15,6 +15,11 @@ declare const StreamingErrorType: {
|
|
|
15
15
|
readonly BadSchema: 4101;
|
|
16
16
|
readonly TooManyStreams: 4102;
|
|
17
17
|
readonly Reconnected: 4103;
|
|
18
|
+
readonly ServerError: 3005;
|
|
19
|
+
readonly InputValidationError: 3006;
|
|
20
|
+
readonly AudioChunkDurationViolation: 3007;
|
|
21
|
+
readonly MaxSessionDurationExceeded: 3008;
|
|
22
|
+
readonly ConcurrencyLimitExceeded: 3009;
|
|
18
23
|
};
|
|
19
24
|
type StreamingErrorTypeCodes = (typeof StreamingErrorType)[keyof typeof StreamingErrorType];
|
|
20
25
|
declare const StreamingErrorMessages: Record<StreamingErrorTypeCodes, string>;
|
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.33.0" },
|
|
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.
|
|
808
|
-
|
|
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
|
-
|
|
811
|
-
|
|
812
|
-
|
|
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,40 @@ 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.voiceFocus) {
|
|
875
|
+
searchParams.set("voice_focus", this.params.voiceFocus);
|
|
876
|
+
}
|
|
877
|
+
if (this.params.voiceFocusThreshold !== undefined) {
|
|
878
|
+
searchParams.set("voice_focus_threshold", this.params.voiceFocusThreshold.toString());
|
|
879
|
+
}
|
|
880
|
+
if (this.params.continuousPartials !== undefined) {
|
|
881
|
+
searchParams.set("continuous_partials", this.params.continuousPartials.toString());
|
|
882
|
+
}
|
|
883
|
+
if (this.params.customerSupportAudioCapture) {
|
|
884
|
+
console.warn("`customerSupportAudioCapture=true` will record session audio. Only enable this when explicitly coordinating with AssemblyAI support.");
|
|
885
|
+
searchParams.set("customer_support_audio_capture", this.params.customerSupportAudioCapture.toString());
|
|
886
|
+
}
|
|
887
|
+
if (this.params.webhookUrl) {
|
|
888
|
+
searchParams.set("webhook_url", this.params.webhookUrl);
|
|
889
|
+
}
|
|
890
|
+
if (this.params.webhookAuthHeaderName) {
|
|
891
|
+
searchParams.set("webhook_auth_header_name", this.params.webhookAuthHeaderName);
|
|
892
|
+
}
|
|
893
|
+
if (this.params.webhookAuthHeaderValue) {
|
|
894
|
+
searchParams.set("webhook_auth_header_value", this.params.webhookAuthHeaderValue);
|
|
895
|
+
}
|
|
896
|
+
if (this.params.includePartialTurns !== undefined) {
|
|
897
|
+
searchParams.set("include_partial_turns", this.params.includePartialTurns.toString());
|
|
898
|
+
}
|
|
899
|
+
if (this.params.redactPii !== undefined) {
|
|
900
|
+
searchParams.set("redact_pii", this.params.redactPii.toString());
|
|
901
|
+
}
|
|
902
|
+
if (this.params.redactPiiPolicies !== undefined) {
|
|
903
|
+
searchParams.set("redact_pii_policies", JSON.stringify(this.params.redactPiiPolicies));
|
|
904
|
+
}
|
|
905
|
+
if (this.params.redactPiiSub !== undefined) {
|
|
906
|
+
searchParams.set("redact_pii_sub", this.params.redactPiiSub);
|
|
907
|
+
}
|
|
858
908
|
if (this.params.llmGateway !== undefined) {
|
|
859
909
|
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
860
910
|
}
|
|
@@ -898,7 +948,12 @@ class StreamingTranscriber {
|
|
|
898
948
|
this.socket.onmessage = ({ data }) => {
|
|
899
949
|
const message = JSON.parse(data.toString());
|
|
900
950
|
if ("error" in message) {
|
|
901
|
-
|
|
951
|
+
const err = new StreamingError(message.error);
|
|
952
|
+
if ("error_code" in message) {
|
|
953
|
+
err.code =
|
|
954
|
+
message.error_code;
|
|
955
|
+
}
|
|
956
|
+
this.listeners.error?.(err);
|
|
902
957
|
return;
|
|
903
958
|
}
|
|
904
959
|
switch (message.type) {
|
|
@@ -919,6 +974,12 @@ class StreamingTranscriber {
|
|
|
919
974
|
this.listeners.llmGatewayResponse?.(message);
|
|
920
975
|
break;
|
|
921
976
|
}
|
|
977
|
+
case "Warning": {
|
|
978
|
+
const warning = message;
|
|
979
|
+
console.warn(`Streaming warning (code=${warning.warning_code}): ${warning.warning}`);
|
|
980
|
+
this.listeners.warning?.(warning);
|
|
981
|
+
break;
|
|
982
|
+
}
|
|
922
983
|
case "Termination": {
|
|
923
984
|
this.sessionTerminatedResolve?.();
|
|
924
985
|
break;
|
|
@@ -942,9 +1003,20 @@ class StreamingTranscriber {
|
|
|
942
1003
|
* @param config - The configuration parameters to update
|
|
943
1004
|
*/
|
|
944
1005
|
updateConfiguration(config) {
|
|
1006
|
+
const { min_end_of_turn_silence_when_confident, min_turn_silence, ...rest } = config;
|
|
1007
|
+
if (min_end_of_turn_silence_when_confident !== undefined) {
|
|
1008
|
+
if (min_turn_silence !== undefined) {
|
|
1009
|
+
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.");
|
|
1010
|
+
}
|
|
1011
|
+
else {
|
|
1012
|
+
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.");
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
const effective = min_turn_silence ?? min_end_of_turn_silence_when_confident;
|
|
945
1016
|
const message = {
|
|
946
1017
|
type: "UpdateConfiguration",
|
|
947
|
-
...
|
|
1018
|
+
...rest,
|
|
1019
|
+
...(effective !== undefined ? { min_turn_silence: effective } : {}),
|
|
948
1020
|
};
|
|
949
1021
|
this.send(JSON.stringify(message));
|
|
950
1022
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblyai",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.33.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"
|
|
@@ -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.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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,74 @@ export class StreamingTranscriber {
|
|
|
176
180
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
177
181
|
}
|
|
178
182
|
|
|
183
|
+
if (this.params.voiceFocus) {
|
|
184
|
+
searchParams.set("voice_focus", this.params.voiceFocus);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (this.params.voiceFocusThreshold !== undefined) {
|
|
188
|
+
searchParams.set(
|
|
189
|
+
"voice_focus_threshold",
|
|
190
|
+
this.params.voiceFocusThreshold.toString(),
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (this.params.continuousPartials !== undefined) {
|
|
195
|
+
searchParams.set(
|
|
196
|
+
"continuous_partials",
|
|
197
|
+
this.params.continuousPartials.toString(),
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (this.params.customerSupportAudioCapture) {
|
|
202
|
+
console.warn(
|
|
203
|
+
"`customerSupportAudioCapture=true` will record session audio. Only enable this when explicitly coordinating with AssemblyAI support.",
|
|
204
|
+
);
|
|
205
|
+
searchParams.set(
|
|
206
|
+
"customer_support_audio_capture",
|
|
207
|
+
this.params.customerSupportAudioCapture.toString(),
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (this.params.webhookUrl) {
|
|
212
|
+
searchParams.set("webhook_url", this.params.webhookUrl);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (this.params.webhookAuthHeaderName) {
|
|
216
|
+
searchParams.set(
|
|
217
|
+
"webhook_auth_header_name",
|
|
218
|
+
this.params.webhookAuthHeaderName,
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (this.params.webhookAuthHeaderValue) {
|
|
223
|
+
searchParams.set(
|
|
224
|
+
"webhook_auth_header_value",
|
|
225
|
+
this.params.webhookAuthHeaderValue,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (this.params.includePartialTurns !== undefined) {
|
|
230
|
+
searchParams.set(
|
|
231
|
+
"include_partial_turns",
|
|
232
|
+
this.params.includePartialTurns.toString(),
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (this.params.redactPii !== undefined) {
|
|
237
|
+
searchParams.set("redact_pii", this.params.redactPii.toString());
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (this.params.redactPiiPolicies !== undefined) {
|
|
241
|
+
searchParams.set(
|
|
242
|
+
"redact_pii_policies",
|
|
243
|
+
JSON.stringify(this.params.redactPiiPolicies),
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (this.params.redactPiiSub !== undefined) {
|
|
248
|
+
searchParams.set("redact_pii_sub", this.params.redactPiiSub);
|
|
249
|
+
}
|
|
250
|
+
|
|
179
251
|
if (this.params.llmGateway !== undefined) {
|
|
180
252
|
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
181
253
|
}
|
|
@@ -191,6 +263,7 @@ export class StreamingTranscriber {
|
|
|
191
263
|
event: "llmGatewayResponse",
|
|
192
264
|
listener: (event: LLMGatewayResponseEvent) => void,
|
|
193
265
|
): void;
|
|
266
|
+
on(event: "warning", listener: (event: WarningEvent) => void): void;
|
|
194
267
|
on(event: "error", listener: (error: Error) => void): void;
|
|
195
268
|
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
196
269
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -243,7 +316,12 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
243
316
|
const message = JSON.parse(data.toString()) as StreamingEventMessage;
|
|
244
317
|
|
|
245
318
|
if ("error" in message) {
|
|
246
|
-
|
|
319
|
+
const err = new StreamingError(message.error);
|
|
320
|
+
if ("error_code" in message) {
|
|
321
|
+
(err as StreamingError & { code?: number }).code =
|
|
322
|
+
message.error_code;
|
|
323
|
+
}
|
|
324
|
+
this.listeners.error?.(err);
|
|
247
325
|
return;
|
|
248
326
|
}
|
|
249
327
|
|
|
@@ -265,6 +343,14 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
265
343
|
this.listeners.llmGatewayResponse?.(message);
|
|
266
344
|
break;
|
|
267
345
|
}
|
|
346
|
+
case "Warning": {
|
|
347
|
+
const warning = message as WarningEvent;
|
|
348
|
+
console.warn(
|
|
349
|
+
`Streaming warning (code=${warning.warning_code}): ${warning.warning}`,
|
|
350
|
+
);
|
|
351
|
+
this.listeners.warning?.(warning);
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
268
354
|
case "Termination": {
|
|
269
355
|
this.sessionTerminatedResolve?.();
|
|
270
356
|
break;
|
|
@@ -291,9 +377,28 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
291
377
|
* @param config - The configuration parameters to update
|
|
292
378
|
*/
|
|
293
379
|
updateConfiguration(config: Omit<StreamingUpdateConfiguration, "type">) {
|
|
380
|
+
const {
|
|
381
|
+
min_end_of_turn_silence_when_confident,
|
|
382
|
+
min_turn_silence,
|
|
383
|
+
...rest
|
|
384
|
+
} = config;
|
|
385
|
+
if (min_end_of_turn_silence_when_confident !== undefined) {
|
|
386
|
+
if (min_turn_silence !== undefined) {
|
|
387
|
+
console.warn(
|
|
388
|
+
"[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.",
|
|
389
|
+
);
|
|
390
|
+
} else {
|
|
391
|
+
console.warn(
|
|
392
|
+
"[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.",
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
const effective =
|
|
397
|
+
min_turn_silence ?? min_end_of_turn_silence_when_confident;
|
|
294
398
|
const message: StreamingUpdateConfiguration = {
|
|
295
399
|
type: "UpdateConfiguration",
|
|
296
|
-
...
|
|
400
|
+
...rest,
|
|
401
|
+
...(effective !== undefined ? { min_turn_silence: effective } : {}),
|
|
297
402
|
};
|
|
298
403
|
this.send(JSON.stringify(message));
|
|
299
404
|
}
|
|
@@ -2825,6 +2825,10 @@ export type Transcript = {
|
|
|
2825
2825
|
* See {@link https://www.assemblyai.com/docs/models/pii-redaction | PII redaction } for more information.
|
|
2826
2826
|
*/
|
|
2827
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;
|
|
2828
2832
|
/**
|
|
2829
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.
|
|
2830
2834
|
*/
|
|
@@ -2917,6 +2921,18 @@ export type Transcript = {
|
|
|
2917
2921
|
* The list of custom topics provided if custom topics is enabled
|
|
2918
2922
|
*/
|
|
2919
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;
|
|
2920
2936
|
/**
|
|
2921
2937
|
* When dual_channel or speaker_labels is enabled, a list of turn-by-turn utterance objects.
|
|
2922
2938
|
* See {@link https://www.assemblyai.com/docs/models/speaker-diarization | Speaker diarization } for more information.
|
|
@@ -3396,6 +3412,11 @@ export type TranscriptOptionalParams = {
|
|
|
3396
3412
|
* The list of PII Redaction policies to enable. See {@link https://www.assemblyai.com/docs/models/pii-redaction | PII redaction } for more details.
|
|
3397
3413
|
*/
|
|
3398
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;
|
|
3399
3420
|
/**
|
|
3400
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.
|
|
3401
3422
|
* @defaultValue "hash"
|