assemblyai 4.19.0 → 4.22.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.20.0]
4
+
5
+ - Add `on_low_language_confidence` property to `LanguageDetectionOptions`
6
+ > Controls behavior when language confidence is below threshold. Either "error" (default) or "fallback".
7
+ > When set to "fallback", the transcription will use the fallback language instead of erroring when confidence is low.
8
+
3
9
  ## [4.8.0]
4
10
 
5
11
  - Add `multichannel` property to `TranscriptParams`
@@ -65,7 +65,7 @@
65
65
  defaultUserAgentString += navigator.userAgent;
66
66
  }
67
67
  const defaultUserAgent = {
68
- sdk: { name: "JavaScript", version: "4.19.0" },
68
+ sdk: { name: "JavaScript", version: "4.22.0" },
69
69
  };
70
70
  if (typeof process !== "undefined") {
71
71
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -912,6 +912,9 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
912
912
  if (this.params.maxTurnSilence) {
913
913
  searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
914
914
  }
915
+ if (this.params.vadThreshold !== undefined) {
916
+ searchParams.set("vad_threshold", this.params.vadThreshold.toString());
917
+ }
915
918
  if (this.params.formatTurns) {
916
919
  searchParams.set("format_turns", this.params.formatTurns.toString());
917
920
  }
@@ -931,6 +934,12 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
931
934
  if (this.params.speechModel) {
932
935
  searchParams.set("speech_model", this.params.speechModel.toString());
933
936
  }
937
+ if (this.params.languageDetection !== undefined) {
938
+ searchParams.set("language_detection", this.params.languageDetection.toString());
939
+ }
940
+ if (this.params.inactivityTimeout !== undefined) {
941
+ searchParams.set("inactivity_timeout", this.params.inactivityTimeout.toString());
942
+ }
934
943
  url.search = searchParams.toString();
935
944
  return url;
936
945
  }
