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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.33.0]
|
|
4
|
+
|
|
5
|
+
- Add streaming parameters to match the Python SDK:
|
|
6
|
+
- `voiceFocus` and `voiceFocusThreshold` (replaces the unreleased `noiseSuppressionModel` / `noiseSuppressionThreshold`)
|
|
7
|
+
- `continuousPartials`
|
|
8
|
+
- `customerSupportAudioCapture` (logs a warning when enabled — records session audio for AssemblyAI support)
|
|
9
|
+
- `webhookUrl`, `webhookAuthHeaderName`, `webhookAuthHeaderValue`
|
|
10
|
+
- Add `speaker` field to `StreamingWord`
|
|
11
|
+
|
|
3
12
|
## [4.20.0]
|
|
4
13
|
|
|
5
14
|
- Add `on_low_language_confidence` property to `LanguageDetectionOptions`
|
package/dist/assemblyai.umd.js
CHANGED
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
defaultUserAgentString += navigator.userAgent;
|
|
66
66
|
}
|
|
67
67
|
const defaultUserAgent = {
|
|
68
|
-
sdk: { name: "JavaScript", version: "4.
|
|
68
|
+
sdk: { name: "JavaScript", version: "4.33.0" },
|
|
69
69
|
};
|
|
70
70
|
if (typeof process !== "undefined") {
|
|
71
71
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -288,8 +288,18 @@
|
|
|
288
288
|
BadSchema: 4101,
|
|
289
289
|
TooManyStreams: 4102,
|
|
290
290
|
Reconnected: 4103,
|
|
291
|
+
ServerError: 3005,
|
|
292
|
+
InputValidationError: 3006,
|
|
293
|
+
AudioChunkDurationViolation: 3007,
|
|
294
|
+
MaxSessionDurationExceeded: 3008,
|
|
295
|
+
ConcurrencyLimitExceeded: 3009,
|
|
291
296
|
};
|
|
292
297
|
const StreamingErrorMessages = {
|
|
298
|
+
[StreamingErrorType.ServerError]: "Server error",
|
|
299
|
+
[StreamingErrorType.InputValidationError]: "Input validation error",
|
|
300
|
+
[StreamingErrorType.AudioChunkDurationViolation]: "Audio chunk duration violation",
|
|
301
|
+
[StreamingErrorType.MaxSessionDurationExceeded]: "Session expired: maximum session duration exceeded",
|
|
302
|
+
[StreamingErrorType.ConcurrencyLimitExceeded]: "Too many concurrent sessions",
|
|
293
303
|
[StreamingErrorType.BadSampleRate]: "Sample rate must be a positive integer",
|
|
294
304
|
[StreamingErrorType.AuthFailed]: "Not Authorized",
|
|
295
305
|
[StreamingErrorType.InsufficientFunds]: "Insufficient funds",
|
|
@@ -893,7 +903,7 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
893
903
|
}
|
|
894
904
|
}
|
|
895
905
|
connectionUrl() {
|
|
896
|
-
var _a;
|
|
906
|
+
var _a, _b;
|
|
897
907
|
const url = new URL((_a = this.params.websocketBaseUrl) !== null && _a !== void 0 ? _a : "");
|
|
898
908
|
if (url.protocol !== "wss:") {
|
|
899
909
|
throw new Error("Invalid protocol, must be wss");
|
|
@@ -906,12 +916,17 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
906
916
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
907
917
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
908
918
|
}
|
|
909
|
-
if (this.params.
|
|
910
|
-
|
|
919
|
+
if (this.params.minEndOfTurnSilenceWhenConfident !== undefined) {
|
|
920
|
+
if (this.params.minTurnSilence !== undefined) {
|
|
921
|
+
console.warn("[Deprecation Warning] Both `minEndOfTurnSilenceWhenConfident` and `minTurnSilence` are set. Using `minTurnSilence`; `minEndOfTurnSilenceWhenConfident` is deprecated.");
|
|
922
|
+
}
|
|
923
|
+
else {
|
|
924
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
925
|
+
}
|
|
911
926
|
}
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
searchParams.set("
|
|
927
|
+
const effectiveMinTurnSilence = (_b = this.params.minTurnSilence) !== null && _b !== void 0 ? _b : this.params.minEndOfTurnSilenceWhenConfident;
|
|
928
|
+
if (effectiveMinTurnSilence !== undefined) {
|
|
929
|
+
searchParams.set("min_turn_silence", effectiveMinTurnSilence.toString());
|
|
915
930
|
}
|
|
916
931
|
if (this.params.maxTurnSilence) {
|
|
917
932
|
searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
|
|
@@ -957,6 +972,40 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
957
972
|
if (this.params.maxSpeakers !== undefined) {
|
|
958
973
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
959
974
|
}
|
|
975
|
+
if (this.params.voiceFocus) {
|
|
976
|
+
searchParams.set("voice_focus", this.params.voiceFocus);
|
|
977
|
+
}
|
|
978
|
+
if (this.params.voiceFocusThreshold !== undefined) {
|
|
979
|
+
searchParams.set("voice_focus_threshold", this.params.voiceFocusThreshold.toString());
|
|
980
|
+
}
|
|
981
|
+
if (this.params.continuousPartials !== undefined) {
|
|
982
|
+
searchParams.set("continuous_partials", this.params.continuousPartials.toString());
|
|
983
|
+
}
|
|
984
|
+
if (this.params.customerSupportAudioCapture) {
|
|
985
|
+
console.warn("`customerSupportAudioCapture=true` will record session audio. Only enable this when explicitly coordinating with AssemblyAI support.");
|
|
986
|
+
searchParams.set("customer_support_audio_capture", this.params.customerSupportAudioCapture.toString());
|
|
987
|
+
}
|
|
988
|
+
if (this.params.webhookUrl) {
|
|
989
|
+
searchParams.set("webhook_url", this.params.webhookUrl);
|
|
990
|
+
}
|
|
991
|
+
if (this.params.webhookAuthHeaderName) {
|
|
992
|
+
searchParams.set("webhook_auth_header_name", this.params.webhookAuthHeaderName);
|
|
993
|
+
}
|
|
994
|
+
if (this.params.webhookAuthHeaderValue) {
|
|
995
|
+
searchParams.set("webhook_auth_header_value", this.params.webhookAuthHeaderValue);
|
|
996
|
+
}
|
|
997
|
+
if (this.params.includePartialTurns !== undefined) {
|
|
998
|
+
searchParams.set("include_partial_turns", this.params.includePartialTurns.toString());
|
|
999
|
+
}
|
|
1000
|
+
if (this.params.redactPii !== undefined) {
|
|
1001
|
+
searchParams.set("redact_pii", this.params.redactPii.toString());
|
|
1002
|
+
}
|
|
1003
|
+
if (this.params.redactPiiPolicies !== undefined) {
|
|
1004
|
+
searchParams.set("redact_pii_policies", JSON.stringify(this.params.redactPiiPolicies));
|
|
1005
|
+
}
|
|
1006
|
+
if (this.params.redactPiiSub !== undefined) {
|
|
1007
|
+
searchParams.set("redact_pii_sub", this.params.redactPiiSub);
|
|
1008
|
+
}
|
|
960
1009
|
if (this.params.llmGateway !== undefined) {
|
|
961
1010
|
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
962
1011
|
}
|
|
@@ -1004,10 +1053,15 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
1004
1053
|
(_d = (_c = this.listeners).error) === null || _d === void 0 ? void 0 : _d.call(_c, new Error(event.message));
|
|
1005
1054
|
};
|
|
1006
1055
|
this.socket.onmessage = ({ data }) => {
|
|
1007
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
1056
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
1008
1057
|
const message = JSON.parse(data.toString());
|
|
1009
1058
|
if ("error" in message) {
|
|
1010
|
-
|
|
1059
|
+
const err = new StreamingError(message.error);
|
|
1060
|
+
if ("error_code" in message) {
|
|
1061
|
+
err.code =
|
|
1062
|
+
message.error_code;
|
|
1063
|
+
}
|
|
1064
|
+
(_b = (_a = this.listeners).error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
|
|
1011
1065
|
return;
|
|
1012
1066
|
}
|
|
1013
1067
|
switch (message.type) {
|
|
@@ -1028,8 +1082,14 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
1028
1082
|
(_k = (_j = this.listeners).llmGatewayResponse) === null || _k === void 0 ? void 0 : _k.call(_j, message);
|
|
1029
1083
|
break;
|
|
1030
1084
|
}
|
|
1085
|
+
case "Warning": {
|
|
1086
|
+
const warning = message;
|
|
1087
|
+
console.warn(`Streaming warning (code=${warning.warning_code}): ${warning.warning}`);
|
|
1088
|
+
(_m = (_l = this.listeners).warning) === null || _m === void 0 ? void 0 : _m.call(_l, warning);
|
|
1089
|
+
break;
|
|
1090
|
+
}
|
|
1031
1091
|
case "Termination": {
|
|
1032
|
-
(
|
|
1092
|
+
(_o = this.sessionTerminatedResolve) === null || _o === void 0 ? void 0 : _o.call(this);
|
|
1033
1093
|
break;
|
|
1034
1094
|
}
|
|
1035
1095
|
}
|
|
@@ -1051,7 +1111,17 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
1051
1111
|
* @param config - The configuration parameters to update
|
|
1052
1112
|
*/
|
|
1053
1113
|
updateConfiguration(config) {
|
|
1054
|
-
const
|
|
1114
|
+
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"]);
|
|
1115
|
+
if (min_end_of_turn_silence_when_confident !== undefined) {
|
|
1116
|
+
if (min_turn_silence !== undefined) {
|
|
1117
|
+
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.");
|
|
1118
|
+
}
|
|
1119
|
+
else {
|
|
1120
|
+
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.");
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
const effective = min_turn_silence !== null && min_turn_silence !== void 0 ? min_turn_silence : min_end_of_turn_silence_when_confident;
|
|
1124
|
+
const message = Object.assign(Object.assign({ type: "UpdateConfiguration" }, rest), (effective !== undefined ? { min_turn_silence: effective } : {}));
|
|
1055
1125
|
this.send(JSON.stringify(message));
|
|
1056
1126
|
}
|
|
1057
1127
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).assemblyai={})}(this,(function(e){"use strict";function t(e,t,s,i){return new(s||(s=Promise))((function(n,r){function o(e){try{l(i.next(e))}catch(e){r(e)}}function a(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s={cache:"no-store"};let i="";"undefined"!=typeof navigator&&navigator.userAgent&&(i+=navigator.userAgent);const n={sdk:{name:"JavaScript",version:"4.30.0"}};"undefined"!=typeof process&&(process.versions.node&&-1===i.indexOf("Node")&&(n.runtime_env={name:"Node",version:process.versions.node}),process.versions.bun&&-1===i.indexOf("Bun")&&(n.runtime_env={name:"Bun",version:process.versions.bun})),"undefined"!=typeof Deno&&process.versions.bun&&-1===i.indexOf("Deno")&&(n.runtime_env={name:"Deno",version:Deno.version.deno});class r{constructor(e){var t;this.params=e,!1===e.userAgent?this.userAgent=void 0:this.userAgent=(t=e.userAgent||{},i+(!1===t?"":" AssemblyAI/1.0 ("+Object.entries(Object.assign(Object.assign({},n),t)).map((([e,t])=>t?`${e}=${t.name}/${t.version}`:"")).join(" ")+")"))}fetch(e,i){return t(this,void 0,void 0,(function*(){i=Object.assign(Object.assign({},s),i);let t={Authorization:this.params.apiKey,"Content-Type":"application/json"};(null==s?void 0:s.headers)&&(t=Object.assign(Object.assign({},t),s.headers)),(null==i?void 0:i.headers)&&(t=Object.assign(Object.assign({},t),i.headers)),this.userAgent&&(t["User-Agent"]=this.userAgent,"undefined"!=typeof window&&"chrome"in window&&(t["AssemblyAI-Agent"]=this.userAgent)),i.headers=t,e.startsWith("http")||(e=this.params.baseUrl+e);const n=yield fetch(e,i);if(n.status>=400){let e;const t=yield n.text();if(t){try{e=JSON.parse(t)}catch(e){}if(null==e?void 0:e.error)throw new Error(e.error);throw new Error(t)}throw new Error(`HTTP Error: ${n.status} ${n.statusText}`)}return n}))}fetchJson(e,s){return t(this,void 0,void 0,(function*(){return(yield this.fetch(e,s)).json()}))}}class o extends r{summary(e,t){return this.fetchJson("/lemur/v3/generate/summary",{method:"POST",body:JSON.stringify(e),signal:t})}questionAnswer(e,t){return this.fetchJson("/lemur/v3/generate/question-answer",{method:"POST",body:JSON.stringify(e),signal:t})}actionItems(e,t){return this.fetchJson("/lemur/v3/generate/action-items",{method:"POST",body:JSON.stringify(e),signal:t})}task(e,t){return this.fetchJson("/lemur/v3/generate/task",{method:"POST",body:JSON.stringify(e),signal:t})}getResponse(e,t){return this.fetchJson(`/lemur/v3/${e}`,{signal:t})}purgeRequestData(e,t){return this.fetchJson(`/lemur/v3/${e}`,{method:"DELETE",signal:t})}}const{WritableStream:a}="undefined"!=typeof window?window:"undefined"!=typeof global?global:globalThis;var l,c;const d=null!==(c=null!==(l=null!==WebSocket&&void 0!==WebSocket?WebSocket:null===global||void 0===global?void 0:global.WebSocket)&&void 0!==l?l:null===window||void 0===window?void 0:window.WebSocket)&&void 0!==c?c:null===self||void 0===self?void 0:self.WebSocket,h=(e,t)=>t?new d(e,t):new d(e),u={[4e3]:"Sample rate must be a positive integer",[4001]:"Not Authorized",[4002]:"Insufficient funds",[4003]:"This feature is paid-only and requires you to add a credit card. Please visit https://app.assemblyai.com/ to add a credit card to your account.",[4004]:"Session ID does not exist",[4008]:"Session has expired",[4010]:"Session is closed",[4029]:"Rate limited",[4030]:"Unique session violation",[4031]:"Session Timeout",[4032]:"Audio too short",[4033]:"Audio too long",[4034]:"Audio too small to transcode",[4100]:"Bad JSON",[4101]:"Bad schema",[4102]:"Too many streams",[4103]:"This session has been reconnected. This WebSocket is no longer valid.",[1013]:"Reconnect attempts exhausted",[4104]:"Could not parse word boost parameter"};class p extends Error{}const m={[4e3]:"Sample rate must be a positive integer",[4001]:"Not Authorized",[4002]:"Insufficient funds",[4003]:"This feature is paid-only and requires you to add a credit card. Please visit https://app.assemblyai.com/ to add a credit card to your account.",[4004]:"Session ID does not exist",[4008]:"Session has expired",[4010]:"Session is closed",[4029]:"Rate limited",[4030]:"Unique session violation",[4031]:"Session Timeout",[4032]:"Audio too short",[4033]:"Audio too long",[4034]:"Audio too small to transcode",[4101]:"Bad schema",[4102]:"Too many streams",[4103]:"This session has been reconnected. This WebSocket is no longer valid."};class f extends Error{}const v='{"terminate_session":true}';class y{constructor(e){var t,s;if(this.listeners={},this.realtimeUrl=null!==(t=e.realtimeUrl)&&void 0!==t?t:"wss://api.assemblyai.com/v2/realtime/ws",this.sampleRate=null!==(s=e.sampleRate)&&void 0!==s?s:16e3,this.wordBoost=e.wordBoost,this.encoding=e.encoding,this.endUtteranceSilenceThreshold=e.endUtteranceSilenceThreshold,this.disablePartialTranscripts=e.disablePartialTranscripts,"token"in e&&e.token&&(this.token=e.token),"apiKey"in e&&e.apiKey&&(this.apiKey=e.apiKey),!this.token&&!this.apiKey)throw new Error("API key or temporary token is required.")}connectionUrl(){const e=new URL(this.realtimeUrl);if("wss:"!==e.protocol)throw new Error("Invalid protocol, must be wss");const t=new URLSearchParams;return this.token&&t.set("token",this.token),t.set("sample_rate",this.sampleRate.toString()),this.wordBoost&&this.wordBoost.length>0&&t.set("word_boost",JSON.stringify(this.wordBoost)),this.encoding&&t.set("encoding",this.encoding),t.set("enable_extra_session_information","true"),this.disablePartialTranscripts&&t.set("disable_partial_transcripts",this.disablePartialTranscripts.toString()),e.search=t.toString(),e}on(e,t){this.listeners[e]=t}connect(){return new Promise((e=>{if(this.socket)throw new Error("Already connected");const t=this.connectionUrl();this.token?this.socket=h(t.toString()):(console.warn("API key authentication is not supported for the RealtimeTranscriber in browser environment. Use temporary token authentication instead.\nLearn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/compat.md#browser-compatibility."),this.socket=h(t.toString(),{headers:{Authorization:this.apiKey}})),this.socket.binaryType="arraybuffer",this.socket.onopen=()=>{void 0!==this.endUtteranceSilenceThreshold&&null!==this.endUtteranceSilenceThreshold&&this.configureEndUtteranceSilenceThreshold(this.endUtteranceSilenceThreshold)},this.socket.onclose=({code:e,reason:t})=>{var s,i;t||e in u&&(t=u[e]),null===(i=(s=this.listeners).close)||void 0===i||i.call(s,e,t)},this.socket.onerror=e=>{var t,s,i,n;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(n=(i=this.listeners).error)||void 0===n||n.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,n,r,o,a,l,c,d,h,u,m,f,v,y;const g=JSON.parse(t.toString());if("error"in g)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new p(g.error));else switch(g.message_type){case"SessionBegins":{const t={sessionId:g.session_id,expiresAt:new Date(g.expires_at)};e(t),null===(r=(n=this.listeners).open)||void 0===r||r.call(n,t);break}case"PartialTranscript":g.created=new Date(g.created),null===(a=(o=this.listeners).transcript)||void 0===a||a.call(o,g),null===(c=(l=this.listeners)["transcript.partial"])||void 0===c||c.call(l,g);break;case"FinalTranscript":g.created=new Date(g.created),null===(h=(d=this.listeners).transcript)||void 0===h||h.call(d,g),null===(m=(u=this.listeners)["transcript.final"])||void 0===m||m.call(u,g);break;case"SessionInformation":null===(v=(f=this.listeners).session_information)||void 0===v||v.call(f,g);break;case"SessionTerminated":null===(y=this.sessionTerminatedResolve)||void 0===y||y.call(this)}}}))}sendAudio(e){this.send(e)}stream(){return new a({write:e=>{this.sendAudio(e)}})}forceEndUtterance(){this.send('{"force_end_utterance":true}')}configureEndUtteranceSilenceThreshold(e){this.send(`{"end_utterance_silence_threshold":${e}}`)}send(e){if(!this.socket||this.socket.readyState!==this.socket.OPEN)throw new Error("Socket is not open for communication");this.socket.send(e)}close(){return t(this,arguments,void 0,(function*(e=!0){var t;if(this.socket){if(this.socket.readyState===this.socket.OPEN)if(e){const e=new Promise((e=>{this.sessionTerminatedResolve=e}));this.socket.send(v),yield e}else this.socket.send(v);(null===(t=this.socket)||void 0===t?void 0:t.removeAllListeners)&&this.socket.removeAllListeners(),this.socket.close()}this.listeners={},this.socket=void 0}))}}class g extends r{constructor(e){super(e),this.rtFactoryParams=e}createService(e){return this.transcriber(e)}transcriber(e){const t=Object.assign({},e);return t.token||t.apiKey||(t.apiKey=this.rtFactoryParams.apiKey),new y(t)}createTemporaryToken(e){return t(this,void 0,void 0,(function*(){return(yield this.fetchJson("/v2/realtime/token",{method:"POST",body:JSON.stringify(e)})).token}))}}function b(e){return e.startsWith("http")||e.startsWith("https")||e.startsWith("data:")?null:e.startsWith("file://")?e.substring(7):e.startsWith("file:")?e.substring(5):e}class w extends r{constructor(e,t){super(e),this.files=t}transcribe(e,s){return t(this,void 0,void 0,(function*(){const t=yield this.submit(e);return yield this.waitUntilReady(t.id,s)}))}submit(e){return t(this,void 0,void 0,(function*(){let t,s;if("audio"in e){const{audio:i}=e,n=function(e,t){var s={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(s[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(s[i[n]]=e[i[n]])}return s}(e,["audio"]);if("string"==typeof i){const e=b(i);t=null!==e?yield this.files.upload(e):i.startsWith("data:")?yield this.files.upload(i):i}else t=yield this.files.upload(i);s=Object.assign(Object.assign({},n),{audio_url:t})}else s=e;return yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(s)})}))}create(e,s){return t(this,void 0,void 0,(function*(){var t;const i=b(e.audio_url);if(null!==i){const t=yield this.files.upload(i);e.audio_url=t}const n=yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(e)});return null===(t=null==s?void 0:s.poll)||void 0===t||t?yield this.waitUntilReady(n.id,s):n}))}waitUntilReady(e,s){return t(this,void 0,void 0,(function*(){var t,i;const n=null!==(t=null==s?void 0:s.pollingInterval)&&void 0!==t?t:3e3,r=null!==(i=null==s?void 0:s.pollingTimeout)&&void 0!==i?i:-1,o=Date.now();for(;;){const t=yield this.get(e);if("completed"===t.status||"error"===t.status)return t;if(r>0&&Date.now()-o>r)throw new Error("Polling timeout");yield new Promise((e=>setTimeout(e,n)))}}))}get(e){return this.fetchJson(`/v2/transcript/${e}`)}list(e){return t(this,void 0,void 0,(function*(){let t="/v2/transcript";"string"==typeof e?t=e:e&&(t=`${t}?${new URLSearchParams(Object.keys(e).map((t=>{var s;return[t,(null===(s=e[t])||void 0===s?void 0:s.toString())||""]})))}`);const s=yield this.fetchJson(t);for(const e of s.transcripts)e.created=new Date(e.created),e.completed&&(e.completed=new Date(e.completed));return s}))}delete(e){return this.fetchJson(`/v2/transcript/${e}`,{method:"DELETE"})}wordSearch(e,t){const s=new URLSearchParams({words:t.join(",")});return this.fetchJson(`/v2/transcript/${e}/word-search?${s.toString()}`)}sentences(e){return this.fetchJson(`/v2/transcript/${e}/sentences`)}paragraphs(e){return this.fetchJson(`/v2/transcript/${e}/paragraphs`)}subtitles(e){return t(this,arguments,void 0,(function*(e,t="srt",s){let i=`/v2/transcript/${e}/${t}`;if(s){const e=new URLSearchParams;e.set("chars_per_caption",s.toString()),i+=`?${e.toString()}`}const n=yield this.fetch(i);return yield n.text()}))}redactions(e){return this.redactedAudio(e)}redactedAudio(e){return this.fetchJson(`/v2/transcript/${e}/redacted-audio`)}redactedAudioFile(e){return t(this,void 0,void 0,(function*(){const{redacted_audio_url:t,status:s}=yield this.redactedAudio(e);if("redacted_audio_ready"!==s)throw new Error(`Redacted audio status is ${s}`);const i=yield fetch(t);if(!i.ok)throw new Error(`Failed to fetch redacted audio: ${i.statusText}`);return{arrayBuffer:i.arrayBuffer.bind(i),blob:i.blob.bind(i),body:i.body,bodyUsed:i.bodyUsed}}))}}class S extends r{upload(e){return t(this,void 0,void 0,(function*(){let s;s="string"==typeof e?e.startsWith("data:")?function(e){const t=e.split(","),s=t[0].match(/:(.*?);/)[1],i=atob(t[1]);let n=i.length;const r=new Uint8Array(n);for(;n--;)r[n]=i.charCodeAt(n);return new Blob([r],{type:s})}(e):yield function(e){return t(this,void 0,void 0,(function*(){throw new Error("Interacting with the file system is not supported in this environment.")}))}():e;return(yield this.fetchJson("/v2/upload",{method:"POST",body:s,headers:{"Content-Type":"application/octet-stream"},duplex:"half"})).upload_url}))}}const k='{"type":"Terminate"}';class T{constructor(e){if(this.listeners={},this.params=Object.assign(Object.assign({},e),{websocketBaseUrl:e.websocketBaseUrl||"wss://streaming.assemblyai.com/v3/ws"}),"token"in e&&e.token&&(this.token=e.token),"apiKey"in e&&e.apiKey&&(this.apiKey=e.apiKey),!this.token&&!this.apiKey)throw new Error("API key or temporary token is required.")}connectionUrl(){var e;const t=new URL(null!==(e=this.params.websocketBaseUrl)&&void 0!==e?e:"");if("wss:"!==t.protocol)throw new Error("Invalid protocol, must be wss");const s=new URLSearchParams;return this.token&&s.set("token",this.token),s.set("sample_rate",this.params.sampleRate.toString()),this.params.endOfTurnConfidenceThreshold&&s.set("end_of_turn_confidence_threshold",this.params.endOfTurnConfidenceThreshold.toString()),this.params.minTurnSilence?s.set("min_turn_silence",this.params.minTurnSilence.toString()):this.params.minEndOfTurnSilenceWhenConfident&&(console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead."),s.set("min_end_of_turn_silence_when_confident",this.params.minEndOfTurnSilenceWhenConfident.toString())),this.params.maxTurnSilence&&s.set("max_turn_silence",this.params.maxTurnSilence.toString()),void 0!==this.params.vadThreshold&&s.set("vad_threshold",this.params.vadThreshold.toString()),this.params.formatTurns&&s.set("format_turns",this.params.formatTurns.toString()),this.params.encoding&&s.set("encoding",this.params.encoding.toString()),this.params.keytermsPrompt?s.set("keyterms_prompt",JSON.stringify(this.params.keytermsPrompt)):this.params.keyterms&&(console.warn("[Deprecation Warning] `keyterms` is deprecated and will be removed in a future release. Please use `keytermsPrompt` instead."),s.set("keyterms_prompt",JSON.stringify(this.params.keyterms))),this.params.prompt&&s.set("prompt",this.params.prompt),this.params.filterProfanity&&s.set("filter_profanity",this.params.filterProfanity.toString()),"u3-pro"===this.params.speechModel&&console.warn("[Deprecation Warning] The speech model `u3-pro` is deprecated and will be removed in a future release. Please use `u3-rt-pro` instead."),s.set("speech_model",this.params.speechModel.toString()),void 0!==this.params.languageDetection&&s.set("language_detection",this.params.languageDetection.toString()),this.params.domain&&s.set("domain",this.params.domain),void 0!==this.params.inactivityTimeout&&s.set("inactivity_timeout",this.params.inactivityTimeout.toString()),void 0!==this.params.speakerLabels&&s.set("speaker_labels",this.params.speakerLabels.toString()),void 0!==this.params.maxSpeakers&&s.set("max_speakers",this.params.maxSpeakers.toString()),void 0!==this.params.llmGateway&&s.set("llm_gateway",JSON.stringify(this.params.llmGateway)),t.search=s.toString(),t}on(e,t){this.listeners[e]=t}connect(){return new Promise((e=>{if(this.socket)throw new Error("Already connected");const t=this.connectionUrl();this.token?this.socket=h(t.toString()):(console.warn("API key authentication is not supported for the StreamingTranscriber in browser environment. Use temporary token authentication instead.\nLearn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/compat.md#browser-compatibility."),this.socket=h(t.toString(),{headers:{Authorization:this.apiKey}})),this.socket.binaryType="arraybuffer",this.socket.onopen=()=>{},this.socket.onclose=({code:e,reason:t})=>{var s,i;t||e in m&&(t=m[e]),null===(i=(s=this.listeners).close)||void 0===i||i.call(s,e,t)},this.socket.onerror=e=>{var t,s,i,n;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(n=(i=this.listeners).error)||void 0===n||n.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,n,r,o,a,l,c,d,h,u;const p=JSON.parse(t.toString());if("error"in p)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new f(p.error));else switch(p.type){case"Begin":e(p),null===(r=(n=this.listeners).open)||void 0===r||r.call(n,p);break;case"Turn":null===(a=(o=this.listeners).turn)||void 0===a||a.call(o,p);break;case"SpeechStarted":null===(c=(l=this.listeners).speechStarted)||void 0===c||c.call(l,p);break;case"LLMGatewayResponse":null===(h=(d=this.listeners).llmGatewayResponse)||void 0===h||h.call(d,p);break;case"Termination":null===(u=this.sessionTerminatedResolve)||void 0===u||u.call(this)}}}))}stream(){return new a({write:e=>{this.sendAudio(e)}})}sendAudio(e){this.send(e)}updateConfiguration(e){const t=Object.assign({type:"UpdateConfiguration"},e);this.send(JSON.stringify(t))}forceEndpoint(){this.send(JSON.stringify({type:"ForceEndpoint"}))}send(e){if(!this.socket||this.socket.readyState!==this.socket.OPEN)throw new Error("Socket is not open for communication");this.socket.send(e)}close(){return t(this,arguments,void 0,(function*(e=!0){var t;if(this.socket){if(this.socket.readyState===this.socket.OPEN)if(e){const e=new Promise((e=>{this.sessionTerminatedResolve=e}));this.socket.send(k),yield e}else this.socket.send(k);(null===(t=this.socket)||void 0===t?void 0:t.removeAllListeners)&&this.socket.removeAllListeners(),this.socket.close()}this.listeners={},this.socket=void 0}))}}class O extends r{constructor(e){super(e),this.baseServiceParams=e}transcriber(e){const t=Object.assign({},e);return t.token||t.apiKey||(t.apiKey=this.baseServiceParams.apiKey),new T(t)}createTemporaryToken(e){return t(this,void 0,void 0,(function*(){const t=new URLSearchParams;Object.entries(e).forEach((([e,s])=>{null!=s&&t.append(e,String(s))}));const s=t.toString(),i=s?`/v3/token?${s}`:"/v3/token";return(yield this.fetchJson(i,{method:"GET"})).token}))}}e.AssemblyAI=class{constructor(e){e.baseUrl=e.baseUrl||"https://api.assemblyai.com",e.baseUrl&&e.baseUrl.endsWith("/")&&(e.baseUrl=e.baseUrl.slice(0,-1)),this.files=new S(e),this.transcripts=new w(e,this.files),this.lemur=new o(e),this.realtime=new g(e),this.streaming=new O(Object.assign(Object.assign({},e),{baseUrl:e.streamingBaseUrl||"https://streaming.assemblyai.com"}))}},e.FileService=S,e.LemurService=o,e.RealtimeService=class extends y{},e.RealtimeServiceFactory=class extends g{},e.RealtimeTranscriber=y,e.RealtimeTranscriberFactory=g,e.StreamingTranscriber=T,e.TranscriptService=w}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).assemblyai={})}(this,(function(e){"use strict";function t(e,t){var s={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(s[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(s[i[n]]=e[i[n]])}return s}function s(e,t,s,i){return new(s||(s=Promise))((function(n,r){function o(e){try{c(i.next(e))}catch(e){r(e)}}function a(e){try{c(i.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}c((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const i={cache:"no-store"};let n="";"undefined"!=typeof navigator&&navigator.userAgent&&(n+=navigator.userAgent);const r={sdk:{name:"JavaScript",version:"4.33.0"}};"undefined"!=typeof process&&(process.versions.node&&-1===n.indexOf("Node")&&(r.runtime_env={name:"Node",version:process.versions.node}),process.versions.bun&&-1===n.indexOf("Bun")&&(r.runtime_env={name:"Bun",version:process.versions.bun})),"undefined"!=typeof Deno&&process.versions.bun&&-1===n.indexOf("Deno")&&(r.runtime_env={name:"Deno",version:Deno.version.deno});class o{constructor(e){var t;this.params=e,!1===e.userAgent?this.userAgent=void 0:this.userAgent=(t=e.userAgent||{},n+(!1===t?"":" AssemblyAI/1.0 ("+Object.entries(Object.assign(Object.assign({},r),t)).map((([e,t])=>t?`${e}=${t.name}/${t.version}`:"")).join(" ")+")"))}fetch(e,t){return s(this,void 0,void 0,(function*(){t=Object.assign(Object.assign({},i),t);let s={Authorization:this.params.apiKey,"Content-Type":"application/json"};(null==i?void 0:i.headers)&&(s=Object.assign(Object.assign({},s),i.headers)),(null==t?void 0:t.headers)&&(s=Object.assign(Object.assign({},s),t.headers)),this.userAgent&&(s["User-Agent"]=this.userAgent,"undefined"!=typeof window&&"chrome"in window&&(s["AssemblyAI-Agent"]=this.userAgent)),t.headers=s,e.startsWith("http")||(e=this.params.baseUrl+e);const n=yield fetch(e,t);if(n.status>=400){let e;const t=yield n.text();if(t){try{e=JSON.parse(t)}catch(e){}if(null==e?void 0:e.error)throw new Error(e.error);throw new Error(t)}throw new Error(`HTTP Error: ${n.status} ${n.statusText}`)}return n}))}fetchJson(e,t){return s(this,void 0,void 0,(function*(){return(yield this.fetch(e,t)).json()}))}}class a extends o{summary(e,t){return this.fetchJson("/lemur/v3/generate/summary",{method:"POST",body:JSON.stringify(e),signal:t})}questionAnswer(e,t){return this.fetchJson("/lemur/v3/generate/question-answer",{method:"POST",body:JSON.stringify(e),signal:t})}actionItems(e,t){return this.fetchJson("/lemur/v3/generate/action-items",{method:"POST",body:JSON.stringify(e),signal:t})}task(e,t){return this.fetchJson("/lemur/v3/generate/task",{method:"POST",body:JSON.stringify(e),signal:t})}getResponse(e,t){return this.fetchJson(`/lemur/v3/${e}`,{signal:t})}purgeRequestData(e,t){return this.fetchJson(`/lemur/v3/${e}`,{method:"DELETE",signal:t})}}const{WritableStream:c}="undefined"!=typeof window?window:"undefined"!=typeof global?global:globalThis;var l,d;const h=null!==(d=null!==(l=null!==WebSocket&&void 0!==WebSocket?WebSocket:null===global||void 0===global?void 0:global.WebSocket)&&void 0!==l?l:null===window||void 0===window?void 0:window.WebSocket)&&void 0!==d?d:null===self||void 0===self?void 0:self.WebSocket,u=(e,t)=>t?new h(e,t):new h(e),p={[4e3]:"Sample rate must be a positive integer",[4001]:"Not Authorized",[4002]:"Insufficient funds",[4003]:"This feature is paid-only and requires you to add a credit card. Please visit https://app.assemblyai.com/ to add a credit card to your account.",[4004]:"Session ID does not exist",[4008]:"Session has expired",[4010]:"Session is closed",[4029]:"Rate limited",[4030]:"Unique session violation",[4031]:"Session Timeout",[4032]:"Audio too short",[4033]:"Audio too long",[4034]:"Audio too small to transcode",[4100]:"Bad JSON",[4101]:"Bad schema",[4102]:"Too many streams",[4103]:"This session has been reconnected. This WebSocket is no longer valid.",[1013]:"Reconnect attempts exhausted",[4104]:"Could not parse word boost parameter"};class m extends Error{}const f={[3005]:"Server error",[3006]:"Input validation error",[3007]:"Audio chunk duration violation",[3008]:"Session expired: maximum session duration exceeded",[3009]:"Too many concurrent sessions",[4e3]:"Sample rate must be a positive integer",[4001]:"Not Authorized",[4002]:"Insufficient funds",[4003]:"This feature is paid-only and requires you to add a credit card. Please visit https://app.assemblyai.com/ to add a credit card to your account.",[4004]:"Session ID does not exist",[4008]:"Session has expired",[4010]:"Session is closed",[4029]:"Rate limited",[4030]:"Unique session violation",[4031]:"Session Timeout",[4032]:"Audio too short",[4033]:"Audio too long",[4034]:"Audio too small to transcode",[4101]:"Bad schema",[4102]:"Too many streams",[4103]:"This session has been reconnected. This WebSocket is no longer valid."};class v extends Error{}const y='{"terminate_session":true}';class g{constructor(e){var t,s;if(this.listeners={},this.realtimeUrl=null!==(t=e.realtimeUrl)&&void 0!==t?t:"wss://api.assemblyai.com/v2/realtime/ws",this.sampleRate=null!==(s=e.sampleRate)&&void 0!==s?s:16e3,this.wordBoost=e.wordBoost,this.encoding=e.encoding,this.endUtteranceSilenceThreshold=e.endUtteranceSilenceThreshold,this.disablePartialTranscripts=e.disablePartialTranscripts,"token"in e&&e.token&&(this.token=e.token),"apiKey"in e&&e.apiKey&&(this.apiKey=e.apiKey),!this.token&&!this.apiKey)throw new Error("API key or temporary token is required.")}connectionUrl(){const e=new URL(this.realtimeUrl);if("wss:"!==e.protocol)throw new Error("Invalid protocol, must be wss");const t=new URLSearchParams;return this.token&&t.set("token",this.token),t.set("sample_rate",this.sampleRate.toString()),this.wordBoost&&this.wordBoost.length>0&&t.set("word_boost",JSON.stringify(this.wordBoost)),this.encoding&&t.set("encoding",this.encoding),t.set("enable_extra_session_information","true"),this.disablePartialTranscripts&&t.set("disable_partial_transcripts",this.disablePartialTranscripts.toString()),e.search=t.toString(),e}on(e,t){this.listeners[e]=t}connect(){return new Promise((e=>{if(this.socket)throw new Error("Already connected");const t=this.connectionUrl();this.token?this.socket=u(t.toString()):(console.warn("API key authentication is not supported for the RealtimeTranscriber in browser environment. Use temporary token authentication instead.\nLearn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/compat.md#browser-compatibility."),this.socket=u(t.toString(),{headers:{Authorization:this.apiKey}})),this.socket.binaryType="arraybuffer",this.socket.onopen=()=>{void 0!==this.endUtteranceSilenceThreshold&&null!==this.endUtteranceSilenceThreshold&&this.configureEndUtteranceSilenceThreshold(this.endUtteranceSilenceThreshold)},this.socket.onclose=({code:e,reason:t})=>{var s,i;t||e in p&&(t=p[e]),null===(i=(s=this.listeners).close)||void 0===i||i.call(s,e,t)},this.socket.onerror=e=>{var t,s,i,n;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(n=(i=this.listeners).error)||void 0===n||n.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,n,r,o,a,c,l,d,h,u,p,f,v,y;const g=JSON.parse(t.toString());if("error"in g)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new m(g.error));else switch(g.message_type){case"SessionBegins":{const t={sessionId:g.session_id,expiresAt:new Date(g.expires_at)};e(t),null===(r=(n=this.listeners).open)||void 0===r||r.call(n,t);break}case"PartialTranscript":g.created=new Date(g.created),null===(a=(o=this.listeners).transcript)||void 0===a||a.call(o,g),null===(l=(c=this.listeners)["transcript.partial"])||void 0===l||l.call(c,g);break;case"FinalTranscript":g.created=new Date(g.created),null===(h=(d=this.listeners).transcript)||void 0===h||h.call(d,g),null===(p=(u=this.listeners)["transcript.final"])||void 0===p||p.call(u,g);break;case"SessionInformation":null===(v=(f=this.listeners).session_information)||void 0===v||v.call(f,g);break;case"SessionTerminated":null===(y=this.sessionTerminatedResolve)||void 0===y||y.call(this)}}}))}sendAudio(e){this.send(e)}stream(){return new c({write:e=>{this.sendAudio(e)}})}forceEndUtterance(){this.send('{"force_end_utterance":true}')}configureEndUtteranceSilenceThreshold(e){this.send(`{"end_utterance_silence_threshold":${e}}`)}send(e){if(!this.socket||this.socket.readyState!==this.socket.OPEN)throw new Error("Socket is not open for communication");this.socket.send(e)}close(){return s(this,arguments,void 0,(function*(e=!0){var t;if(this.socket){if(this.socket.readyState===this.socket.OPEN)if(e){const e=new Promise((e=>{this.sessionTerminatedResolve=e}));this.socket.send(y),yield e}else this.socket.send(y);(null===(t=this.socket)||void 0===t?void 0:t.removeAllListeners)&&this.socket.removeAllListeners(),this.socket.close()}this.listeners={},this.socket=void 0}))}}class b extends o{constructor(e){super(e),this.rtFactoryParams=e}createService(e){return this.transcriber(e)}transcriber(e){const t=Object.assign({},e);return t.token||t.apiKey||(t.apiKey=this.rtFactoryParams.apiKey),new g(t)}createTemporaryToken(e){return s(this,void 0,void 0,(function*(){return(yield this.fetchJson("/v2/realtime/token",{method:"POST",body:JSON.stringify(e)})).token}))}}function w(e){return e.startsWith("http")||e.startsWith("https")||e.startsWith("data:")?null:e.startsWith("file://")?e.substring(7):e.startsWith("file:")?e.substring(5):e}class S extends o{constructor(e,t){super(e),this.files=t}transcribe(e,t){return s(this,void 0,void 0,(function*(){const s=yield this.submit(e);return yield this.waitUntilReady(s.id,t)}))}submit(e){return s(this,void 0,void 0,(function*(){let s,i;if("audio"in e){const{audio:n}=e,r=t(e,["audio"]);if("string"==typeof n){const e=w(n);s=null!==e?yield this.files.upload(e):n.startsWith("data:")?yield this.files.upload(n):n}else s=yield this.files.upload(n);i=Object.assign(Object.assign({},r),{audio_url:s})}else i=e;return yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(i)})}))}create(e,t){return s(this,void 0,void 0,(function*(){var s;const i=w(e.audio_url);if(null!==i){const t=yield this.files.upload(i);e.audio_url=t}const n=yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(e)});return null===(s=null==t?void 0:t.poll)||void 0===s||s?yield this.waitUntilReady(n.id,t):n}))}waitUntilReady(e,t){return s(this,void 0,void 0,(function*(){var s,i;const n=null!==(s=null==t?void 0:t.pollingInterval)&&void 0!==s?s:3e3,r=null!==(i=null==t?void 0:t.pollingTimeout)&&void 0!==i?i:-1,o=Date.now();for(;;){const t=yield this.get(e);if("completed"===t.status||"error"===t.status)return t;if(r>0&&Date.now()-o>r)throw new Error("Polling timeout");yield new Promise((e=>setTimeout(e,n)))}}))}get(e){return this.fetchJson(`/v2/transcript/${e}`)}list(e){return s(this,void 0,void 0,(function*(){let t="/v2/transcript";"string"==typeof e?t=e:e&&(t=`${t}?${new URLSearchParams(Object.keys(e).map((t=>{var s;return[t,(null===(s=e[t])||void 0===s?void 0:s.toString())||""]})))}`);const s=yield this.fetchJson(t);for(const e of s.transcripts)e.created=new Date(e.created),e.completed&&(e.completed=new Date(e.completed));return s}))}delete(e){return this.fetchJson(`/v2/transcript/${e}`,{method:"DELETE"})}wordSearch(e,t){const s=new URLSearchParams({words:t.join(",")});return this.fetchJson(`/v2/transcript/${e}/word-search?${s.toString()}`)}sentences(e){return this.fetchJson(`/v2/transcript/${e}/sentences`)}paragraphs(e){return this.fetchJson(`/v2/transcript/${e}/paragraphs`)}subtitles(e){return s(this,arguments,void 0,(function*(e,t="srt",s){let i=`/v2/transcript/${e}/${t}`;if(s){const e=new URLSearchParams;e.set("chars_per_caption",s.toString()),i+=`?${e.toString()}`}const n=yield this.fetch(i);return yield n.text()}))}redactions(e){return this.redactedAudio(e)}redactedAudio(e){return this.fetchJson(`/v2/transcript/${e}/redacted-audio`)}redactedAudioFile(e){return s(this,void 0,void 0,(function*(){const{redacted_audio_url:t,status:s}=yield this.redactedAudio(e);if("redacted_audio_ready"!==s)throw new Error(`Redacted audio status is ${s}`);const i=yield fetch(t);if(!i.ok)throw new Error(`Failed to fetch redacted audio: ${i.statusText}`);return{arrayBuffer:i.arrayBuffer.bind(i),blob:i.blob.bind(i),body:i.body,bodyUsed:i.bodyUsed}}))}}class k extends o{upload(e){return s(this,void 0,void 0,(function*(){let t;t="string"==typeof e?e.startsWith("data:")?function(e){const t=e.split(","),s=t[0].match(/:(.*?);/)[1],i=atob(t[1]);let n=i.length;const r=new Uint8Array(n);for(;n--;)r[n]=i.charCodeAt(n);return new Blob([r],{type:s})}(e):yield function(e){return s(this,void 0,void 0,(function*(){throw new Error("Interacting with the file system is not supported in this environment.")}))}():e;return(yield this.fetchJson("/v2/upload",{method:"POST",body:t,headers:{"Content-Type":"application/octet-stream"},duplex:"half"})).upload_url}))}}const _='{"type":"Terminate"}';class T{constructor(e){if(this.listeners={},this.params=Object.assign(Object.assign({},e),{websocketBaseUrl:e.websocketBaseUrl||"wss://streaming.assemblyai.com/v3/ws"}),"token"in e&&e.token&&(this.token=e.token),"apiKey"in e&&e.apiKey&&(this.apiKey=e.apiKey),!this.token&&!this.apiKey)throw new Error("API key or temporary token is required.")}connectionUrl(){var e,t;const s=new URL(null!==(e=this.params.websocketBaseUrl)&&void 0!==e?e:"");if("wss:"!==s.protocol)throw new Error("Invalid protocol, must be wss");const i=new URLSearchParams;this.token&&i.set("token",this.token),i.set("sample_rate",this.params.sampleRate.toString()),this.params.endOfTurnConfidenceThreshold&&i.set("end_of_turn_confidence_threshold",this.params.endOfTurnConfidenceThreshold.toString()),void 0!==this.params.minEndOfTurnSilenceWhenConfident&&(void 0!==this.params.minTurnSilence?console.warn("[Deprecation Warning] Both `minEndOfTurnSilenceWhenConfident` and `minTurnSilence` are set. Using `minTurnSilence`; `minEndOfTurnSilenceWhenConfident` is deprecated."):console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead."));const n=null!==(t=this.params.minTurnSilence)&&void 0!==t?t:this.params.minEndOfTurnSilenceWhenConfident;return void 0!==n&&i.set("min_turn_silence",n.toString()),this.params.maxTurnSilence&&i.set("max_turn_silence",this.params.maxTurnSilence.toString()),void 0!==this.params.vadThreshold&&i.set("vad_threshold",this.params.vadThreshold.toString()),this.params.formatTurns&&i.set("format_turns",this.params.formatTurns.toString()),this.params.encoding&&i.set("encoding",this.params.encoding.toString()),this.params.keytermsPrompt?i.set("keyterms_prompt",JSON.stringify(this.params.keytermsPrompt)):this.params.keyterms&&(console.warn("[Deprecation Warning] `keyterms` is deprecated and will be removed in a future release. Please use `keytermsPrompt` instead."),i.set("keyterms_prompt",JSON.stringify(this.params.keyterms))),this.params.prompt&&i.set("prompt",this.params.prompt),this.params.filterProfanity&&i.set("filter_profanity",this.params.filterProfanity.toString()),"u3-pro"===this.params.speechModel&&console.warn("[Deprecation Warning] The speech model `u3-pro` is deprecated and will be removed in a future release. Please use `u3-rt-pro` instead."),i.set("speech_model",this.params.speechModel.toString()),void 0!==this.params.languageDetection&&i.set("language_detection",this.params.languageDetection.toString()),this.params.domain&&i.set("domain",this.params.domain),void 0!==this.params.inactivityTimeout&&i.set("inactivity_timeout",this.params.inactivityTimeout.toString()),void 0!==this.params.speakerLabels&&i.set("speaker_labels",this.params.speakerLabels.toString()),void 0!==this.params.maxSpeakers&&i.set("max_speakers",this.params.maxSpeakers.toString()),this.params.voiceFocus&&i.set("voice_focus",this.params.voiceFocus),void 0!==this.params.voiceFocusThreshold&&i.set("voice_focus_threshold",this.params.voiceFocusThreshold.toString()),void 0!==this.params.continuousPartials&&i.set("continuous_partials",this.params.continuousPartials.toString()),this.params.customerSupportAudioCapture&&(console.warn("`customerSupportAudioCapture=true` will record session audio. Only enable this when explicitly coordinating with AssemblyAI support."),i.set("customer_support_audio_capture",this.params.customerSupportAudioCapture.toString())),this.params.webhookUrl&&i.set("webhook_url",this.params.webhookUrl),this.params.webhookAuthHeaderName&&i.set("webhook_auth_header_name",this.params.webhookAuthHeaderName),this.params.webhookAuthHeaderValue&&i.set("webhook_auth_header_value",this.params.webhookAuthHeaderValue),void 0!==this.params.includePartialTurns&&i.set("include_partial_turns",this.params.includePartialTurns.toString()),void 0!==this.params.redactPii&&i.set("redact_pii",this.params.redactPii.toString()),void 0!==this.params.redactPiiPolicies&&i.set("redact_pii_policies",JSON.stringify(this.params.redactPiiPolicies)),void 0!==this.params.redactPiiSub&&i.set("redact_pii_sub",this.params.redactPiiSub),void 0!==this.params.llmGateway&&i.set("llm_gateway",JSON.stringify(this.params.llmGateway)),s.search=i.toString(),s}on(e,t){this.listeners[e]=t}connect(){return new Promise((e=>{if(this.socket)throw new Error("Already connected");const t=this.connectionUrl();this.token?this.socket=u(t.toString()):(console.warn("API key authentication is not supported for the StreamingTranscriber in browser environment. Use temporary token authentication instead.\nLearn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/compat.md#browser-compatibility."),this.socket=u(t.toString(),{headers:{Authorization:this.apiKey}})),this.socket.binaryType="arraybuffer",this.socket.onopen=()=>{},this.socket.onclose=({code:e,reason:t})=>{var s,i;t||e in f&&(t=f[e]),null===(i=(s=this.listeners).close)||void 0===i||i.call(s,e,t)},this.socket.onerror=e=>{var t,s,i,n;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(n=(i=this.listeners).error)||void 0===n||n.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,n,r,o,a,c,l,d,h,u,p,m;const f=JSON.parse(t.toString());if("error"in f){const e=new v(f.error);return"error_code"in f&&(e.code=f.error_code),void(null===(i=(s=this.listeners).error)||void 0===i||i.call(s,e))}switch(f.type){case"Begin":e(f),null===(r=(n=this.listeners).open)||void 0===r||r.call(n,f);break;case"Turn":null===(a=(o=this.listeners).turn)||void 0===a||a.call(o,f);break;case"SpeechStarted":null===(l=(c=this.listeners).speechStarted)||void 0===l||l.call(c,f);break;case"LLMGatewayResponse":null===(h=(d=this.listeners).llmGatewayResponse)||void 0===h||h.call(d,f);break;case"Warning":{const e=f;console.warn(`Streaming warning (code=${e.warning_code}): ${e.warning}`),null===(p=(u=this.listeners).warning)||void 0===p||p.call(u,e);break}case"Termination":null===(m=this.sessionTerminatedResolve)||void 0===m||m.call(this)}}}))}stream(){return new c({write:e=>{this.sendAudio(e)}})}sendAudio(e){this.send(e)}updateConfiguration(e){const{min_end_of_turn_silence_when_confident:s,min_turn_silence:i}=e,n=t(e,["min_end_of_turn_silence_when_confident","min_turn_silence"]);void 0!==s&&(void 0!==i?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."):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."));const r=null!=i?i:s,o=Object.assign(Object.assign({type:"UpdateConfiguration"},n),void 0!==r?{min_turn_silence:r}:{});this.send(JSON.stringify(o))}forceEndpoint(){this.send(JSON.stringify({type:"ForceEndpoint"}))}send(e){if(!this.socket||this.socket.readyState!==this.socket.OPEN)throw new Error("Socket is not open for communication");this.socket.send(e)}close(){return s(this,arguments,void 0,(function*(e=!0){var t;if(this.socket){if(this.socket.readyState===this.socket.OPEN)if(e){const e=new Promise((e=>{this.sessionTerminatedResolve=e}));this.socket.send(_),yield e}else this.socket.send(_);(null===(t=this.socket)||void 0===t?void 0:t.removeAllListeners)&&this.socket.removeAllListeners(),this.socket.close()}this.listeners={},this.socket=void 0}))}}class O extends o{constructor(e){super(e),this.baseServiceParams=e}transcriber(e){const t=Object.assign({},e);return t.token||t.apiKey||(t.apiKey=this.baseServiceParams.apiKey),new T(t)}createTemporaryToken(e){return s(this,void 0,void 0,(function*(){const t=new URLSearchParams;Object.entries(e).forEach((([e,s])=>{null!=s&&t.append(e,String(s))}));const s=t.toString(),i=s?`/v3/token?${s}`:"/v3/token";return(yield this.fetchJson(i,{method:"GET"})).token}))}}e.AssemblyAI=class{constructor(e){e.baseUrl=e.baseUrl||"https://api.assemblyai.com",e.baseUrl&&e.baseUrl.endsWith("/")&&(e.baseUrl=e.baseUrl.slice(0,-1)),this.files=new k(e),this.transcripts=new S(e,this.files),this.lemur=new a(e),this.realtime=new b(e),this.streaming=new O(Object.assign(Object.assign({},e),{baseUrl:e.streamingBaseUrl||"https://streaming.assemblyai.com"}))}},e.FileService=k,e.LemurService=a,e.RealtimeService=class extends g{},e.RealtimeServiceFactory=class extends b{},e.RealtimeTranscriber=g,e.RealtimeTranscriberFactory=b,e.StreamingTranscriber=T,e.TranscriptService=S}));
|
package/dist/browser.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) {
|
|
@@ -233,8 +233,18 @@ const StreamingErrorType = {
|
|
|
233
233
|
BadSchema: 4101,
|
|
234
234
|
TooManyStreams: 4102,
|
|
235
235
|
Reconnected: 4103,
|
|
236
|
+
ServerError: 3005,
|
|
237
|
+
InputValidationError: 3006,
|
|
238
|
+
AudioChunkDurationViolation: 3007,
|
|
239
|
+
MaxSessionDurationExceeded: 3008,
|
|
240
|
+
ConcurrencyLimitExceeded: 3009,
|
|
236
241
|
};
|
|
237
242
|
const StreamingErrorMessages = {
|
|
243
|
+
[StreamingErrorType.ServerError]: "Server error",
|
|
244
|
+
[StreamingErrorType.InputValidationError]: "Input validation error",
|
|
245
|
+
[StreamingErrorType.AudioChunkDurationViolation]: "Audio chunk duration violation",
|
|
246
|
+
[StreamingErrorType.MaxSessionDurationExceeded]: "Session expired: maximum session duration exceeded",
|
|
247
|
+
[StreamingErrorType.ConcurrencyLimitExceeded]: "Too many concurrent sessions",
|
|
238
248
|
[StreamingErrorType.BadSampleRate]: "Sample rate must be a positive integer",
|
|
239
249
|
[StreamingErrorType.AuthFailed]: "Not Authorized",
|
|
240
250
|
[StreamingErrorType.InsufficientFunds]: "Insufficient funds",
|
|
@@ -821,12 +831,18 @@ class StreamingTranscriber {
|
|
|
821
831
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
822
832
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
823
833
|
}
|
|
824
|
-
if (this.params.
|
|
825
|
-
|
|
834
|
+
if (this.params.minEndOfTurnSilenceWhenConfident !== undefined) {
|
|
835
|
+
if (this.params.minTurnSilence !== undefined) {
|
|
836
|
+
console.warn("[Deprecation Warning] Both `minEndOfTurnSilenceWhenConfident` and `minTurnSilence` are set. Using `minTurnSilence`; `minEndOfTurnSilenceWhenConfident` is deprecated.");
|
|
837
|
+
}
|
|
838
|
+
else {
|
|
839
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
840
|
+
}
|
|
826
841
|
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
842
|
+
const effectiveMinTurnSilence = this.params.minTurnSilence ??
|
|
843
|
+
this.params.minEndOfTurnSilenceWhenConfident;
|
|
844
|
+
if (effectiveMinTurnSilence !== undefined) {
|
|
845
|
+
searchParams.set("min_turn_silence", effectiveMinTurnSilence.toString());
|
|
830
846
|
}
|
|
831
847
|
if (this.params.maxTurnSilence) {
|
|
832
848
|
searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
|
|
@@ -872,6 +888,40 @@ class StreamingTranscriber {
|
|
|
872
888
|
if (this.params.maxSpeakers !== undefined) {
|
|
873
889
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
874
890
|
}
|
|
891
|
+
if (this.params.voiceFocus) {
|
|
892
|
+
searchParams.set("voice_focus", this.params.voiceFocus);
|
|
893
|
+
}
|
|
894
|
+
if (this.params.voiceFocusThreshold !== undefined) {
|
|
895
|
+
searchParams.set("voice_focus_threshold", this.params.voiceFocusThreshold.toString());
|
|
896
|
+
}
|
|
897
|
+
if (this.params.continuousPartials !== undefined) {
|
|
898
|
+
searchParams.set("continuous_partials", this.params.continuousPartials.toString());
|
|
899
|
+
}
|
|
900
|
+
if (this.params.customerSupportAudioCapture) {
|
|
901
|
+
console.warn("`customerSupportAudioCapture=true` will record session audio. Only enable this when explicitly coordinating with AssemblyAI support.");
|
|
902
|
+
searchParams.set("customer_support_audio_capture", this.params.customerSupportAudioCapture.toString());
|
|
903
|
+
}
|
|
904
|
+
if (this.params.webhookUrl) {
|
|
905
|
+
searchParams.set("webhook_url", this.params.webhookUrl);
|
|
906
|
+
}
|
|
907
|
+
if (this.params.webhookAuthHeaderName) {
|
|
908
|
+
searchParams.set("webhook_auth_header_name", this.params.webhookAuthHeaderName);
|
|
909
|
+
}
|
|
910
|
+
if (this.params.webhookAuthHeaderValue) {
|
|
911
|
+
searchParams.set("webhook_auth_header_value", this.params.webhookAuthHeaderValue);
|
|
912
|
+
}
|
|
913
|
+
if (this.params.includePartialTurns !== undefined) {
|
|
914
|
+
searchParams.set("include_partial_turns", this.params.includePartialTurns.toString());
|
|
915
|
+
}
|
|
916
|
+
if (this.params.redactPii !== undefined) {
|
|
917
|
+
searchParams.set("redact_pii", this.params.redactPii.toString());
|
|
918
|
+
}
|
|
919
|
+
if (this.params.redactPiiPolicies !== undefined) {
|
|
920
|
+
searchParams.set("redact_pii_policies", JSON.stringify(this.params.redactPiiPolicies));
|
|
921
|
+
}
|
|
922
|
+
if (this.params.redactPiiSub !== undefined) {
|
|
923
|
+
searchParams.set("redact_pii_sub", this.params.redactPiiSub);
|
|
924
|
+
}
|
|
875
925
|
if (this.params.llmGateway !== undefined) {
|
|
876
926
|
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
877
927
|
}
|
|
@@ -919,7 +969,12 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
919
969
|
this.socket.onmessage = ({ data }) => {
|
|
920
970
|
const message = JSON.parse(data.toString());
|
|
921
971
|
if ("error" in message) {
|
|
922
|
-
|
|
972
|
+
const err = new StreamingError(message.error);
|
|
973
|
+
if ("error_code" in message) {
|
|
974
|
+
err.code =
|
|
975
|
+
message.error_code;
|
|
976
|
+
}
|
|
977
|
+
this.listeners.error?.(err);
|
|
923
978
|
return;
|
|
924
979
|
}
|
|
925
980
|
switch (message.type) {
|
|
@@ -940,6 +995,12 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
940
995
|
this.listeners.llmGatewayResponse?.(message);
|
|
941
996
|
break;
|
|
942
997
|
}
|
|
998
|
+
case "Warning": {
|
|
999
|
+
const warning = message;
|
|
1000
|
+
console.warn(`Streaming warning (code=${warning.warning_code}): ${warning.warning}`);
|
|
1001
|
+
this.listeners.warning?.(warning);
|
|
1002
|
+
break;
|
|
1003
|
+
}
|
|
943
1004
|
case "Termination": {
|
|
944
1005
|
this.sessionTerminatedResolve?.();
|
|
945
1006
|
break;
|
|
@@ -963,9 +1024,20 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
963
1024
|
* @param config - The configuration parameters to update
|
|
964
1025
|
*/
|
|
965
1026
|
updateConfiguration(config) {
|
|
1027
|
+
const { min_end_of_turn_silence_when_confident, min_turn_silence, ...rest } = config;
|
|
1028
|
+
if (min_end_of_turn_silence_when_confident !== undefined) {
|
|
1029
|
+
if (min_turn_silence !== undefined) {
|
|
1030
|
+
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.");
|
|
1031
|
+
}
|
|
1032
|
+
else {
|
|
1033
|
+
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.");
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
const effective = min_turn_silence ?? min_end_of_turn_silence_when_confident;
|
|
966
1037
|
const message = {
|
|
967
1038
|
type: "UpdateConfiguration",
|
|
968
|
-
...
|
|
1039
|
+
...rest,
|
|
1040
|
+
...(effective !== undefined ? { min_turn_silence: effective } : {}),
|
|
969
1041
|
};
|
|
970
1042
|
this.send(JSON.stringify(message));
|
|
971
1043
|
}
|
package/dist/bun.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
|
}
|