assemblyai 4.25.1 → 4.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/dist/assemblyai.umd.js +13 -8
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/browser.mjs +11 -6
- package/dist/bun.mjs +11 -6
- package/dist/deno.mjs +11 -6
- package/dist/index.cjs +13 -8
- package/dist/index.mjs +13 -8
- package/dist/node.cjs +11 -6
- package/dist/node.mjs +11 -6
- package/dist/services/streaming/service.d.ts +2 -1
- package/dist/types/streaming/index.d.ts +20 -3
- package/dist/workerd.mjs +11 -6
- package/package.json +1 -1
- package/src/services/streaming/service.ts +18 -7
- package/src/types/streaming/index.ts +23 -1
package/CHANGELOG.md
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
- Add `language_confidence_threshold` to `Transcript`, `TranscriptParams`, and `TranscriptOptionalParams`.
|
|
24
24
|
> The confidence threshold for the automatically detected language.
|
|
25
|
-
> An error will be returned if the
|
|
25
|
+
> An error will be returned if the language confidence is below this threshold.
|
|
26
26
|
- Add `language_confidence` to `Transcript`
|
|
27
27
|
> The confidence score for the detected language, between 0.0 (low confidence) and 1.0 (high confidence)
|
|
28
28
|
|
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.26.1" },
|
|
69
69
|
};
|
|
70
70
|
if (typeof process !== "undefined") {
|
|
71
71
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -938,12 +938,10 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
938
938
|
if (this.params.filterProfanity) {
|
|
939
939
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
940
940
|
}
|
|
941
|
-
if (this.params.speechModel) {
|
|
942
|
-
|
|
943
|
-
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.");
|
|
944
|
-
}
|
|
945
|
-
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
941
|
+
if (this.params.speechModel === "u3-pro") {
|
|
942
|
+
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.");
|
|
946
943
|
}
|
|
944
|
+
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
947
945
|
if (this.params.languageDetection !== undefined) {
|
|
948
946
|
searchParams.set("language_detection", this.params.languageDetection.toString());
|
|
949
947
|
}
|
|
@@ -956,6 +954,9 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
956
954
|
if (this.params.maxSpeakers !== undefined) {
|
|
957
955
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
958
956
|
}
|
|
957
|
+
if (this.params.llmGateway !== undefined) {
|
|
958
|
+
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
959
|
+
}
|
|
959
960
|
url.search = searchParams.toString();
|
|
960
961
|
return url;
|
|
961
962
|
}
|
|
@@ -1000,7 +1001,7 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
1000
1001
|
(_d = (_c = this.listeners).error) === null || _d === void 0 ? void 0 : _d.call(_c, new Error(event.message));
|
|
1001
1002
|
};
|
|
1002
1003
|
this.socket.onmessage = ({ data }) => {
|
|
1003
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
1004
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
1004
1005
|
const message = JSON.parse(data.toString());
|
|
1005
1006
|
if ("error" in message) {
|
|
1006
1007
|
(_b = (_a = this.listeners).error) === null || _b === void 0 ? void 0 : _b.call(_a, new StreamingError(message.error));
|
|
@@ -1020,8 +1021,12 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
1020
1021
|
(_h = (_g = this.listeners).speechStarted) === null || _h === void 0 ? void 0 : _h.call(_g, message);
|
|
1021
1022
|
break;
|
|
1022
1023
|
}
|
|
1024
|
+
case "LLMGatewayResponse": {
|
|
1025
|
+
(_k = (_j = this.listeners).llmGatewayResponse) === null || _k === void 0 ? void 0 : _k.call(_j, message);
|
|
1026
|
+
break;
|
|
1027
|
+
}
|
|
1023
1028
|
case "Termination": {
|
|
1024
|
-
(
|
|
1029
|
+
(_l = this.sessionTerminatedResolve) === null || _l === void 0 ? void 0 : _l.call(this);
|
|
1025
1030
|
break;
|
|
1026
1031
|
}
|
|
1027
1032
|
}
|
|
@@ -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(r,n){function o(e){try{c(i.next(e))}catch(e){n(e)}}function a(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?r(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 s={cache:"no-store"};let i="";"undefined"!=typeof navigator&&navigator.userAgent&&(i+=navigator.userAgent);const r={sdk:{name:"JavaScript",version:"4.25.1"}};"undefined"!=typeof process&&(process.versions.node&&-1===i.indexOf("Node")&&(r.runtime_env={name:"Node",version:process.versions.node}),process.versions.bun&&-1===i.indexOf("Bun")&&(r.runtime_env={name:"Bun",version:process.versions.bun})),"undefined"!=typeof Deno&&process.versions.bun&&-1===i.indexOf("Deno")&&(r.runtime_env={name:"Deno",version:Deno.version.deno});class n{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({},r),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 r=yield fetch(e,i);if(r.status>=400){let e;const t=yield r.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: ${r.status} ${r.statusText}`)}return r}))}fetchJson(e,s){return t(this,void 0,void 0,(function*(){return(yield this.fetch(e,s)).json()}))}}class o extends n{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 c,l;const d=null!==(l=null!==(c=null!==WebSocket&&void 0!==WebSocket?WebSocket:null===global||void 0===global?void 0:global.WebSocket)&&void 0!==c?c:null===window||void 0===window?void 0:window.WebSocket)&&void 0!==l?l: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,r;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(r=(i=this.listeners).error)||void 0===r||r.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,r,n,o,a,c,l,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===(n=(r=this.listeners).open)||void 0===n||n.call(r,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===(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 n{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 n{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,r=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 r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(s[i[r]]=e[i[r]])}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({},r),{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 r=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(r.id,s):r}))}waitUntilReady(e,s){return t(this,void 0,void 0,(function*(){var t,i;const r=null!==(t=null==s?void 0:s.pollingInterval)&&void 0!==t?t:3e3,n=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(n>0&&Date.now()-o>n)throw new Error("Polling timeout");yield new Promise((e=>setTimeout(e,r)))}}))}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 r=yield this.fetch(i);return yield r.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 n{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 r=i.length;const n=new Uint8Array(r);for(;r--;)n[r]=i.charCodeAt(r);return new Blob([n],{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()),this.params.speechModel&&("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()),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()),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,r;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(r=(i=this.listeners).error)||void 0===r||r.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,r,n,o,a,c,l,d;const h=JSON.parse(t.toString());if("error"in h)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new f(h.error));else switch(h.type){case"Begin":e(h),null===(n=(r=this.listeners).open)||void 0===n||n.call(r,h);break;case"Turn":null===(a=(o=this.listeners).turn)||void 0===a||a.call(o,h);break;case"SpeechStarted":null===(l=(c=this.listeners).speechStarted)||void 0===l||l.call(c,h);break;case"Termination":null===(d=this.sessionTerminatedResolve)||void 0===d||d.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 n{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,s,i){return new(s||(s=Promise))((function(r,n){function o(e){try{l(i.next(e))}catch(e){n(e)}}function a(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?r(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 r={sdk:{name:"JavaScript",version:"4.26.1"}};"undefined"!=typeof process&&(process.versions.node&&-1===i.indexOf("Node")&&(r.runtime_env={name:"Node",version:process.versions.node}),process.versions.bun&&-1===i.indexOf("Bun")&&(r.runtime_env={name:"Bun",version:process.versions.bun})),"undefined"!=typeof Deno&&process.versions.bun&&-1===i.indexOf("Deno")&&(r.runtime_env={name:"Deno",version:Deno.version.deno});class n{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({},r),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 r=yield fetch(e,i);if(r.status>=400){let e;const t=yield r.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: ${r.status} ${r.statusText}`)}return r}))}fetchJson(e,s){return t(this,void 0,void 0,(function*(){return(yield this.fetch(e,s)).json()}))}}class o extends n{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,r;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(r=(i=this.listeners).error)||void 0===r||r.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,r,n,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===(n=(r=this.listeners).open)||void 0===n||n.call(r,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 n{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 n{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,r=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 r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(s[i[r]]=e[i[r]])}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({},r),{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 r=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(r.id,s):r}))}waitUntilReady(e,s){return t(this,void 0,void 0,(function*(){var t,i;const r=null!==(t=null==s?void 0:s.pollingInterval)&&void 0!==t?t:3e3,n=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(n>0&&Date.now()-o>n)throw new Error("Polling timeout");yield new Promise((e=>setTimeout(e,r)))}}))}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 r=yield this.fetch(i);return yield r.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 n{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 r=i.length;const n=new Uint8Array(r);for(;r--;)n[r]=i.charCodeAt(r);return new Blob([n],{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()),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,r;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(r=(i=this.listeners).error)||void 0===r||r.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,r,n,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===(n=(r=this.listeners).open)||void 0===n||n.call(r,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 n{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}));
|
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.26.1" },
|
|
19
19
|
};
|
|
20
20
|
if (typeof process !== "undefined") {
|
|
21
21
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -853,12 +853,10 @@ class StreamingTranscriber {
|
|
|
853
853
|
if (this.params.filterProfanity) {
|
|
854
854
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
855
855
|
}
|
|
856
|
-
if (this.params.speechModel) {
|
|
857
|
-
|
|
858
|
-
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.");
|
|
859
|
-
}
|
|
860
|
-
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
856
|
+
if (this.params.speechModel === "u3-pro") {
|
|
857
|
+
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.");
|
|
861
858
|
}
|
|
859
|
+
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
862
860
|
if (this.params.languageDetection !== undefined) {
|
|
863
861
|
searchParams.set("language_detection", this.params.languageDetection.toString());
|
|
864
862
|
}
|
|
@@ -871,6 +869,9 @@ class StreamingTranscriber {
|
|
|
871
869
|
if (this.params.maxSpeakers !== undefined) {
|
|
872
870
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
873
871
|
}
|
|
872
|
+
if (this.params.llmGateway !== undefined) {
|
|
873
|
+
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
874
|
+
}
|
|
874
875
|
url.search = searchParams.toString();
|
|
875
876
|
return url;
|
|
876
877
|
}
|
|
@@ -932,6 +933,10 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
932
933
|
this.listeners.speechStarted?.(message);
|
|
933
934
|
break;
|
|
934
935
|
}
|
|
936
|
+
case "LLMGatewayResponse": {
|
|
937
|
+
this.listeners.llmGatewayResponse?.(message);
|
|
938
|
+
break;
|
|
939
|
+
}
|
|
935
940
|
case "Termination": {
|
|
936
941
|
this.sessionTerminatedResolve?.();
|
|
937
942
|
break;
|
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.26.1" },
|
|
21
21
|
};
|
|
22
22
|
if (typeof process !== "undefined") {
|
|
23
23
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -834,12 +834,10 @@ class StreamingTranscriber {
|
|
|
834
834
|
if (this.params.filterProfanity) {
|
|
835
835
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
836
836
|
}
|
|
837
|
-
if (this.params.speechModel) {
|
|
838
|
-
|
|
839
|
-
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.");
|
|
840
|
-
}
|
|
841
|
-
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
837
|
+
if (this.params.speechModel === "u3-pro") {
|
|
838
|
+
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.");
|
|
842
839
|
}
|
|
840
|
+
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
843
841
|
if (this.params.languageDetection !== undefined) {
|
|
844
842
|
searchParams.set("language_detection", this.params.languageDetection.toString());
|
|
845
843
|
}
|
|
@@ -852,6 +850,9 @@ class StreamingTranscriber {
|
|
|
852
850
|
if (this.params.maxSpeakers !== undefined) {
|
|
853
851
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
854
852
|
}
|
|
853
|
+
if (this.params.llmGateway !== undefined) {
|
|
854
|
+
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
855
|
+
}
|
|
855
856
|
url.search = searchParams.toString();
|
|
856
857
|
return url;
|
|
857
858
|
}
|
|
@@ -909,6 +910,10 @@ class StreamingTranscriber {
|
|
|
909
910
|
this.listeners.speechStarted?.(message);
|
|
910
911
|
break;
|
|
911
912
|
}
|
|
913
|
+
case "LLMGatewayResponse": {
|
|
914
|
+
this.listeners.llmGatewayResponse?.(message);
|
|
915
|
+
break;
|
|
916
|
+
}
|
|
912
917
|
case "Termination": {
|
|
913
918
|
this.sessionTerminatedResolve?.();
|
|
914
919
|
break;
|
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.26.1" },
|
|
21
21
|
};
|
|
22
22
|
if (typeof process !== "undefined") {
|
|
23
23
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -834,12 +834,10 @@ class StreamingTranscriber {
|
|
|
834
834
|
if (this.params.filterProfanity) {
|
|
835
835
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
836
836
|
}
|
|
837
|
-
if (this.params.speechModel) {
|
|
838
|
-
|
|
839
|
-
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.");
|
|
840
|
-
}
|
|
841
|
-
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
837
|
+
if (this.params.speechModel === "u3-pro") {
|
|
838
|
+
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.");
|
|
842
839
|
}
|
|
840
|
+
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
843
841
|
if (this.params.languageDetection !== undefined) {
|
|
844
842
|
searchParams.set("language_detection", this.params.languageDetection.toString());
|
|
845
843
|
}
|
|
@@ -852,6 +850,9 @@ class StreamingTranscriber {
|
|
|
852
850
|
if (this.params.maxSpeakers !== undefined) {
|
|
853
851
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
854
852
|
}
|
|
853
|
+
if (this.params.llmGateway !== undefined) {
|
|
854
|
+
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
855
|
+
}
|
|
855
856
|
url.search = searchParams.toString();
|
|
856
857
|
return url;
|
|
857
858
|
}
|
|
@@ -909,6 +910,10 @@ class StreamingTranscriber {
|
|
|
909
910
|
this.listeners.speechStarted?.(message);
|
|
910
911
|
break;
|
|
911
912
|
}
|
|
913
|
+
case "LLMGatewayResponse": {
|
|
914
|
+
this.listeners.llmGatewayResponse?.(message);
|
|
915
|
+
break;
|
|
916
|
+
}
|
|
912
917
|
case "Termination": {
|
|
913
918
|
this.sessionTerminatedResolve?.();
|
|
914
919
|
break;
|
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.26.1" },
|
|
67
67
|
};
|
|
68
68
|
if (typeof process !== "undefined") {
|
|
69
69
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -925,12 +925,10 @@ class StreamingTranscriber {
|
|
|
925
925
|
if (this.params.filterProfanity) {
|
|
926
926
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
927
927
|
}
|
|
928
|
-
if (this.params.speechModel) {
|
|
929
|
-
|
|
930
|
-
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.");
|
|
931
|
-
}
|
|
932
|
-
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
928
|
+
if (this.params.speechModel === "u3-pro") {
|
|
929
|
+
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.");
|
|
933
930
|
}
|
|
931
|
+
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
934
932
|
if (this.params.languageDetection !== undefined) {
|
|
935
933
|
searchParams.set("language_detection", this.params.languageDetection.toString());
|
|
936
934
|
}
|
|
@@ -943,6 +941,9 @@ class StreamingTranscriber {
|
|
|
943
941
|
if (this.params.maxSpeakers !== undefined) {
|
|
944
942
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
945
943
|
}
|
|
944
|
+
if (this.params.llmGateway !== undefined) {
|
|
945
|
+
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
946
|
+
}
|
|
946
947
|
url.search = searchParams.toString();
|
|
947
948
|
return url;
|
|
948
949
|
}
|
|
@@ -983,7 +984,7 @@ class StreamingTranscriber {
|
|
|
983
984
|
(_d = (_c = this.listeners).error) === null || _d === void 0 ? void 0 : _d.call(_c, new Error(event.message));
|
|
984
985
|
};
|
|
985
986
|
this.socket.onmessage = ({ data }) => {
|
|
986
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
987
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
987
988
|
const message = JSON.parse(data.toString());
|
|
988
989
|
if ("error" in message) {
|
|
989
990
|
(_b = (_a = this.listeners).error) === null || _b === void 0 ? void 0 : _b.call(_a, new StreamingError(message.error));
|
|
@@ -1003,8 +1004,12 @@ class StreamingTranscriber {
|
|
|
1003
1004
|
(_h = (_g = this.listeners).speechStarted) === null || _h === void 0 ? void 0 : _h.call(_g, message);
|
|
1004
1005
|
break;
|
|
1005
1006
|
}
|
|
1007
|
+
case "LLMGatewayResponse": {
|
|
1008
|
+
(_k = (_j = this.listeners).llmGatewayResponse) === null || _k === void 0 ? void 0 : _k.call(_j, message);
|
|
1009
|
+
break;
|
|
1010
|
+
}
|
|
1006
1011
|
case "Termination": {
|
|
1007
|
-
(
|
|
1012
|
+
(_l = this.sessionTerminatedResolve) === null || _l === void 0 ? void 0 : _l.call(this);
|
|
1008
1013
|
break;
|
|
1009
1014
|
}
|
|
1010
1015
|
}
|
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.26.1" },
|
|
65
65
|
};
|
|
66
66
|
if (typeof process !== "undefined") {
|
|
67
67
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -923,12 +923,10 @@ class StreamingTranscriber {
|
|
|
923
923
|
if (this.params.filterProfanity) {
|
|
924
924
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
925
925
|
}
|
|
926
|
-
if (this.params.speechModel) {
|
|
927
|
-
|
|
928
|
-
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.");
|
|
929
|
-
}
|
|
930
|
-
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
926
|
+
if (this.params.speechModel === "u3-pro") {
|
|
927
|
+
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.");
|
|
931
928
|
}
|
|
929
|
+
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
932
930
|
if (this.params.languageDetection !== undefined) {
|
|
933
931
|
searchParams.set("language_detection", this.params.languageDetection.toString());
|
|
934
932
|
}
|
|
@@ -941,6 +939,9 @@ class StreamingTranscriber {
|
|
|
941
939
|
if (this.params.maxSpeakers !== undefined) {
|
|
942
940
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
943
941
|
}
|
|
942
|
+
if (this.params.llmGateway !== undefined) {
|
|
943
|
+
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
944
|
+
}
|
|
944
945
|
url.search = searchParams.toString();
|
|
945
946
|
return url;
|
|
946
947
|
}
|
|
@@ -981,7 +982,7 @@ class StreamingTranscriber {
|
|
|
981
982
|
(_d = (_c = this.listeners).error) === null || _d === void 0 ? void 0 : _d.call(_c, new Error(event.message));
|
|
982
983
|
};
|
|
983
984
|
this.socket.onmessage = ({ data }) => {
|
|
984
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
985
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
985
986
|
const message = JSON.parse(data.toString());
|
|
986
987
|
if ("error" in message) {
|
|
987
988
|
(_b = (_a = this.listeners).error) === null || _b === void 0 ? void 0 : _b.call(_a, new StreamingError(message.error));
|
|
@@ -1001,8 +1002,12 @@ class StreamingTranscriber {
|
|
|
1001
1002
|
(_h = (_g = this.listeners).speechStarted) === null || _h === void 0 ? void 0 : _h.call(_g, message);
|
|
1002
1003
|
break;
|
|
1003
1004
|
}
|
|
1005
|
+
case "LLMGatewayResponse": {
|
|
1006
|
+
(_k = (_j = this.listeners).llmGatewayResponse) === null || _k === void 0 ? void 0 : _k.call(_j, message);
|
|
1007
|
+
break;
|
|
1008
|
+
}
|
|
1004
1009
|
case "Termination": {
|
|
1005
|
-
(
|
|
1010
|
+
(_l = this.sessionTerminatedResolve) === null || _l === void 0 ? void 0 : _l.call(this);
|
|
1006
1011
|
break;
|
|
1007
1012
|
}
|
|
1008
1013
|
}
|
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.26.1" },
|
|
26
26
|
};
|
|
27
27
|
if (typeof process !== "undefined") {
|
|
28
28
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -833,12 +833,10 @@ class StreamingTranscriber {
|
|
|
833
833
|
if (this.params.filterProfanity) {
|
|
834
834
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
835
835
|
}
|
|
836
|
-
if (this.params.speechModel) {
|
|
837
|
-
|
|
838
|
-
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.");
|
|
839
|
-
}
|
|
840
|
-
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
836
|
+
if (this.params.speechModel === "u3-pro") {
|
|
837
|
+
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.");
|
|
841
838
|
}
|
|
839
|
+
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
842
840
|
if (this.params.languageDetection !== undefined) {
|
|
843
841
|
searchParams.set("language_detection", this.params.languageDetection.toString());
|
|
844
842
|
}
|
|
@@ -851,6 +849,9 @@ class StreamingTranscriber {
|
|
|
851
849
|
if (this.params.maxSpeakers !== undefined) {
|
|
852
850
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
853
851
|
}
|
|
852
|
+
if (this.params.llmGateway !== undefined) {
|
|
853
|
+
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
854
|
+
}
|
|
854
855
|
url.search = searchParams.toString();
|
|
855
856
|
return url;
|
|
856
857
|
}
|
|
@@ -908,6 +909,10 @@ class StreamingTranscriber {
|
|
|
908
909
|
this.listeners.speechStarted?.(message);
|
|
909
910
|
break;
|
|
910
911
|
}
|
|
912
|
+
case "LLMGatewayResponse": {
|
|
913
|
+
this.listeners.llmGatewayResponse?.(message);
|
|
914
|
+
break;
|
|
915
|
+
}
|
|
911
916
|
case "Termination": {
|
|
912
917
|
this.sessionTerminatedResolve?.();
|
|
913
918
|
break;
|
package/dist/node.mjs
CHANGED
|
@@ -20,7 +20,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
20
20
|
defaultUserAgentString += navigator.userAgent;
|
|
21
21
|
}
|
|
22
22
|
const defaultUserAgent = {
|
|
23
|
-
sdk: { name: "JavaScript", version: "4.
|
|
23
|
+
sdk: { name: "JavaScript", version: "4.26.1" },
|
|
24
24
|
};
|
|
25
25
|
if (typeof process !== "undefined") {
|
|
26
26
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -831,12 +831,10 @@ class StreamingTranscriber {
|
|
|
831
831
|
if (this.params.filterProfanity) {
|
|
832
832
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
833
833
|
}
|
|
834
|
-
if (this.params.speechModel) {
|
|
835
|
-
|
|
836
|
-
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.");
|
|
837
|
-
}
|
|
838
|
-
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
834
|
+
if (this.params.speechModel === "u3-pro") {
|
|
835
|
+
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.");
|
|
839
836
|
}
|
|
837
|
+
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
840
838
|
if (this.params.languageDetection !== undefined) {
|
|
841
839
|
searchParams.set("language_detection", this.params.languageDetection.toString());
|
|
842
840
|
}
|
|
@@ -849,6 +847,9 @@ class StreamingTranscriber {
|
|
|
849
847
|
if (this.params.maxSpeakers !== undefined) {
|
|
850
848
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
851
849
|
}
|
|
850
|
+
if (this.params.llmGateway !== undefined) {
|
|
851
|
+
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
852
|
+
}
|
|
852
853
|
url.search = searchParams.toString();
|
|
853
854
|
return url;
|
|
854
855
|
}
|
|
@@ -906,6 +907,10 @@ class StreamingTranscriber {
|
|
|
906
907
|
this.listeners.speechStarted?.(message);
|
|
907
908
|
break;
|
|
908
909
|
}
|
|
910
|
+
case "LLMGatewayResponse": {
|
|
911
|
+
this.listeners.llmGatewayResponse?.(message);
|
|
912
|
+
break;
|
|
913
|
+
}
|
|
909
914
|
case "Termination": {
|
|
910
915
|
this.sessionTerminatedResolve?.();
|
|
911
916
|
break;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StreamingTranscriberParams, AudioData, BeginEvent, TurnEvent, StreamingUpdateConfiguration } from "../..";
|
|
1
|
+
import { StreamingTranscriberParams, AudioData, BeginEvent, TurnEvent, LLMGatewayResponseEvent, StreamingUpdateConfiguration } from "../..";
|
|
2
2
|
export declare class StreamingTranscriber {
|
|
3
3
|
private apiKey?;
|
|
4
4
|
private token?;
|
|
@@ -10,6 +10,7 @@ export declare class StreamingTranscriber {
|
|
|
10
10
|
private connectionUrl;
|
|
11
11
|
on(event: "open", listener: (event: BeginEvent) => void): void;
|
|
12
12
|
on(event: "turn", listener: (event: TurnEvent) => void): void;
|
|
13
|
+
on(event: "llmGatewayResponse", listener: (event: LLMGatewayResponseEvent) => void): void;
|
|
13
14
|
on(event: "error", listener: (error: Error) => void): void;
|
|
14
15
|
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
15
16
|
connect(): Promise<BeginEvent>;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { AudioEncoding } from "..";
|
|
2
|
+
export type LLMGatewayMessage = {
|
|
3
|
+
role: string;
|
|
4
|
+
content: string;
|
|
5
|
+
};
|
|
6
|
+
export type LLMGatewayConfig = {
|
|
7
|
+
model: string;
|
|
8
|
+
messages: LLMGatewayMessage[];
|
|
9
|
+
max_tokens: number;
|
|
10
|
+
};
|
|
2
11
|
export type StreamingTranscriberParams = {
|
|
3
12
|
websocketBaseUrl?: string;
|
|
4
13
|
apiKey?: string;
|
|
@@ -18,18 +27,20 @@ export type StreamingTranscriberParams = {
|
|
|
18
27
|
keyterms?: string[];
|
|
19
28
|
keytermsPrompt?: string[];
|
|
20
29
|
prompt?: string;
|
|
21
|
-
speechModel
|
|
30
|
+
speechModel: StreamingSpeechModel;
|
|
22
31
|
languageDetection?: boolean;
|
|
23
32
|
inactivityTimeout?: number;
|
|
24
33
|
speakerLabels?: boolean;
|
|
25
34
|
maxSpeakers?: number;
|
|
35
|
+
llmGateway?: LLMGatewayConfig;
|
|
26
36
|
};
|
|
27
|
-
export type StreamingEvents = "open" | "close" | "turn" | "speechStarted" | "error";
|
|
37
|
+
export type StreamingEvents = "open" | "close" | "turn" | "speechStarted" | "llmGatewayResponse" | "error";
|
|
28
38
|
export type StreamingListeners = {
|
|
29
39
|
open?: (event: BeginEvent) => void;
|
|
30
40
|
close?: (code: number, reason: string) => void;
|
|
31
41
|
turn?: (event: TurnEvent) => void;
|
|
32
42
|
speechStarted?: (event: SpeechStartedEvent) => void;
|
|
43
|
+
llmGatewayResponse?: (event: LLMGatewayResponseEvent) => void;
|
|
33
44
|
error?: (error: Error) => void;
|
|
34
45
|
};
|
|
35
46
|
export type StreamingSpeechModel = "universal-streaming-english" | "universal-streaming-multilingual" | "u3-rt-pro" | "whisper-rt" | "u3-pro";
|
|
@@ -98,5 +109,11 @@ export type StreamingForceEndpoint = {
|
|
|
98
109
|
export type ErrorEvent = {
|
|
99
110
|
error: string;
|
|
100
111
|
};
|
|
101
|
-
export type
|
|
112
|
+
export type LLMGatewayResponseEvent = {
|
|
113
|
+
type: "LLMGatewayResponse";
|
|
114
|
+
turn_order: number;
|
|
115
|
+
transcript: string;
|
|
116
|
+
data: unknown;
|
|
117
|
+
};
|
|
118
|
+
export type StreamingEventMessage = BeginEvent | TurnEvent | SpeechStartedEvent | TerminationEvent | LLMGatewayResponseEvent | ErrorEvent;
|
|
102
119
|
export type StreamingOperationMessage = StreamingUpdateConfiguration | StreamingForceEndpoint | StreamingTerminateSession;
|
package/dist/workerd.mjs
CHANGED
|
@@ -15,7 +15,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
15
15
|
defaultUserAgentString += navigator.userAgent;
|
|
16
16
|
}
|
|
17
17
|
const defaultUserAgent = {
|
|
18
|
-
sdk: { name: "JavaScript", version: "4.
|
|
18
|
+
sdk: { name: "JavaScript", version: "4.26.1" },
|
|
19
19
|
};
|
|
20
20
|
if (typeof process !== "undefined") {
|
|
21
21
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -836,12 +836,10 @@ class StreamingTranscriber {
|
|
|
836
836
|
if (this.params.filterProfanity) {
|
|
837
837
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
838
838
|
}
|
|
839
|
-
if (this.params.speechModel) {
|
|
840
|
-
|
|
841
|
-
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.");
|
|
842
|
-
}
|
|
843
|
-
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
839
|
+
if (this.params.speechModel === "u3-pro") {
|
|
840
|
+
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.");
|
|
844
841
|
}
|
|
842
|
+
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
845
843
|
if (this.params.languageDetection !== undefined) {
|
|
846
844
|
searchParams.set("language_detection", this.params.languageDetection.toString());
|
|
847
845
|
}
|
|
@@ -854,6 +852,9 @@ class StreamingTranscriber {
|
|
|
854
852
|
if (this.params.maxSpeakers !== undefined) {
|
|
855
853
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
856
854
|
}
|
|
855
|
+
if (this.params.llmGateway !== undefined) {
|
|
856
|
+
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
857
|
+
}
|
|
857
858
|
url.search = searchParams.toString();
|
|
858
859
|
return url;
|
|
859
860
|
}
|
|
@@ -911,6 +912,10 @@ class StreamingTranscriber {
|
|
|
911
912
|
this.listeners.speechStarted?.(message);
|
|
912
913
|
break;
|
|
913
914
|
}
|
|
915
|
+
case "LLMGatewayResponse": {
|
|
916
|
+
this.listeners.llmGatewayResponse?.(message);
|
|
917
|
+
break;
|
|
918
|
+
}
|
|
914
919
|
case "Termination": {
|
|
915
920
|
this.sessionTerminatedResolve?.();
|
|
916
921
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblyai",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.26.1",
|
|
4
4
|
"description": "The AssemblyAI JavaScript SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription, as well as the latest LeMUR models.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18"
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
BeginEvent,
|
|
14
14
|
StreamingEventMessage,
|
|
15
15
|
TurnEvent,
|
|
16
|
+
LLMGatewayResponseEvent,
|
|
16
17
|
StreamingUpdateConfiguration,
|
|
17
18
|
StreamingForceEndpoint,
|
|
18
19
|
} from "../..";
|
|
@@ -142,14 +143,12 @@ export class StreamingTranscriber {
|
|
|
142
143
|
);
|
|
143
144
|
}
|
|
144
145
|
|
|
145
|
-
if (this.params.speechModel) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
146
|
+
if (this.params.speechModel === "u3-pro") {
|
|
147
|
+
console.warn(
|
|
148
|
+
"[Deprecation Warning] The speech model `u3-pro` is deprecated and will be removed in a future release. Please use `u3-rt-pro` instead.",
|
|
149
|
+
);
|
|
152
150
|
}
|
|
151
|
+
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
153
152
|
|
|
154
153
|
if (this.params.languageDetection !== undefined) {
|
|
155
154
|
searchParams.set(
|
|
@@ -173,6 +172,10 @@ export class StreamingTranscriber {
|
|
|
173
172
|
searchParams.set("max_speakers", this.params.maxSpeakers.toString());
|
|
174
173
|
}
|
|
175
174
|
|
|
175
|
+
if (this.params.llmGateway !== undefined) {
|
|
176
|
+
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
|
|
177
|
+
}
|
|
178
|
+
|
|
176
179
|
url.search = searchParams.toString();
|
|
177
180
|
|
|
178
181
|
return url;
|
|
@@ -180,6 +183,10 @@ export class StreamingTranscriber {
|
|
|
180
183
|
|
|
181
184
|
on(event: "open", listener: (event: BeginEvent) => void): void;
|
|
182
185
|
on(event: "turn", listener: (event: TurnEvent) => void): void;
|
|
186
|
+
on(
|
|
187
|
+
event: "llmGatewayResponse",
|
|
188
|
+
listener: (event: LLMGatewayResponseEvent) => void,
|
|
189
|
+
): void;
|
|
183
190
|
on(event: "error", listener: (error: Error) => void): void;
|
|
184
191
|
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
185
192
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -250,6 +257,10 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
250
257
|
this.listeners.speechStarted?.(message);
|
|
251
258
|
break;
|
|
252
259
|
}
|
|
260
|
+
case "LLMGatewayResponse": {
|
|
261
|
+
this.listeners.llmGatewayResponse?.(message);
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
253
264
|
case "Termination": {
|
|
254
265
|
this.sessionTerminatedResolve?.();
|
|
255
266
|
break;
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { AudioEncoding } from "..";
|
|
2
2
|
|
|
3
|
+
export type LLMGatewayMessage = {
|
|
4
|
+
role: string;
|
|
5
|
+
content: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type LLMGatewayConfig = {
|
|
9
|
+
model: string;
|
|
10
|
+
messages: LLMGatewayMessage[];
|
|
11
|
+
max_tokens: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
3
14
|
export type StreamingTranscriberParams = {
|
|
4
15
|
websocketBaseUrl?: string;
|
|
5
16
|
apiKey?: string;
|
|
@@ -19,11 +30,12 @@ export type StreamingTranscriberParams = {
|
|
|
19
30
|
keyterms?: string[];
|
|
20
31
|
keytermsPrompt?: string[];
|
|
21
32
|
prompt?: string;
|
|
22
|
-
speechModel
|
|
33
|
+
speechModel: StreamingSpeechModel;
|
|
23
34
|
languageDetection?: boolean;
|
|
24
35
|
inactivityTimeout?: number;
|
|
25
36
|
speakerLabels?: boolean;
|
|
26
37
|
maxSpeakers?: number;
|
|
38
|
+
llmGateway?: LLMGatewayConfig;
|
|
27
39
|
};
|
|
28
40
|
|
|
29
41
|
export type StreamingEvents =
|
|
@@ -31,6 +43,7 @@ export type StreamingEvents =
|
|
|
31
43
|
| "close"
|
|
32
44
|
| "turn"
|
|
33
45
|
| "speechStarted"
|
|
46
|
+
| "llmGatewayResponse"
|
|
34
47
|
| "error";
|
|
35
48
|
|
|
36
49
|
export type StreamingListeners = {
|
|
@@ -38,6 +51,7 @@ export type StreamingListeners = {
|
|
|
38
51
|
close?: (code: number, reason: string) => void;
|
|
39
52
|
turn?: (event: TurnEvent) => void;
|
|
40
53
|
speechStarted?: (event: SpeechStartedEvent) => void;
|
|
54
|
+
llmGatewayResponse?: (event: LLMGatewayResponseEvent) => void;
|
|
41
55
|
error?: (error: Error) => void;
|
|
42
56
|
};
|
|
43
57
|
|
|
@@ -125,11 +139,19 @@ export type ErrorEvent = {
|
|
|
125
139
|
error: string;
|
|
126
140
|
};
|
|
127
141
|
|
|
142
|
+
export type LLMGatewayResponseEvent = {
|
|
143
|
+
type: "LLMGatewayResponse";
|
|
144
|
+
turn_order: number;
|
|
145
|
+
transcript: string;
|
|
146
|
+
data: unknown;
|
|
147
|
+
};
|
|
148
|
+
|
|
128
149
|
export type StreamingEventMessage =
|
|
129
150
|
| BeginEvent
|
|
130
151
|
| TurnEvent
|
|
131
152
|
| SpeechStartedEvent
|
|
132
153
|
| TerminationEvent
|
|
154
|
+
| LLMGatewayResponseEvent
|
|
133
155
|
| ErrorEvent;
|
|
134
156
|
|
|
135
157
|
export type StreamingOperationMessage =
|