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/deno.mjs
CHANGED
|
@@ -17,7 +17,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
17
17
|
defaultUserAgentString += navigator.userAgent;
|
|
18
18
|
}
|
|
19
19
|
const defaultUserAgent = {
|
|
20
|
-
sdk: { name: "JavaScript", version: "4.
|
|
20
|
+
sdk: { name: "JavaScript", version: "4.33.0" },
|
|
21
21
|
};
|
|
22
22
|
if (typeof process !== "undefined") {
|
|
23
23
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -222,8 +222,18 @@ const StreamingErrorType = {
|
|
|
222
222
|
BadSchema: 4101,
|
|
223
223
|
TooManyStreams: 4102,
|
|
224
224
|
Reconnected: 4103,
|
|
225
|
+
ServerError: 3005,
|
|
226
|
+
InputValidationError: 3006,
|
|
227
|
+
AudioChunkDurationViolation: 3007,
|
|
228
|
+
MaxSessionDurationExceeded: 3008,
|
|
229
|
+
ConcurrencyLimitExceeded: 3009,
|
|
225
230
|
};
|
|
226
231
|
const StreamingErrorMessages = {
|
|
232
|
+
[StreamingErrorType.ServerError]: "Server error",
|
|
233
|
+
[StreamingErrorType.InputValidationError]: "Input validation error",
|
|
234
|
+
[StreamingErrorType.AudioChunkDurationViolation]: "Audio chunk duration violation",
|
|
235
|
+
[StreamingErrorType.MaxSessionDurationExceeded]: "Session expired: maximum session duration exceeded",
|
|
236
|
+
[StreamingErrorType.ConcurrencyLimitExceeded]: "Too many concurrent sessions",
|
|
227
237
|
[StreamingErrorType.BadSampleRate]: "Sample rate must be a positive integer",
|
|
228
238
|
[StreamingErrorType.AuthFailed]: "Not Authorized",
|
|
229
239
|
[StreamingErrorType.InsufficientFunds]: "Insufficient funds",
|
|
@@ -802,12 +812,18 @@ class StreamingTranscriber {
|
|
|
802
812
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
803
813
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
804
814
|
}
|
|
805
|
-
if (this.params.
|
|
806
|
-
|
|
815
|
+
if (this.params.minEndOfTurnSilenceWhenConfident !== undefined) {
|
|
816
|
+
if (this.params.minTurnSilence !== undefined) {
|
|
817
|
+
console.warn("[Deprecation Warning] Both `minEndOfTurnSilenceWhenConfident` and `minTurnSilence` are set. Using `minTurnSilence`; `minEndOfTurnSilenceWhenConfident` is deprecated.");
|
|
818
|
+
}
|
|
819
|
+
else {
|
|
820
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
821
|
+
}
|
|
807
822
|
}
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
823
|
+
const effectiveMinTurnSilence = this.params.minTurnSilence ??
|
|
824
|
+
this.params.minEndOfTurnSilenceWhenConfident;
|
|
825
|
+
if (effectiveMinTurnSilence !== undefined) {
|
|
826
|
+
searchParams.set("min_turn_silence", effectiveMinTurnSilence.toString());
|
|
811
827
|
}
|
|
812
828
|
if (this.params.maxTurnSilence) {
|
|
813
829
|
searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
|
|
@@ -853,6 +869,40 @@ class StreamingTranscriber {
|
|
|
853
869
|
if (this.params.maxSpeakers !== undefined) {
|
|
854
870
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
855
871
|
}
|
|
872
|
+
if (this.params.voiceFocus) {
|
|
873
|
+
searchParams.set("voice_focus", this.params.voiceFocus);
|
|
874
|
+
}
|
|
875
|
+
if (this.params.voiceFocusThreshold !== undefined) {
|
|
876
|
+
searchParams.set("voice_focus_threshold", this.params.voiceFocusThreshold.toString());
|
|
877
|
+
}
|
|
878
|
+
if (this.params.continuousPartials !== undefined) {
|
|
879
|
+
searchParams.set("continuous_partials", this.params.continuousPartials.toString());
|
|
880
|
+
}
|
|
881
|
+
if (this.params.customerSupportAudioCapture) {
|
|
882
|
+
console.warn("`customerSupportAudioCapture=true` will record session audio. Only enable this when explicitly coordinating with AssemblyAI support.");
|
|
883
|
+
searchParams.set("customer_support_audio_capture", this.params.customerSupportAudioCapture.toString());
|
|
884
|
+
}
|
|
885
|
+
if (this.params.webhookUrl) {
|
|
886
|
+
searchParams.set("webhook_url", this.params.webhookUrl);
|
|
887
|
+
}
|
|
888
|
+
if (this.params.webhookAuthHeaderName) {
|
|
889
|
+
searchParams.set("webhook_auth_header_name", this.params.webhookAuthHeaderName);
|
|
890
|
+
}
|
|
891
|
+
if (this.params.webhookAuthHeaderValue) {
|
|
892
|
+
searchParams.set("webhook_auth_header_value", this.params.webhookAuthHeaderValue);
|
|
893
|
+
}
|
|
894
|
+
if (this.params.includePartialTurns !== undefined) {
|
|
895
|
+
searchParams.set("include_partial_turns", this.params.includePartialTurns.toString());
|
|
896
|
+
}
|
|
897
|
+
if (this.params.redactPii !== undefined) {
|
|
898
|
+
searchParams.set("redact_pii", this.params.redactPii.toString());
|
|
899
|
+
}
|
|
900
|
+
if (this.params.redactPiiPolicies !== undefined) {
|
|
901
|
+
searchParams.set("redact_pii_policies", JSON.stringify(this.params.redactPiiPolicies));
|
|
902
|
+
}
|
|
903
|
+
if (this.params.redactPiiSub !== undefined) {
|
|
904
|
+
searchParams.set("redact_pii_sub", this.params.redactPiiSub);
|
|
905
|
+
}
|
|
856
906
|
if (this.params.llmGateway !== undefined) {
|
|
857
907
|
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
858
908
|
}
|
|
@@ -896,7 +946,12 @@ class StreamingTranscriber {
|
|
|
896
946
|
this.socket.onmessage = ({ data }) => {
|
|
897
947
|
const message = JSON.parse(data.toString());
|
|
898
948
|
if ("error" in message) {
|
|
899
|
-
|
|
949
|
+
const err = new StreamingError(message.error);
|
|
950
|
+
if ("error_code" in message) {
|
|
951
|
+
err.code =
|
|
952
|
+
message.error_code;
|
|
953
|
+
}
|
|
954
|
+
this.listeners.error?.(err);
|
|
900
955
|
return;
|
|
901
956
|
}
|
|
902
957
|
switch (message.type) {
|
|
@@ -917,6 +972,12 @@ class StreamingTranscriber {
|
|
|
917
972
|
this.listeners.llmGatewayResponse?.(message);
|
|
918
973
|
break;
|
|
919
974
|
}
|
|
975
|
+
case "Warning": {
|
|
976
|
+
const warning = message;
|
|
977
|
+
console.warn(`Streaming warning (code=${warning.warning_code}): ${warning.warning}`);
|
|
978
|
+
this.listeners.warning?.(warning);
|
|
979
|
+
break;
|
|
980
|
+
}
|
|
920
981
|
case "Termination": {
|
|
921
982
|
this.sessionTerminatedResolve?.();
|
|
922
983
|
break;
|
|
@@ -940,9 +1001,20 @@ class StreamingTranscriber {
|
|
|
940
1001
|
* @param config - The configuration parameters to update
|
|
941
1002
|
*/
|
|
942
1003
|
updateConfiguration(config) {
|
|
1004
|
+
const { min_end_of_turn_silence_when_confident, min_turn_silence, ...rest } = config;
|
|
1005
|
+
if (min_end_of_turn_silence_when_confident !== undefined) {
|
|
1006
|
+
if (min_turn_silence !== undefined) {
|
|
1007
|
+
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.");
|
|
1008
|
+
}
|
|
1009
|
+
else {
|
|
1010
|
+
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.");
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
const effective = min_turn_silence ?? min_end_of_turn_silence_when_confident;
|
|
943
1014
|
const message = {
|
|
944
1015
|
type: "UpdateConfiguration",
|
|
945
|
-
...
|
|
1016
|
+
...rest,
|
|
1017
|
+
...(effective !== undefined ? { min_turn_silence: effective } : {}),
|
|
946
1018
|
};
|
|
947
1019
|
this.send(JSON.stringify(message));
|
|
948
1020
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -63,7 +63,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
63
63
|
defaultUserAgentString += navigator.userAgent;
|
|
64
64
|
}
|
|
65
65
|
const defaultUserAgent = {
|
|
66
|
-
sdk: { name: "JavaScript", version: "4.
|
|
66
|
+
sdk: { name: "JavaScript", version: "4.33.0" },
|
|
67
67
|
};
|
|
68
68
|
if (typeof process !== "undefined") {
|
|
69
69
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -279,8 +279,18 @@ const StreamingErrorType = {
|
|
|
279
279
|
BadSchema: 4101,
|
|
280
280
|
TooManyStreams: 4102,
|
|
281
281
|
Reconnected: 4103,
|
|
282
|
+
ServerError: 3005,
|
|
283
|
+
InputValidationError: 3006,
|
|
284
|
+
AudioChunkDurationViolation: 3007,
|
|
285
|
+
MaxSessionDurationExceeded: 3008,
|
|
286
|
+
ConcurrencyLimitExceeded: 3009,
|
|
282
287
|
};
|
|
283
288
|
const StreamingErrorMessages = {
|
|
289
|
+
[StreamingErrorType.ServerError]: "Server error",
|
|
290
|
+
[StreamingErrorType.InputValidationError]: "Input validation error",
|
|
291
|
+
[StreamingErrorType.AudioChunkDurationViolation]: "Audio chunk duration violation",
|
|
292
|
+
[StreamingErrorType.MaxSessionDurationExceeded]: "Session expired: maximum session duration exceeded",
|
|
293
|
+
[StreamingErrorType.ConcurrencyLimitExceeded]: "Too many concurrent sessions",
|
|
284
294
|
[StreamingErrorType.BadSampleRate]: "Sample rate must be a positive integer",
|
|
285
295
|
[StreamingErrorType.AuthFailed]: "Not Authorized",
|
|
286
296
|
[StreamingErrorType.InsufficientFunds]: "Insufficient funds",
|
|
@@ -880,7 +890,7 @@ class StreamingTranscriber {
|
|
|
880
890
|
}
|
|
881
891
|
}
|
|
882
892
|
connectionUrl() {
|
|
883
|
-
var _a;
|
|
893
|
+
var _a, _b;
|
|
884
894
|
const url = new URL((_a = this.params.websocketBaseUrl) !== null && _a !== void 0 ? _a : "");
|
|
885
895
|
if (url.protocol !== "wss:") {
|
|
886
896
|
throw new Error("Invalid protocol, must be wss");
|
|
@@ -893,12 +903,17 @@ class StreamingTranscriber {
|
|
|
893
903
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
894
904
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
895
905
|
}
|
|
896
|
-
if (this.params.
|
|
897
|
-
|
|
906
|
+
if (this.params.minEndOfTurnSilenceWhenConfident !== undefined) {
|
|
907
|
+
if (this.params.minTurnSilence !== undefined) {
|
|
908
|
+
console.warn("[Deprecation Warning] Both `minEndOfTurnSilenceWhenConfident` and `minTurnSilence` are set. Using `minTurnSilence`; `minEndOfTurnSilenceWhenConfident` is deprecated.");
|
|
909
|
+
}
|
|
910
|
+
else {
|
|
911
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
912
|
+
}
|
|
898
913
|
}
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
searchParams.set("
|
|
914
|
+
const effectiveMinTurnSilence = (_b = this.params.minTurnSilence) !== null && _b !== void 0 ? _b : this.params.minEndOfTurnSilenceWhenConfident;
|
|
915
|
+
if (effectiveMinTurnSilence !== undefined) {
|
|
916
|
+
searchParams.set("min_turn_silence", effectiveMinTurnSilence.toString());
|
|
902
917
|
}
|
|
903
918
|
if (this.params.maxTurnSilence) {
|
|
904
919
|
searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
|
|
@@ -944,6 +959,40 @@ class StreamingTranscriber {
|
|
|
944
959
|
if (this.params.maxSpeakers !== undefined) {
|
|
945
960
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
946
961
|
}
|
|
962
|
+
if (this.params.voiceFocus) {
|
|
963
|
+
searchParams.set("voice_focus", this.params.voiceFocus);
|
|
964
|
+
}
|
|
965
|
+
if (this.params.voiceFocusThreshold !== undefined) {
|
|
966
|
+
searchParams.set("voice_focus_threshold", this.params.voiceFocusThreshold.toString());
|
|
967
|
+
}
|
|
968
|
+
if (this.params.continuousPartials !== undefined) {
|
|
969
|
+
searchParams.set("continuous_partials", this.params.continuousPartials.toString());
|
|
970
|
+
}
|
|
971
|
+
if (this.params.customerSupportAudioCapture) {
|
|
972
|
+
console.warn("`customerSupportAudioCapture=true` will record session audio. Only enable this when explicitly coordinating with AssemblyAI support.");
|
|
973
|
+
searchParams.set("customer_support_audio_capture", this.params.customerSupportAudioCapture.toString());
|
|
974
|
+
}
|
|
975
|
+
if (this.params.webhookUrl) {
|
|
976
|
+
searchParams.set("webhook_url", this.params.webhookUrl);
|
|
977
|
+
}
|
|
978
|
+
if (this.params.webhookAuthHeaderName) {
|
|
979
|
+
searchParams.set("webhook_auth_header_name", this.params.webhookAuthHeaderName);
|
|
980
|
+
}
|
|
981
|
+
if (this.params.webhookAuthHeaderValue) {
|
|
982
|
+
searchParams.set("webhook_auth_header_value", this.params.webhookAuthHeaderValue);
|
|
983
|
+
}
|
|
984
|
+
if (this.params.includePartialTurns !== undefined) {
|
|
985
|
+
searchParams.set("include_partial_turns", this.params.includePartialTurns.toString());
|
|
986
|
+
}
|
|
987
|
+
if (this.params.redactPii !== undefined) {
|
|
988
|
+
searchParams.set("redact_pii", this.params.redactPii.toString());
|
|
989
|
+
}
|
|
990
|
+
if (this.params.redactPiiPolicies !== undefined) {
|
|
991
|
+
searchParams.set("redact_pii_policies", JSON.stringify(this.params.redactPiiPolicies));
|
|
992
|
+
}
|
|
993
|
+
if (this.params.redactPiiSub !== undefined) {
|
|
994
|
+
searchParams.set("redact_pii_sub", this.params.redactPiiSub);
|
|
995
|
+
}
|
|
947
996
|
if (this.params.llmGateway !== undefined) {
|
|
948
997
|
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
949
998
|
}
|
|
@@ -987,10 +1036,15 @@ class StreamingTranscriber {
|
|
|
987
1036
|
(_d = (_c = this.listeners).error) === null || _d === void 0 ? void 0 : _d.call(_c, new Error(event.message));
|
|
988
1037
|
};
|
|
989
1038
|
this.socket.onmessage = ({ data }) => {
|
|
990
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
1039
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
991
1040
|
const message = JSON.parse(data.toString());
|
|
992
1041
|
if ("error" in message) {
|
|
993
|
-
|
|
1042
|
+
const err = new StreamingError(message.error);
|
|
1043
|
+
if ("error_code" in message) {
|
|
1044
|
+
err.code =
|
|
1045
|
+
message.error_code;
|
|
1046
|
+
}
|
|
1047
|
+
(_b = (_a = this.listeners).error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
|
|
994
1048
|
return;
|
|
995
1049
|
}
|
|
996
1050
|
switch (message.type) {
|
|
@@ -1011,8 +1065,14 @@ class StreamingTranscriber {
|
|
|
1011
1065
|
(_k = (_j = this.listeners).llmGatewayResponse) === null || _k === void 0 ? void 0 : _k.call(_j, message);
|
|
1012
1066
|
break;
|
|
1013
1067
|
}
|
|
1068
|
+
case "Warning": {
|
|
1069
|
+
const warning = message;
|
|
1070
|
+
console.warn(`Streaming warning (code=${warning.warning_code}): ${warning.warning}`);
|
|
1071
|
+
(_m = (_l = this.listeners).warning) === null || _m === void 0 ? void 0 : _m.call(_l, warning);
|
|
1072
|
+
break;
|
|
1073
|
+
}
|
|
1014
1074
|
case "Termination": {
|
|
1015
|
-
(
|
|
1075
|
+
(_o = this.sessionTerminatedResolve) === null || _o === void 0 ? void 0 : _o.call(this);
|
|
1016
1076
|
break;
|
|
1017
1077
|
}
|
|
1018
1078
|
}
|
|
@@ -1034,7 +1094,17 @@ class StreamingTranscriber {
|
|
|
1034
1094
|
* @param config - The configuration parameters to update
|
|
1035
1095
|
*/
|
|
1036
1096
|
updateConfiguration(config) {
|
|
1037
|
-
const
|
|
1097
|
+
const { min_end_of_turn_silence_when_confident, min_turn_silence } = config, rest = __rest(config, ["min_end_of_turn_silence_when_confident", "min_turn_silence"]);
|
|
1098
|
+
if (min_end_of_turn_silence_when_confident !== undefined) {
|
|
1099
|
+
if (min_turn_silence !== undefined) {
|
|
1100
|
+
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.");
|
|
1101
|
+
}
|
|
1102
|
+
else {
|
|
1103
|
+
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.");
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
const effective = min_turn_silence !== null && min_turn_silence !== void 0 ? min_turn_silence : min_end_of_turn_silence_when_confident;
|
|
1107
|
+
const message = Object.assign(Object.assign({ type: "UpdateConfiguration" }, rest), (effective !== undefined ? { min_turn_silence: effective } : {}));
|
|
1038
1108
|
this.send(JSON.stringify(message));
|
|
1039
1109
|
}
|
|
1040
1110
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -61,7 +61,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
61
61
|
defaultUserAgentString += navigator.userAgent;
|
|
62
62
|
}
|
|
63
63
|
const defaultUserAgent = {
|
|
64
|
-
sdk: { name: "JavaScript", version: "4.
|
|
64
|
+
sdk: { name: "JavaScript", version: "4.33.0" },
|
|
65
65
|
};
|
|
66
66
|
if (typeof process !== "undefined") {
|
|
67
67
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -277,8 +277,18 @@ const StreamingErrorType = {
|
|
|
277
277
|
BadSchema: 4101,
|
|
278
278
|
TooManyStreams: 4102,
|
|
279
279
|
Reconnected: 4103,
|
|
280
|
+
ServerError: 3005,
|
|
281
|
+
InputValidationError: 3006,
|
|
282
|
+
AudioChunkDurationViolation: 3007,
|
|
283
|
+
MaxSessionDurationExceeded: 3008,
|
|
284
|
+
ConcurrencyLimitExceeded: 3009,
|
|
280
285
|
};
|
|
281
286
|
const StreamingErrorMessages = {
|
|
287
|
+
[StreamingErrorType.ServerError]: "Server error",
|
|
288
|
+
[StreamingErrorType.InputValidationError]: "Input validation error",
|
|
289
|
+
[StreamingErrorType.AudioChunkDurationViolation]: "Audio chunk duration violation",
|
|
290
|
+
[StreamingErrorType.MaxSessionDurationExceeded]: "Session expired: maximum session duration exceeded",
|
|
291
|
+
[StreamingErrorType.ConcurrencyLimitExceeded]: "Too many concurrent sessions",
|
|
282
292
|
[StreamingErrorType.BadSampleRate]: "Sample rate must be a positive integer",
|
|
283
293
|
[StreamingErrorType.AuthFailed]: "Not Authorized",
|
|
284
294
|
[StreamingErrorType.InsufficientFunds]: "Insufficient funds",
|
|
@@ -878,7 +888,7 @@ class StreamingTranscriber {
|
|
|
878
888
|
}
|
|
879
889
|
}
|
|
880
890
|
connectionUrl() {
|
|
881
|
-
var _a;
|
|
891
|
+
var _a, _b;
|
|
882
892
|
const url = new URL((_a = this.params.websocketBaseUrl) !== null && _a !== void 0 ? _a : "");
|
|
883
893
|
if (url.protocol !== "wss:") {
|
|
884
894
|
throw new Error("Invalid protocol, must be wss");
|
|
@@ -891,12 +901,17 @@ class StreamingTranscriber {
|
|
|
891
901
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
892
902
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
893
903
|
}
|
|
894
|
-
if (this.params.
|
|
895
|
-
|
|
904
|
+
if (this.params.minEndOfTurnSilenceWhenConfident !== undefined) {
|
|
905
|
+
if (this.params.minTurnSilence !== undefined) {
|
|
906
|
+
console.warn("[Deprecation Warning] Both `minEndOfTurnSilenceWhenConfident` and `minTurnSilence` are set. Using `minTurnSilence`; `minEndOfTurnSilenceWhenConfident` is deprecated.");
|
|
907
|
+
}
|
|
908
|
+
else {
|
|
909
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
910
|
+
}
|
|
896
911
|
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
searchParams.set("
|
|
912
|
+
const effectiveMinTurnSilence = (_b = this.params.minTurnSilence) !== null && _b !== void 0 ? _b : this.params.minEndOfTurnSilenceWhenConfident;
|
|
913
|
+
if (effectiveMinTurnSilence !== undefined) {
|
|
914
|
+
searchParams.set("min_turn_silence", effectiveMinTurnSilence.toString());
|
|
900
915
|
}
|
|
901
916
|
if (this.params.maxTurnSilence) {
|
|
902
917
|
searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
|
|
@@ -942,6 +957,40 @@ class StreamingTranscriber {
|
|
|
942
957
|
if (this.params.maxSpeakers !== undefined) {
|
|
943
958
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
944
959
|
}
|
|
960
|
+
if (this.params.voiceFocus) {
|
|
961
|
+
searchParams.set("voice_focus", this.params.voiceFocus);
|
|
962
|
+
}
|
|
963
|
+
if (this.params.voiceFocusThreshold !== undefined) {
|
|
964
|
+
searchParams.set("voice_focus_threshold", this.params.voiceFocusThreshold.toString());
|
|
965
|
+
}
|
|
966
|
+
if (this.params.continuousPartials !== undefined) {
|
|
967
|
+
searchParams.set("continuous_partials", this.params.continuousPartials.toString());
|
|
968
|
+
}
|
|
969
|
+
if (this.params.customerSupportAudioCapture) {
|
|
970
|
+
console.warn("`customerSupportAudioCapture=true` will record session audio. Only enable this when explicitly coordinating with AssemblyAI support.");
|
|
971
|
+
searchParams.set("customer_support_audio_capture", this.params.customerSupportAudioCapture.toString());
|
|
972
|
+
}
|
|
973
|
+
if (this.params.webhookUrl) {
|
|
974
|
+
searchParams.set("webhook_url", this.params.webhookUrl);
|
|
975
|
+
}
|
|
976
|
+
if (this.params.webhookAuthHeaderName) {
|
|
977
|
+
searchParams.set("webhook_auth_header_name", this.params.webhookAuthHeaderName);
|
|
978
|
+
}
|
|
979
|
+
if (this.params.webhookAuthHeaderValue) {
|
|
980
|
+
searchParams.set("webhook_auth_header_value", this.params.webhookAuthHeaderValue);
|
|
981
|
+
}
|
|
982
|
+
if (this.params.includePartialTurns !== undefined) {
|
|
983
|
+
searchParams.set("include_partial_turns", this.params.includePartialTurns.toString());
|
|
984
|
+
}
|
|
985
|
+
if (this.params.redactPii !== undefined) {
|
|
986
|
+
searchParams.set("redact_pii", this.params.redactPii.toString());
|
|
987
|
+
}
|
|
988
|
+
if (this.params.redactPiiPolicies !== undefined) {
|
|
989
|
+
searchParams.set("redact_pii_policies", JSON.stringify(this.params.redactPiiPolicies));
|
|
990
|
+
}
|
|
991
|
+
if (this.params.redactPiiSub !== undefined) {
|
|
992
|
+
searchParams.set("redact_pii_sub", this.params.redactPiiSub);
|
|
993
|
+
}
|
|
945
994
|
if (this.params.llmGateway !== undefined) {
|
|
946
995
|
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
947
996
|
}
|
|
@@ -985,10 +1034,15 @@ class StreamingTranscriber {
|
|
|
985
1034
|
(_d = (_c = this.listeners).error) === null || _d === void 0 ? void 0 : _d.call(_c, new Error(event.message));
|
|
986
1035
|
};
|
|
987
1036
|
this.socket.onmessage = ({ data }) => {
|
|
988
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
1037
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
989
1038
|
const message = JSON.parse(data.toString());
|
|
990
1039
|
if ("error" in message) {
|
|
991
|
-
|
|
1040
|
+
const err = new StreamingError(message.error);
|
|
1041
|
+
if ("error_code" in message) {
|
|
1042
|
+
err.code =
|
|
1043
|
+
message.error_code;
|
|
1044
|
+
}
|
|
1045
|
+
(_b = (_a = this.listeners).error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
|
|
992
1046
|
return;
|
|
993
1047
|
}
|
|
994
1048
|
switch (message.type) {
|
|
@@ -1009,8 +1063,14 @@ class StreamingTranscriber {
|
|
|
1009
1063
|
(_k = (_j = this.listeners).llmGatewayResponse) === null || _k === void 0 ? void 0 : _k.call(_j, message);
|
|
1010
1064
|
break;
|
|
1011
1065
|
}
|
|
1066
|
+
case "Warning": {
|
|
1067
|
+
const warning = message;
|
|
1068
|
+
console.warn(`Streaming warning (code=${warning.warning_code}): ${warning.warning}`);
|
|
1069
|
+
(_m = (_l = this.listeners).warning) === null || _m === void 0 ? void 0 : _m.call(_l, warning);
|
|
1070
|
+
break;
|
|
1071
|
+
}
|
|
1012
1072
|
case "Termination": {
|
|
1013
|
-
(
|
|
1073
|
+
(_o = this.sessionTerminatedResolve) === null || _o === void 0 ? void 0 : _o.call(this);
|
|
1014
1074
|
break;
|
|
1015
1075
|
}
|
|
1016
1076
|
}
|
|
@@ -1032,7 +1092,17 @@ class StreamingTranscriber {
|
|
|
1032
1092
|
* @param config - The configuration parameters to update
|
|
1033
1093
|
*/
|
|
1034
1094
|
updateConfiguration(config) {
|
|
1035
|
-
const
|
|
1095
|
+
const { min_end_of_turn_silence_when_confident, min_turn_silence } = config, rest = __rest(config, ["min_end_of_turn_silence_when_confident", "min_turn_silence"]);
|
|
1096
|
+
if (min_end_of_turn_silence_when_confident !== undefined) {
|
|
1097
|
+
if (min_turn_silence !== undefined) {
|
|
1098
|
+
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.");
|
|
1099
|
+
}
|
|
1100
|
+
else {
|
|
1101
|
+
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.");
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
const effective = min_turn_silence !== null && min_turn_silence !== void 0 ? min_turn_silence : min_end_of_turn_silence_when_confident;
|
|
1105
|
+
const message = Object.assign(Object.assign({ type: "UpdateConfiguration" }, rest), (effective !== undefined ? { min_turn_silence: effective } : {}));
|
|
1036
1106
|
this.send(JSON.stringify(message));
|
|
1037
1107
|
}
|
|
1038
1108
|
/**
|
package/dist/node.cjs
CHANGED
|
@@ -22,7 +22,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
22
22
|
defaultUserAgentString += navigator.userAgent;
|
|
23
23
|
}
|
|
24
24
|
const defaultUserAgent = {
|
|
25
|
-
sdk: { name: "JavaScript", version: "4.
|
|
25
|
+
sdk: { name: "JavaScript", version: "4.33.0" },
|
|
26
26
|
};
|
|
27
27
|
if (typeof process !== "undefined") {
|
|
28
28
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -221,8 +221,18 @@ const StreamingErrorType = {
|
|
|
221
221
|
BadSchema: 4101,
|
|
222
222
|
TooManyStreams: 4102,
|
|
223
223
|
Reconnected: 4103,
|
|
224
|
+
ServerError: 3005,
|
|
225
|
+
InputValidationError: 3006,
|
|
226
|
+
AudioChunkDurationViolation: 3007,
|
|
227
|
+
MaxSessionDurationExceeded: 3008,
|
|
228
|
+
ConcurrencyLimitExceeded: 3009,
|
|
224
229
|
};
|
|
225
230
|
const StreamingErrorMessages = {
|
|
231
|
+
[StreamingErrorType.ServerError]: "Server error",
|
|
232
|
+
[StreamingErrorType.InputValidationError]: "Input validation error",
|
|
233
|
+
[StreamingErrorType.AudioChunkDurationViolation]: "Audio chunk duration violation",
|
|
234
|
+
[StreamingErrorType.MaxSessionDurationExceeded]: "Session expired: maximum session duration exceeded",
|
|
235
|
+
[StreamingErrorType.ConcurrencyLimitExceeded]: "Too many concurrent sessions",
|
|
226
236
|
[StreamingErrorType.BadSampleRate]: "Sample rate must be a positive integer",
|
|
227
237
|
[StreamingErrorType.AuthFailed]: "Not Authorized",
|
|
228
238
|
[StreamingErrorType.InsufficientFunds]: "Insufficient funds",
|
|
@@ -801,12 +811,18 @@ class StreamingTranscriber {
|
|
|
801
811
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
802
812
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
803
813
|
}
|
|
804
|
-
if (this.params.
|
|
805
|
-
|
|
814
|
+
if (this.params.minEndOfTurnSilenceWhenConfident !== undefined) {
|
|
815
|
+
if (this.params.minTurnSilence !== undefined) {
|
|
816
|
+
console.warn("[Deprecation Warning] Both `minEndOfTurnSilenceWhenConfident` and `minTurnSilence` are set. Using `minTurnSilence`; `minEndOfTurnSilenceWhenConfident` is deprecated.");
|
|
817
|
+
}
|
|
818
|
+
else {
|
|
819
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
820
|
+
}
|
|
806
821
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
822
|
+
const effectiveMinTurnSilence = this.params.minTurnSilence ??
|
|
823
|
+
this.params.minEndOfTurnSilenceWhenConfident;
|
|
824
|
+
if (effectiveMinTurnSilence !== undefined) {
|
|
825
|
+
searchParams.set("min_turn_silence", effectiveMinTurnSilence.toString());
|
|
810
826
|
}
|
|
811
827
|
if (this.params.maxTurnSilence) {
|
|
812
828
|
searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
|
|
@@ -852,6 +868,40 @@ class StreamingTranscriber {
|
|
|
852
868
|
if (this.params.maxSpeakers !== undefined) {
|
|
853
869
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
854
870
|
}
|
|
871
|
+
if (this.params.voiceFocus) {
|
|
872
|
+
searchParams.set("voice_focus", this.params.voiceFocus);
|
|
873
|
+
}
|
|
874
|
+
if (this.params.voiceFocusThreshold !== undefined) {
|
|
875
|
+
searchParams.set("voice_focus_threshold", this.params.voiceFocusThreshold.toString());
|
|
876
|
+
}
|
|
877
|
+
if (this.params.continuousPartials !== undefined) {
|
|
878
|
+
searchParams.set("continuous_partials", this.params.continuousPartials.toString());
|
|
879
|
+
}
|
|
880
|
+
if (this.params.customerSupportAudioCapture) {
|
|
881
|
+
console.warn("`customerSupportAudioCapture=true` will record session audio. Only enable this when explicitly coordinating with AssemblyAI support.");
|
|
882
|
+
searchParams.set("customer_support_audio_capture", this.params.customerSupportAudioCapture.toString());
|
|
883
|
+
}
|
|
884
|
+
if (this.params.webhookUrl) {
|
|
885
|
+
searchParams.set("webhook_url", this.params.webhookUrl);
|
|
886
|
+
}
|
|
887
|
+
if (this.params.webhookAuthHeaderName) {
|
|
888
|
+
searchParams.set("webhook_auth_header_name", this.params.webhookAuthHeaderName);
|
|
889
|
+
}
|
|
890
|
+
if (this.params.webhookAuthHeaderValue) {
|
|
891
|
+
searchParams.set("webhook_auth_header_value", this.params.webhookAuthHeaderValue);
|
|
892
|
+
}
|
|
893
|
+
if (this.params.includePartialTurns !== undefined) {
|
|
894
|
+
searchParams.set("include_partial_turns", this.params.includePartialTurns.toString());
|
|
895
|
+
}
|
|
896
|
+
if (this.params.redactPii !== undefined) {
|
|
897
|
+
searchParams.set("redact_pii", this.params.redactPii.toString());
|
|
898
|
+
}
|
|
899
|
+
if (this.params.redactPiiPolicies !== undefined) {
|
|
900
|
+
searchParams.set("redact_pii_policies", JSON.stringify(this.params.redactPiiPolicies));
|
|
901
|
+
}
|
|
902
|
+
if (this.params.redactPiiSub !== undefined) {
|
|
903
|
+
searchParams.set("redact_pii_sub", this.params.redactPiiSub);
|
|
904
|
+
}
|
|
855
905
|
if (this.params.llmGateway !== undefined) {
|
|
856
906
|
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
857
907
|
}
|
|
@@ -895,7 +945,12 @@ class StreamingTranscriber {
|
|
|
895
945
|
this.socket.onmessage = ({ data }) => {
|
|
896
946
|
const message = JSON.parse(data.toString());
|
|
897
947
|
if ("error" in message) {
|
|
898
|
-
|
|
948
|
+
const err = new StreamingError(message.error);
|
|
949
|
+
if ("error_code" in message) {
|
|
950
|
+
err.code =
|
|
951
|
+
message.error_code;
|
|
952
|
+
}
|
|
953
|
+
this.listeners.error?.(err);
|
|
899
954
|
return;
|
|
900
955
|
}
|
|
901
956
|
switch (message.type) {
|
|
@@ -916,6 +971,12 @@ class StreamingTranscriber {
|
|
|
916
971
|
this.listeners.llmGatewayResponse?.(message);
|
|
917
972
|
break;
|
|
918
973
|
}
|
|
974
|
+
case "Warning": {
|
|
975
|
+
const warning = message;
|
|
976
|
+
console.warn(`Streaming warning (code=${warning.warning_code}): ${warning.warning}`);
|
|
977
|
+
this.listeners.warning?.(warning);
|
|
978
|
+
break;
|
|
979
|
+
}
|
|
919
980
|
case "Termination": {
|
|
920
981
|
this.sessionTerminatedResolve?.();
|
|
921
982
|
break;
|
|
@@ -939,9 +1000,20 @@ class StreamingTranscriber {
|
|
|
939
1000
|
* @param config - The configuration parameters to update
|
|
940
1001
|
*/
|
|
941
1002
|
updateConfiguration(config) {
|
|
1003
|
+
const { min_end_of_turn_silence_when_confident, min_turn_silence, ...rest } = config;
|
|
1004
|
+
if (min_end_of_turn_silence_when_confident !== undefined) {
|
|
1005
|
+
if (min_turn_silence !== undefined) {
|
|
1006
|
+
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.");
|
|
1007
|
+
}
|
|
1008
|
+
else {
|
|
1009
|
+
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.");
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
const effective = min_turn_silence ?? min_end_of_turn_silence_when_confident;
|
|
942
1013
|
const message = {
|
|
943
1014
|
type: "UpdateConfiguration",
|
|
944
|
-
...
|
|
1015
|
+
...rest,
|
|
1016
|
+
...(effective !== undefined ? { min_turn_silence: effective } : {}),
|
|
945
1017
|
};
|
|
946
1018
|
this.send(JSON.stringify(message));
|
|
947
1019
|
}
|