@@ -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.19.0"}};"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 m extends Error{}const 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",[4101]:"Bad schema",[4102]:"Too many streams",[4103]:"This session has been reconnected. This WebSocket is no longer valid."};class f extends Error{}const y='{"terminate_session":true}';class v{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,p,f,y,v;const b=JSON.parse(t.toString());if("error"in b)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new m(b.error));else switch(b.message_type){case"SessionBegins":{const t={sessionId:b.session_id,expiresAt:new Date(b.expires_at)};e(t),null===(n=(r=this.listeners).open)||void 0===n||n.call(r,t);break}case"PartialTranscript":b.created=new Date(b.created),null===(a=(o=this.listeners).transcript)||void 0===a||a.call(o,b),null===(l=(c=this.listeners)["transcript.partial"])||void 0===l||l.call(c,b);break;case"FinalTranscript":b.created=new Date(b.created),null===(h=(d=this.listeners).transcript)||void 0===h||h.call(d,b),null===(p=(u=this.listeners)["transcript.final"])||void 0===p||p.call(u,b);break;case"SessionInformation":null===(y=(f=this.listeners).session_information)||void 0===y||y.call(f,b);break;case"SessionTerminated":null===(v=this.sessionTerminatedResolve)||void 0===v||v.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(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 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 v(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 g(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=g(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=g(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 k 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 S='{"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.minEndOfTurnSilenceWhenConfident&&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()),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.filterProfanity&&s.set("filter_profanity",this.params.filterProfanity.toString()),this.params.speechModel&&s.set("speech_model",this.params.speechModel.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 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,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;const l=JSON.parse(t.toString());if("error"in l)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new f(l.error));else switch(l.type){case"Begin":e(l),null===(n=(r=this.listeners).open)||void 0===n||n.call(r,l);break;case"Turn":null===(a=(o=this.listeners).turn)||void 0===a||a.call(o,l);break;case"Termination":null===(c=this.sessionTerminatedResolve)||void 0===c||c.call(this)}}}))}stream(){return new a({write:e=>{this.sendAudio(e)}})}sendAudio(e){this.send(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(S),yield e}else this.socket.send(S);(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 k(e),this.transcripts=new w(e,this.files),this.lemur=new o(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=o,e.RealtimeService=class extends v{},e.RealtimeServiceFactory=class extends b{},e.RealtimeTranscriber=v,e.RealtimeTranscriberFactory=b,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{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.22.0"}};"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 m extends Error{}const 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",[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,p,f,v,y;const b=JSON.parse(t.toString());if("error"in b)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new m(b.error));else switch(b.message_type){case"SessionBegins":{const t={sessionId:b.session_id,expiresAt:new Date(b.expires_at)};e(t),null===(n=(r=this.listeners).open)||void 0===n||n.call(r,t);break}case"PartialTranscript":b.created=new Date(b.created),null===(a=(o=this.listeners).transcript)||void 0===a||a.call(o,b),null===(l=(c=this.listeners)["transcript.partial"])||void 0===l||l.call(c,b);break;case"FinalTranscript":b.created=new Date(b.created),null===(h=(d=this.listeners).transcript)||void 0===h||h.call(d,b),null===(p=(u=this.listeners)["transcript.final"])||void 0===p||p.call(u,b);break;case"SessionInformation":null===(v=(f=this.listeners).session_information)||void 0===v||v.call(f,b);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 b 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 g(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=g(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=g(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 k 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 S='{"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.minEndOfTurnSilenceWhenConfident&&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.filterProfanity&&s.set("filter_profanity",this.params.filterProfanity.toString()),this.params.speechModel&&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()),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 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,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;const l=JSON.parse(t.toString());if("error"in l)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new f(l.error));else switch(l.type){case"Begin":e(l),null===(n=(r=this.listeners).open)||void 0===n||n.call(r,l);break;case"Turn":null===(a=(o=this.listeners).turn)||void 0===a||a.call(o,l);break;case"Termination":null===(c=this.sessionTerminatedResolve)||void 0===c||c.call(this)}}}))}stream(){return new a({write:e=>{this.sendAudio(e)}})}sendAudio(e){this.send(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(S),yield e}else this.socket.send(S);(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 k(e),this.transcripts=new w(e,this.files),this.lemur=new o(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=o,e.RealtimeService=class extends y{},e.RealtimeServiceFactory=class extends b{},e.RealtimeTranscriber=y,e.RealtimeTranscriberFactory=b,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.19.0" },
18
+ sdk: { name: "JavaScript", version: "4.22.0" },
19
19
  };
20
20
  if (typeof process !== "undefined") {
21
21
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -827,6 +827,9 @@ class StreamingTranscriber {
827
827
  if (this.params.maxTurnSilence) {
828
828
  searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
829
829
  }
830
+ if (this.params.vadThreshold !== undefined) {
831
+ searchParams.set("vad_threshold", this.params.vadThreshold.toString());
832
+ }
830
833
  if (this.params.formatTurns) {
831
834
  searchParams.set("format_turns", this.params.formatTurns.toString());
832
835
  }
@@ -846,6 +849,12 @@ class StreamingTranscriber {
846
849
  if (this.params.speechModel) {
847
850
  searchParams.set("speech_model", this.params.speechModel.toString());
848
851
  }
852
+ if (this.params.languageDetection !== undefined) {
853
+ searchParams.set("language_detection", this.params.languageDetection.toString());
854
+ }
855
+ if (this.params.inactivityTimeout !== undefined) {
856
+ searchParams.set("inactivity_timeout", this.params.inactivityTimeout.toString());
857
+ }
849
858
  url.search = searchParams.toString();
850
859
  return url;
851
860
  }
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.19.0" },
20
+ sdk: { name: "JavaScript", version: "4.22.0" },
21
21
  };
22
22
  if (typeof process !== "undefined") {
23
23
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -808,6 +808,9 @@ class StreamingTranscriber {
808
808
  if (this.params.maxTurnSilence) {
809
809
  searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
810
810
  }
811
+ if (this.params.vadThreshold !== undefined) {
812
+ searchParams.set("vad_threshold", this.params.vadThreshold.toString());
813
+ }
811
814
  if (this.params.formatTurns) {
812
815
  searchParams.set("format_turns", this.params.formatTurns.toString());
813
816
  }
@@ -827,6 +830,12 @@ class StreamingTranscriber {
827
830
  if (this.params.speechModel) {
828
831
  searchParams.set("speech_model", this.params.speechModel.toString());
829
832
  }
833
+ if (this.params.languageDetection !== undefined) {
834
+ searchParams.set("language_detection", this.params.languageDetection.toString());
835
+ }
836
+ if (this.params.inactivityTimeout !== undefined) {
837
+ searchParams.set("inactivity_timeout", this.params.inactivityTimeout.toString());
838
+ }
830
839
  url.search = searchParams.toString();
831
840
  return url;
832
841
  }
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.19.0" },
20
+ sdk: { name: "JavaScript", version: "4.22.0" },
21
21
  };
22
22
  if (typeof process !== "undefined") {
23
23
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -808,6 +808,9 @@ class StreamingTranscriber {
808
808
  if (this.params.maxTurnSilence) {
809
809
  searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
810
810
  }
811
+ if (this.params.vadThreshold !== undefined) {
812
+ searchParams.set("vad_threshold", this.params.vadThreshold.toString());
813
+ }
811
814
  if (this.params.formatTurns) {
812
815
  searchParams.set("format_turns", this.params.formatTurns.toString());
813
816
  }
@@ -827,6 +830,12 @@ class StreamingTranscriber {
827
830
  if (this.params.speechModel) {
828
831
  searchParams.set("speech_model", this.params.speechModel.toString());
829
832
  }
833
+ if (this.params.languageDetection !== undefined) {
834
+ searchParams.set("language_detection", this.params.languageDetection.toString());
835
+ }
836
+ if (this.params.inactivityTimeout !== undefined) {
837
+ searchParams.set("inactivity_timeout", this.params.inactivityTimeout.toString());
838
+ }
830
839
  url.search = searchParams.toString();
831
840
  return url;
832
841
  }
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.19.0" },
66
+ sdk: { name: "JavaScript", version: "4.22.0" },
67
67
  };
68
68
  if (typeof process !== "undefined") {
69
69
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -899,6 +899,9 @@ class StreamingTranscriber {
899
899
  if (this.params.maxTurnSilence) {
900
900
  searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
901
901
  }
902
+ if (this.params.vadThreshold !== undefined) {
903
+ searchParams.set("vad_threshold", this.params.vadThreshold.toString());
904
+ }
902
905
  if (this.params.formatTurns) {
903
906
  searchParams.set("format_turns", this.params.formatTurns.toString());
904
907
  }
@@ -918,6 +921,12 @@ class StreamingTranscriber {
918
921
  if (this.params.speechModel) {
919
922
  searchParams.set("speech_model", this.params.speechModel.toString());
920
923
  }
924
+ if (this.params.languageDetection !== undefined) {
925
+ searchParams.set("language_detection", this.params.languageDetection.toString());
926
+ }
927
+ if (this.params.inactivityTimeout !== undefined) {
928
+ searchParams.set("inactivity_timeout", this.params.inactivityTimeout.toString());
929
+ }
921
930
  url.search = searchParams.toString();
922
931
  return url;
923
932
  }
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.19.0" },
64
+ sdk: { name: "JavaScript", version: "4.22.0" },
65
65
  };
66
66
  if (typeof process !== "undefined") {
67
67
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -897,6 +897,9 @@ class StreamingTranscriber {
897
897
  if (this.params.maxTurnSilence) {
898
898
  searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
899
899
  }
900
+ if (this.params.vadThreshold !== undefined) {
901
+ searchParams.set("vad_threshold", this.params.vadThreshold.toString());
902
+ }
900
903
  if (this.params.formatTurns) {
901
904
  searchParams.set("format_turns", this.params.formatTurns.toString());
902
905
  }
@@ -916,6 +919,12 @@ class StreamingTranscriber {
916
919
  if (this.params.speechModel) {
917
920
  searchParams.set("speech_model", this.params.speechModel.toString());
918
921
  }
922
+ if (this.params.languageDetection !== undefined) {
923
+ searchParams.set("language_detection", this.params.languageDetection.toString());
924
+ }
925
+ if (this.params.inactivityTimeout !== undefined) {
926
+ searchParams.set("inactivity_timeout", this.params.inactivityTimeout.toString());
927
+ }
919
928
  url.search = searchParams.toString();
920
929
  return url;
921
930
  }
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.19.0" },
25
+ sdk: { name: "JavaScript", version: "4.22.0" },
26
26
  };
27
27
  if (typeof process !== "undefined") {
28
28
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -807,6 +807,9 @@ class StreamingTranscriber {
807
807
  if (this.params.maxTurnSilence) {
808
808
  searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
809
809
  }
810
+ if (this.params.vadThreshold !== undefined) {
811
+ searchParams.set("vad_threshold", this.params.vadThreshold.toString());
812
+ }
810
813
  if (this.params.formatTurns) {
811
814
  searchParams.set("format_turns", this.params.formatTurns.toString());
812
815
  }
@@ -826,6 +829,12 @@ class StreamingTranscriber {
826
829
  if (this.params.speechModel) {
827
830
  searchParams.set("speech_model", this.params.speechModel.toString());
828
831
  }
832
+ if (this.params.languageDetection !== undefined) {
833
+ searchParams.set("language_detection", this.params.languageDetection.toString());
834
+ }
835
+ if (this.params.inactivityTimeout !== undefined) {
836
+ searchParams.set("inactivity_timeout", this.params.inactivityTimeout.toString());
837
+ }
829
838
  url.search = searchParams.toString();
830
839
  return url;
831
840
  }
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.19.0" },
23
+ sdk: { name: "JavaScript", version: "4.22.0" },
24
24
  };
25
25
  if (typeof process !== "undefined") {
26
26
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -805,6 +805,9 @@ class StreamingTranscriber {
805
805
  if (this.params.maxTurnSilence) {
806
806
  searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
807
807
  }
808
+ if (this.params.vadThreshold !== undefined) {
809
+ searchParams.set("vad_threshold", this.params.vadThreshold.toString());
810
+ }
808
811
  if (this.params.formatTurns) {
809
812
  searchParams.set("format_turns", this.params.formatTurns.toString());
810
813
  }
@@ -824,6 +827,12 @@ class StreamingTranscriber {
824
827
  if (this.params.speechModel) {
825
828
  searchParams.set("speech_model", this.params.speechModel.toString());
826
829
  }
830
+ if (this.params.languageDetection !== undefined) {
831
+ searchParams.set("language_detection", this.params.languageDetection.toString());
832
+ }
833
+ if (this.params.inactivityTimeout !== undefined) {
834
+ searchParams.set("inactivity_timeout", this.params.inactivityTimeout.toString());
835
+ }
827
836
  url.search = searchParams.toString();
828
837
  return url;
829
838
  }
@@ -1497,6 +1497,15 @@ export type CodeSwitchingLanguage = {
1497
1497
  */
1498
1498
  confidence: number;
1499
1499
  };
1500
+ /**
1501
+ * Language detection results including code switching languages
1502
+ */
1503
+ export type LanguageDetectionResults = {
1504
+ /**
1505
+ * List of detected languages with confidence scores when code switching is enabled
1506
+ */
1507
+ code_switching_languages?: CodeSwitchingLanguage[] | null;
1508
+ };
1500
1509
  /**
1501
1510
  * Options for controlling the behavior of Automatic Language Detection
1502
1511
  */
@@ -1517,6 +1526,10 @@ export type LanguageDetectionOptions = {
1517
1526
  * The confidence threshold for the automatically detected code switching language.
1518
1527
  */
1519
1528
  code_switching_confidence_threshold?: number | null;
1529
+ /**
1530
+ * Controls behavior when language confidence is below threshold. Either "error" (default) or "fallback".
1531
+ */
1532
+ on_low_language_confidence?: string | null;
1520
1533
  };
1521
1534
  /**
1522
1535
  * The speech model to use for the transcription.
@@ -2551,10 +2564,6 @@ export type Transcript = {
2551
2564
  * List of language codes detected in the audio file when language detection is enabled
2552
2565
  */
2553
2566
  language_codes: LiteralUnion<TranscriptLanguageCode, string>[] | null;
2554
- /**
2555
- * List of detected languages with confidence scores when code switching is enabled
2556
- */
2557
- code_switching_languages?: CodeSwitchingLanguage[] | null;
2558
2567
  /**
2559
2568
  * The confidence threshold for the automatically detected language.
2560
2569
  * An error will be returned if the language confidence is below this threshold.
@@ -2564,6 +2573,10 @@ export type Transcript = {
2564
2573
  * Whether {@link https://www.assemblyai.com/docs/models/speech-recognition#automatic-language-detection | Automatic language detection } is enabled, either true or false
2565
2574
  */
2566
2575
  language_detection?: boolean | null;
2576
+ /**
2577
+ * Language detection results including code switching languages
2578
+ */
2579
+ language_detection_results?: LanguageDetectionResults | null;
2567
2580
  /**
2568
2581
  * @deprecated
2569
2582
  * The language model that was used for the transcript
@@ -8,11 +8,14 @@ export type StreamingTranscriberParams = {
8
8
  endOfTurnConfidenceThreshold?: number;
9
9
  minEndOfTurnSilenceWhenConfident?: number;
10
10
  maxTurnSilence?: number;
11
+ vadThreshold?: number;
11
12
  formatTurns?: boolean;
12
13
  filterProfanity?: boolean;
13
14
  keyterms?: string[];
14
15
  keytermsPrompt?: string[];
15
16
  speechModel?: StreamingSpeechModel;
17
+ languageDetection?: boolean;
18
+ inactivityTimeout?: number;
16
19
  };
17
20
  export type StreamingEvents = "open" | "close" | "turn" | "error";
18
21
  export type StreamingListeners = {
@@ -43,6 +46,8 @@ export type TurnEvent = {
43
46
  transcript: string;
44
47
  end_of_turn_confidence: number;
45
48
  words: StreamingWord[];
49
+ language_code?: string;
50
+ language_confidence?: number;
46
51
  };
47
52
  export type StreamingWord = {
48
53
  start: number;
@@ -64,6 +69,7 @@ export type StreamingUpdateConfiguration = {
64
69
  end_of_turn_confidence_threshold?: number;
65
70
  min_end_of_turn_silence_when_confident?: number;
66
71
  max_turn_silence?: number;
72
+ vad_threshold?: number;
67
73
  format_turns?: boolean;
68
74
  };
69
75
  export type StreamingForceEndpoint = {
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.19.0" },
18
+ sdk: { name: "JavaScript", version: "4.22.0" },
19
19
  };
20
20
  if (typeof process !== "undefined") {
21
21
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -810,6 +810,9 @@ class StreamingTranscriber {
810
810
  if (this.params.maxTurnSilence) {
811
811
  searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
812
812
  }
813
+ if (this.params.vadThreshold !== undefined) {
814
+ searchParams.set("vad_threshold", this.params.vadThreshold.toString());
815
+ }
813
816
  if (this.params.formatTurns) {
814
817
  searchParams.set("format_turns", this.params.formatTurns.toString());
815
818
  }
@@ -829,6 +832,12 @@ class StreamingTranscriber {
829
832
  if (this.params.speechModel) {
830
833
  searchParams.set("speech_model", this.params.speechModel.toString());
831
834
  }
835
+ if (this.params.languageDetection !== undefined) {
836
+ searchParams.set("language_detection", this.params.languageDetection.toString());
837
+ }
838
+ if (this.params.inactivityTimeout !== undefined) {
839
+ searchParams.set("inactivity_timeout", this.params.inactivityTimeout.toString());
840
+ }
832
841
  url.search = searchParams.toString();
833
842
  return url;
834
843
  }
package/docs/compat.md CHANGED
@@ -13,17 +13,19 @@ If you do use an older version of Node.js like version 16, you'll need to polyfi
13
13
  To make the SDK compatible with the browser, the SDK aims to use web standards as much as possible.
14
14
  However, there are still incompatibilities between Node.js and the browser.
15
15
 
16
- - `RealtimeTranscriber` doesn't support the AssemblyAI API key in the browser.
17
- Instead, you have to generate a temporary auth token using `client.realtime.createTemporaryToken`, and pass in the resulting token to the real-time transcriber.
16
+ - `StreamingTranscriber` doesn't support the AssemblyAI API key in the browser.
17
+ Instead, you have to generate a temporary auth token using `client.streaming.createTemporaryToken`, and pass in the resulting token to the streaming transcriber.
18
18
 
19
19
  Generate a temporary auth token on the server.
20
20
 
21
21
  ```js
22
- import { AssemblyAI } from "assemblyai"
22
+ import { AssemblyAI } from "assemblyai";
23
23
  // Ideally, to avoid embedding your API key client side,
24
24
  // you generate this token on the server, and pass it to the client via an API.
25
25
  const client = new AssemblyAI({ apiKey: "YOUR_API_KEY" });
26
- const token = await client.realtime.createTemporaryToken({ expires_in = 480 });
26
+ const token = await client.streaming.createTemporaryToken({
27
+ expires_in_seconds: 60,
28
+ });
27
29
  ```
28
30
 
29
31
  > [!NOTE]
@@ -31,16 +33,16 @@ However, there are still incompatibilities between Node.js and the browser.
31
33
  > If you embed the API key on the client, everyone can see it and use it for themselves.
32
34
 
33
35
  Then pass the token via an API to the client.
34
- On the client, create an instance of `RealtimeTranscriber` using the token.
36
+ On the client, create an instance of `StreamingTranscriber` using the token.
35
37
 
36
38
  ```js
37
- import { RealtimeTranscriber } from "assemblyai";
39
+ import { StreamingTranscriber } from "assemblyai";
38
40
  // or the following if you're using UMD
39
- // const { RealtimeTranscriber } = assemblyai;
41
+ // const { StreamingTranscriber } = assemblyai;
40
42
 
41
43
  const token = getToken(); // getToken is a function for you to implement
42
44
 
43
- const rt = new RealtimeTranscriber({
45
+ const rt = new StreamingTranscriber({
44
46
  token: token,
45
47
  });
46
48
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assemblyai",
3
- "version": "4.19.0",
3
+ "version": "4.22.0",
4
4
  "description": "The AssemblyAI JavaScript SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription, as well as the latest LeMUR models.",
5
5
  "engines": {
6
6
  "node": ">=18"
@@ -97,6 +97,10 @@ export class StreamingTranscriber {
97
97
  );
98
98
  }
99
99
 
100
+ if (this.params.vadThreshold !== undefined) {
101
+ searchParams.set("vad_threshold", this.params.vadThreshold.toString());
102
+ }
103
+
100
104
  if (this.params.formatTurns) {
101
105
  searchParams.set("format_turns", this.params.formatTurns.toString());
102
106
  }
@@ -128,6 +132,20 @@ export class StreamingTranscriber {
128
132
  searchParams.set("speech_model", this.params.speechModel.toString());
129
133
  }
130
134
 
135
+ if (this.params.languageDetection !== undefined) {
136
+ searchParams.set(
137
+ "language_detection",
138
+ this.params.languageDetection.toString(),
139
+ );
140
+ }
141
+
142
+ if (this.params.inactivityTimeout !== undefined) {
143
+ searchParams.set(
144
+ "inactivity_timeout",
145
+ this.params.inactivityTimeout.toString(),
146
+ );
147
+ }
148
+
131
149
  url.search = searchParams.toString();
132
150
 
133
151
  return url;
@@ -1670,6 +1670,16 @@ export type CodeSwitchingLanguage = {
1670
1670
  confidence: number;
1671
1671
  };
1672
1672
 
1673
+ /**
1674
+ * Language detection results including code switching languages
1675
+ */
1676
+ export type LanguageDetectionResults = {
1677
+ /**
1678
+ * List of detected languages with confidence scores when code switching is enabled
1679
+ */
1680
+ code_switching_languages?: CodeSwitchingLanguage[] | null;
1681
+ };
1682
+
1673
1683
  /**
1674
1684
  * Options for controlling the behavior of Automatic Language Detection
1675
1685
  */
@@ -1690,6 +1700,10 @@ export type LanguageDetectionOptions = {
1690
1700
  * The confidence threshold for the automatically detected code switching language.
1691
1701
  */
1692
1702
  code_switching_confidence_threshold?: number | null;
1703
+ /**
1704
+ * Controls behavior when language confidence is below threshold. Either "error" (default) or "fallback".
1705
+ */
1706
+ on_low_language_confidence?: string | null;
1693
1707
  };
1694
1708
 
1695
1709
  /**
@@ -2738,10 +2752,6 @@ export type Transcript = {
2738
2752
  * List of language codes detected in the audio file when language detection is enabled
2739
2753
  */
2740
2754
  language_codes: LiteralUnion<TranscriptLanguageCode, string>[] | null;
2741
- /**
2742
- * List of detected languages with confidence scores when code switching is enabled
2743
- */
2744
- code_switching_languages?: CodeSwitchingLanguage[] | null;
2745
2755
  /**
2746
2756
  * The confidence threshold for the automatically detected language.
2747
2757
  * An error will be returned if the language confidence is below this threshold.
@@ -2751,6 +2761,10 @@ export type Transcript = {
2751
2761
  * Whether {@link https://www.assemblyai.com/docs/models/speech-recognition#automatic-language-detection | Automatic language detection } is enabled, either true or false
2752
2762
  */
2753
2763
  language_detection?: boolean | null;
2764
+ /**
2765
+ * Language detection results including code switching languages
2766
+ */
2767
+ language_detection_results?: LanguageDetectionResults | null;
2754
2768
  /**
2755
2769
  * @deprecated
2756
2770
  * The language model that was used for the transcript
@@ -9,11 +9,14 @@ export type StreamingTranscriberParams = {
9
9
  endOfTurnConfidenceThreshold?: number;
10
10
  minEndOfTurnSilenceWhenConfident?: number;
11
11
  maxTurnSilence?: number;
12
+ vadThreshold?: number;
12
13
  formatTurns?: boolean;
13
14
  filterProfanity?: boolean;
14
15
  keyterms?: string[];
15
16
  keytermsPrompt?: string[];
16
17
  speechModel?: StreamingSpeechModel;
18
+ languageDetection?: boolean;
19
+ inactivityTimeout?: number;
17
20
  };
18
21
 
19
22
  export type StreamingEvents = "open" | "close" | "turn" | "error";
@@ -54,6 +57,8 @@ export type TurnEvent = {
54
57
  transcript: string;
55
58
  end_of_turn_confidence: number;
56
59
  words: StreamingWord[];
60
+ language_code?: string;
61
+ language_confidence?: number;
57
62
  };
58
63
 
59
64
  export type StreamingWord = {
@@ -79,6 +84,7 @@ export type StreamingUpdateConfiguration = {
79
84
  end_of_turn_confidence_threshold?: number;
80
85
  min_end_of_turn_silence_when_confident?: number;
81
86
  max_turn_silence?: number;
87
+ vad_threshold?: number;
82
88
  format_turns?: boolean;
83
89
  };
84
90