assemblyai 4.23.0 → 4.24.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/dist/assemblyai.umd.js +29 -2
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/browser.mjs +32 -2
- package/dist/bun.mjs +32 -2
- package/dist/deno.mjs +32 -2
- package/dist/index.cjs +29 -2
- package/dist/index.mjs +29 -2
- package/dist/node.cjs +32 -2
- package/dist/node.mjs +32 -2
- package/dist/services/streaming/service.d.ts +10 -1
- package/dist/types/openapi.generated.d.ts +13 -0
- package/dist/types/streaming/index.d.ts +13 -1
- package/dist/workerd.mjs +32 -2
- package/package.json +1 -1
- package/src/services/streaming/service.ts +42 -1
- package/src/types/openapi.generated.ts +14 -0
- package/src/types/streaming/index.ts +15 -1
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.24.0" },
|
|
69
69
|
};
|
|
70
70
|
if (typeof process !== "undefined") {
|
|
71
71
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -906,7 +906,11 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
906
906
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
907
907
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
908
908
|
}
|
|
909
|
-
if (this.params.
|
|
909
|
+
if (this.params.minTurnSilence) {
|
|
910
|
+
searchParams.set("min_turn_silence", this.params.minTurnSilence.toString());
|
|
911
|
+
}
|
|
912
|
+
else if (this.params.minEndOfTurnSilenceWhenConfident) {
|
|
913
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
910
914
|
searchParams.set("min_end_of_turn_silence_when_confident", this.params.minEndOfTurnSilenceWhenConfident.toString());
|
|
911
915
|
}
|
|
912
916
|
if (this.params.maxTurnSilence) {
|
|
@@ -928,10 +932,16 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
928
932
|
console.warn("[Deprecation Warning] `keyterms` is deprecated and will be removed in a future release. Please use `keytermsPrompt` instead.");
|
|
929
933
|
searchParams.set("keyterms_prompt", JSON.stringify(this.params.keyterms));
|
|
930
934
|
}
|
|
935
|
+
if (this.params.prompt) {
|
|
936
|
+
searchParams.set("prompt", this.params.prompt);
|
|
937
|
+
}
|
|
931
938
|
if (this.params.filterProfanity) {
|
|
932
939
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
933
940
|
}
|
|
934
941
|
if (this.params.speechModel) {
|
|
942
|
+
if (this.params.speechModel === "u3-pro") {
|
|
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
|
+
}
|
|
935
945
|
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
936
946
|
}
|
|
937
947
|
if (this.params.languageDetection !== undefined) {
|
|
@@ -1018,6 +1028,23 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
1018
1028
|
sendAudio(audio) {
|
|
1019
1029
|
this.send(audio);
|
|
1020
1030
|
}
|
|
1031
|
+
/**
|
|
1032
|
+
* Update the streaming configuration mid-stream.
|
|
1033
|
+
* @param config - The configuration parameters to update
|
|
1034
|
+
*/
|
|
1035
|
+
updateConfiguration(config) {
|
|
1036
|
+
const message = Object.assign({ type: "UpdateConfiguration" }, config);
|
|
1037
|
+
this.send(JSON.stringify(message));
|
|
1038
|
+
}
|
|
1039
|
+
/**
|
|
1040
|
+
* Force the current turn to end immediately.
|
|
1041
|
+
*/
|
|
1042
|
+
forceEndpoint() {
|
|
1043
|
+
const message = {
|
|
1044
|
+
type: "ForceEndpoint",
|
|
1045
|
+
};
|
|
1046
|
+
this.send(JSON.stringify(message));
|
|
1047
|
+
}
|
|
1021
1048
|
send(data) {
|
|
1022
1049
|
if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
|
|
1023
1050
|
throw new Error("Socket is not open for communication");
|
|
@@ -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.23.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}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).assemblyai={})}(this,(function(e){"use strict";function t(e,t,s,i){return new(s||(s=Promise))((function(n,r){function o(e){try{c(i.next(e))}catch(e){r(e)}}function a(e){try{c(i.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}c((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s={cache:"no-store"};let i="";"undefined"!=typeof navigator&&navigator.userAgent&&(i+=navigator.userAgent);const n={sdk:{name:"JavaScript",version:"4.24.0"}};"undefined"!=typeof process&&(process.versions.node&&-1===i.indexOf("Node")&&(n.runtime_env={name:"Node",version:process.versions.node}),process.versions.bun&&-1===i.indexOf("Bun")&&(n.runtime_env={name:"Bun",version:process.versions.bun})),"undefined"!=typeof Deno&&process.versions.bun&&-1===i.indexOf("Deno")&&(n.runtime_env={name:"Deno",version:Deno.version.deno});class r{constructor(e){var t;this.params=e,!1===e.userAgent?this.userAgent=void 0:this.userAgent=(t=e.userAgent||{},i+(!1===t?"":" AssemblyAI/1.0 ("+Object.entries(Object.assign(Object.assign({},n),t)).map((([e,t])=>t?`${e}=${t.name}/${t.version}`:"")).join(" ")+")"))}fetch(e,i){return t(this,void 0,void 0,(function*(){i=Object.assign(Object.assign({},s),i);let t={Authorization:this.params.apiKey,"Content-Type":"application/json"};(null==s?void 0:s.headers)&&(t=Object.assign(Object.assign({},t),s.headers)),(null==i?void 0:i.headers)&&(t=Object.assign(Object.assign({},t),i.headers)),this.userAgent&&(t["User-Agent"]=this.userAgent,"undefined"!=typeof window&&"chrome"in window&&(t["AssemblyAI-Agent"]=this.userAgent)),i.headers=t,e.startsWith("http")||(e=this.params.baseUrl+e);const n=yield fetch(e,i);if(n.status>=400){let e;const t=yield n.text();if(t){try{e=JSON.parse(t)}catch(e){}if(null==e?void 0:e.error)throw new Error(e.error);throw new Error(t)}throw new Error(`HTTP Error: ${n.status} ${n.statusText}`)}return n}))}fetchJson(e,s){return t(this,void 0,void 0,(function*(){return(yield this.fetch(e,s)).json()}))}}class o extends r{summary(e,t){return this.fetchJson("/lemur/v3/generate/summary",{method:"POST",body:JSON.stringify(e),signal:t})}questionAnswer(e,t){return this.fetchJson("/lemur/v3/generate/question-answer",{method:"POST",body:JSON.stringify(e),signal:t})}actionItems(e,t){return this.fetchJson("/lemur/v3/generate/action-items",{method:"POST",body:JSON.stringify(e),signal:t})}task(e,t){return this.fetchJson("/lemur/v3/generate/task",{method:"POST",body:JSON.stringify(e),signal:t})}getResponse(e,t){return this.fetchJson(`/lemur/v3/${e}`,{signal:t})}purgeRequestData(e,t){return this.fetchJson(`/lemur/v3/${e}`,{method:"DELETE",signal:t})}}const{WritableStream:a}="undefined"!=typeof window?window:"undefined"!=typeof global?global:globalThis;var 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,n;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(n=(i=this.listeners).error)||void 0===n||n.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,n,r,o,a,c,l,d,h,u,m,f,v,y;const g=JSON.parse(t.toString());if("error"in g)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new p(g.error));else switch(g.message_type){case"SessionBegins":{const t={sessionId:g.session_id,expiresAt:new Date(g.expires_at)};e(t),null===(r=(n=this.listeners).open)||void 0===r||r.call(n,t);break}case"PartialTranscript":g.created=new Date(g.created),null===(a=(o=this.listeners).transcript)||void 0===a||a.call(o,g),null===(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 r{constructor(e){super(e),this.rtFactoryParams=e}createService(e){return this.transcriber(e)}transcriber(e){const t=Object.assign({},e);return t.token||t.apiKey||(t.apiKey=this.rtFactoryParams.apiKey),new y(t)}createTemporaryToken(e){return t(this,void 0,void 0,(function*(){return(yield this.fetchJson("/v2/realtime/token",{method:"POST",body:JSON.stringify(e)})).token}))}}function b(e){return e.startsWith("http")||e.startsWith("https")||e.startsWith("data:")?null:e.startsWith("file://")?e.substring(7):e.startsWith("file:")?e.substring(5):e}class w extends r{constructor(e,t){super(e),this.files=t}transcribe(e,s){return t(this,void 0,void 0,(function*(){const t=yield this.submit(e);return yield this.waitUntilReady(t.id,s)}))}submit(e){return t(this,void 0,void 0,(function*(){let t,s;if("audio"in e){const{audio:i}=e,n=function(e,t){var s={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(s[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(s[i[n]]=e[i[n]])}return s}(e,["audio"]);if("string"==typeof i){const e=b(i);t=null!==e?yield this.files.upload(e):i.startsWith("data:")?yield this.files.upload(i):i}else t=yield this.files.upload(i);s=Object.assign(Object.assign({},n),{audio_url:t})}else s=e;return yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(s)})}))}create(e,s){return t(this,void 0,void 0,(function*(){var t;const i=b(e.audio_url);if(null!==i){const t=yield this.files.upload(i);e.audio_url=t}const n=yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(e)});return null===(t=null==s?void 0:s.poll)||void 0===t||t?yield this.waitUntilReady(n.id,s):n}))}waitUntilReady(e,s){return t(this,void 0,void 0,(function*(){var t,i;const n=null!==(t=null==s?void 0:s.pollingInterval)&&void 0!==t?t:3e3,r=null!==(i=null==s?void 0:s.pollingTimeout)&&void 0!==i?i:-1,o=Date.now();for(;;){const t=yield this.get(e);if("completed"===t.status||"error"===t.status)return t;if(r>0&&Date.now()-o>r)throw new Error("Polling timeout");yield new Promise((e=>setTimeout(e,n)))}}))}get(e){return this.fetchJson(`/v2/transcript/${e}`)}list(e){return t(this,void 0,void 0,(function*(){let t="/v2/transcript";"string"==typeof e?t=e:e&&(t=`${t}?${new URLSearchParams(Object.keys(e).map((t=>{var s;return[t,(null===(s=e[t])||void 0===s?void 0:s.toString())||""]})))}`);const s=yield this.fetchJson(t);for(const e of s.transcripts)e.created=new Date(e.created),e.completed&&(e.completed=new Date(e.completed));return s}))}delete(e){return this.fetchJson(`/v2/transcript/${e}`,{method:"DELETE"})}wordSearch(e,t){const s=new URLSearchParams({words:t.join(",")});return this.fetchJson(`/v2/transcript/${e}/word-search?${s.toString()}`)}sentences(e){return this.fetchJson(`/v2/transcript/${e}/sentences`)}paragraphs(e){return this.fetchJson(`/v2/transcript/${e}/paragraphs`)}subtitles(e){return t(this,arguments,void 0,(function*(e,t="srt",s){let i=`/v2/transcript/${e}/${t}`;if(s){const e=new URLSearchParams;e.set("chars_per_caption",s.toString()),i+=`?${e.toString()}`}const n=yield this.fetch(i);return yield n.text()}))}redactions(e){return this.redactedAudio(e)}redactedAudio(e){return this.fetchJson(`/v2/transcript/${e}/redacted-audio`)}redactedAudioFile(e){return t(this,void 0,void 0,(function*(){const{redacted_audio_url:t,status:s}=yield this.redactedAudio(e);if("redacted_audio_ready"!==s)throw new Error(`Redacted audio status is ${s}`);const i=yield fetch(t);if(!i.ok)throw new Error(`Failed to fetch redacted audio: ${i.statusText}`);return{arrayBuffer:i.arrayBuffer.bind(i),blob:i.blob.bind(i),body:i.body,bodyUsed:i.bodyUsed}}))}}class S extends r{upload(e){return t(this,void 0,void 0,(function*(){let s;s="string"==typeof e?e.startsWith("data:")?function(e){const t=e.split(","),s=t[0].match(/:(.*?);/)[1],i=atob(t[1]);let n=i.length;const r=new Uint8Array(n);for(;n--;)r[n]=i.charCodeAt(n);return new Blob([r],{type:s})}(e):yield function(e){return t(this,void 0,void 0,(function*(){throw new Error("Interacting with the file system is not supported in this environment.")}))}():e;return(yield this.fetchJson("/v2/upload",{method:"POST",body:s,headers:{"Content-Type":"application/octet-stream"},duplex:"half"})).upload_url}))}}const k='{"type":"Terminate"}';class T{constructor(e){if(this.listeners={},this.params=Object.assign(Object.assign({},e),{websocketBaseUrl:e.websocketBaseUrl||"wss://streaming.assemblyai.com/v3/ws"}),"token"in e&&e.token&&(this.token=e.token),"apiKey"in e&&e.apiKey&&(this.apiKey=e.apiKey),!this.token&&!this.apiKey)throw new Error("API key or temporary token is required.")}connectionUrl(){var e;const t=new URL(null!==(e=this.params.websocketBaseUrl)&&void 0!==e?e:"");if("wss:"!==t.protocol)throw new Error("Invalid protocol, must be wss");const s=new URLSearchParams;return this.token&&s.set("token",this.token),s.set("sample_rate",this.params.sampleRate.toString()),this.params.endOfTurnConfidenceThreshold&&s.set("end_of_turn_confidence_threshold",this.params.endOfTurnConfidenceThreshold.toString()),this.params.minTurnSilence?s.set("min_turn_silence",this.params.minTurnSilence.toString()):this.params.minEndOfTurnSilenceWhenConfident&&(console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead."),s.set("min_end_of_turn_silence_when_confident",this.params.minEndOfTurnSilenceWhenConfident.toString())),this.params.maxTurnSilence&&s.set("max_turn_silence",this.params.maxTurnSilence.toString()),void 0!==this.params.vadThreshold&&s.set("vad_threshold",this.params.vadThreshold.toString()),this.params.formatTurns&&s.set("format_turns",this.params.formatTurns.toString()),this.params.encoding&&s.set("encoding",this.params.encoding.toString()),this.params.keytermsPrompt?s.set("keyterms_prompt",JSON.stringify(this.params.keytermsPrompt)):this.params.keyterms&&(console.warn("[Deprecation Warning] `keyterms` is deprecated and will be removed in a future release. Please use `keytermsPrompt` instead."),s.set("keyterms_prompt",JSON.stringify(this.params.keyterms))),this.params.prompt&&s.set("prompt",this.params.prompt),this.params.filterProfanity&&s.set("filter_profanity",this.params.filterProfanity.toString()),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()),t.search=s.toString(),t}on(e,t){this.listeners[e]=t}connect(){return new Promise((e=>{if(this.socket)throw new Error("Already connected");const t=this.connectionUrl();this.token?this.socket=h(t.toString()):(console.warn("API key authentication is not supported for the StreamingTranscriber in browser environment. Use temporary token authentication instead.\nLearn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/compat.md#browser-compatibility."),this.socket=h(t.toString(),{headers:{Authorization:this.apiKey}})),this.socket.binaryType="arraybuffer",this.socket.onopen=()=>{},this.socket.onclose=({code:e,reason:t})=>{var s,i;t||e in m&&(t=m[e]),null===(i=(s=this.listeners).close)||void 0===i||i.call(s,e,t)},this.socket.onerror=e=>{var t,s,i,n;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(n=(i=this.listeners).error)||void 0===n||n.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,n,r,o,a,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===(r=(n=this.listeners).open)||void 0===r||r.call(n,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)}updateConfiguration(e){const t=Object.assign({type:"UpdateConfiguration"},e);this.send(JSON.stringify(t))}forceEndpoint(){this.send(JSON.stringify({type:"ForceEndpoint"}))}send(e){if(!this.socket||this.socket.readyState!==this.socket.OPEN)throw new Error("Socket is not open for communication");this.socket.send(e)}close(){return t(this,arguments,void 0,(function*(e=!0){var t;if(this.socket){if(this.socket.readyState===this.socket.OPEN)if(e){const e=new Promise((e=>{this.sessionTerminatedResolve=e}));this.socket.send(k),yield e}else this.socket.send(k);(null===(t=this.socket)||void 0===t?void 0:t.removeAllListeners)&&this.socket.removeAllListeners(),this.socket.close()}this.listeners={},this.socket=void 0}))}}class O extends r{constructor(e){super(e),this.baseServiceParams=e}transcriber(e){const t=Object.assign({},e);return t.token||t.apiKey||(t.apiKey=this.baseServiceParams.apiKey),new T(t)}createTemporaryToken(e){return t(this,void 0,void 0,(function*(){const t=new URLSearchParams;Object.entries(e).forEach((([e,s])=>{null!=s&&t.append(e,String(s))}));const s=t.toString(),i=s?`/v3/token?${s}`:"/v3/token";return(yield this.fetchJson(i,{method:"GET"})).token}))}}e.AssemblyAI=class{constructor(e){e.baseUrl=e.baseUrl||"https://api.assemblyai.com",e.baseUrl&&e.baseUrl.endsWith("/")&&(e.baseUrl=e.baseUrl.slice(0,-1)),this.files=new S(e),this.transcripts=new w(e,this.files),this.lemur=new o(e),this.realtime=new g(e),this.streaming=new O(Object.assign(Object.assign({},e),{baseUrl:e.streamingBaseUrl||"https://streaming.assemblyai.com"}))}},e.FileService=S,e.LemurService=o,e.RealtimeService=class extends y{},e.RealtimeServiceFactory=class extends g{},e.RealtimeTranscriber=y,e.RealtimeTranscriberFactory=g,e.StreamingTranscriber=T,e.TranscriptService=w}));
|
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.24.0" },
|
|
19
19
|
};
|
|
20
20
|
if (typeof process !== "undefined") {
|
|
21
21
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -821,7 +821,11 @@ class StreamingTranscriber {
|
|
|
821
821
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
822
822
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
823
823
|
}
|
|
824
|
-
if (this.params.
|
|
824
|
+
if (this.params.minTurnSilence) {
|
|
825
|
+
searchParams.set("min_turn_silence", this.params.minTurnSilence.toString());
|
|
826
|
+
}
|
|
827
|
+
else if (this.params.minEndOfTurnSilenceWhenConfident) {
|
|
828
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
825
829
|
searchParams.set("min_end_of_turn_silence_when_confident", this.params.minEndOfTurnSilenceWhenConfident.toString());
|
|
826
830
|
}
|
|
827
831
|
if (this.params.maxTurnSilence) {
|
|
@@ -843,10 +847,16 @@ class StreamingTranscriber {
|
|
|
843
847
|
console.warn("[Deprecation Warning] `keyterms` is deprecated and will be removed in a future release. Please use `keytermsPrompt` instead.");
|
|
844
848
|
searchParams.set("keyterms_prompt", JSON.stringify(this.params.keyterms));
|
|
845
849
|
}
|
|
850
|
+
if (this.params.prompt) {
|
|
851
|
+
searchParams.set("prompt", this.params.prompt);
|
|
852
|
+
}
|
|
846
853
|
if (this.params.filterProfanity) {
|
|
847
854
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
848
855
|
}
|
|
849
856
|
if (this.params.speechModel) {
|
|
857
|
+
if (this.params.speechModel === "u3-pro") {
|
|
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
|
+
}
|
|
850
860
|
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
851
861
|
}
|
|
852
862
|
if (this.params.languageDetection !== undefined) {
|
|
@@ -930,6 +940,26 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
930
940
|
sendAudio(audio) {
|
|
931
941
|
this.send(audio);
|
|
932
942
|
}
|
|
943
|
+
/**
|
|
944
|
+
* Update the streaming configuration mid-stream.
|
|
945
|
+
* @param config - The configuration parameters to update
|
|
946
|
+
*/
|
|
947
|
+
updateConfiguration(config) {
|
|
948
|
+
const message = {
|
|
949
|
+
type: "UpdateConfiguration",
|
|
950
|
+
...config,
|
|
951
|
+
};
|
|
952
|
+
this.send(JSON.stringify(message));
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* Force the current turn to end immediately.
|
|
956
|
+
*/
|
|
957
|
+
forceEndpoint() {
|
|
958
|
+
const message = {
|
|
959
|
+
type: "ForceEndpoint",
|
|
960
|
+
};
|
|
961
|
+
this.send(JSON.stringify(message));
|
|
962
|
+
}
|
|
933
963
|
send(data) {
|
|
934
964
|
if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
|
|
935
965
|
throw new Error("Socket is not open for communication");
|
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.24.0" },
|
|
21
21
|
};
|
|
22
22
|
if (typeof process !== "undefined") {
|
|
23
23
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -802,7 +802,11 @@ class StreamingTranscriber {
|
|
|
802
802
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
803
803
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
804
804
|
}
|
|
805
|
-
if (this.params.
|
|
805
|
+
if (this.params.minTurnSilence) {
|
|
806
|
+
searchParams.set("min_turn_silence", this.params.minTurnSilence.toString());
|
|
807
|
+
}
|
|
808
|
+
else if (this.params.minEndOfTurnSilenceWhenConfident) {
|
|
809
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
806
810
|
searchParams.set("min_end_of_turn_silence_when_confident", this.params.minEndOfTurnSilenceWhenConfident.toString());
|
|
807
811
|
}
|
|
808
812
|
if (this.params.maxTurnSilence) {
|
|
@@ -824,10 +828,16 @@ class StreamingTranscriber {
|
|
|
824
828
|
console.warn("[Deprecation Warning] `keyterms` is deprecated and will be removed in a future release. Please use `keytermsPrompt` instead.");
|
|
825
829
|
searchParams.set("keyterms_prompt", JSON.stringify(this.params.keyterms));
|
|
826
830
|
}
|
|
831
|
+
if (this.params.prompt) {
|
|
832
|
+
searchParams.set("prompt", this.params.prompt);
|
|
833
|
+
}
|
|
827
834
|
if (this.params.filterProfanity) {
|
|
828
835
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
829
836
|
}
|
|
830
837
|
if (this.params.speechModel) {
|
|
838
|
+
if (this.params.speechModel === "u3-pro") {
|
|
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
|
+
}
|
|
831
841
|
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
832
842
|
}
|
|
833
843
|
if (this.params.languageDetection !== undefined) {
|
|
@@ -907,6 +917,26 @@ class StreamingTranscriber {
|
|
|
907
917
|
sendAudio(audio) {
|
|
908
918
|
this.send(audio);
|
|
909
919
|
}
|
|
920
|
+
/**
|
|
921
|
+
* Update the streaming configuration mid-stream.
|
|
922
|
+
* @param config - The configuration parameters to update
|
|
923
|
+
*/
|
|
924
|
+
updateConfiguration(config) {
|
|
925
|
+
const message = {
|
|
926
|
+
type: "UpdateConfiguration",
|
|
927
|
+
...config,
|
|
928
|
+
};
|
|
929
|
+
this.send(JSON.stringify(message));
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Force the current turn to end immediately.
|
|
933
|
+
*/
|
|
934
|
+
forceEndpoint() {
|
|
935
|
+
const message = {
|
|
936
|
+
type: "ForceEndpoint",
|
|
937
|
+
};
|
|
938
|
+
this.send(JSON.stringify(message));
|
|
939
|
+
}
|
|
910
940
|
send(data) {
|
|
911
941
|
if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
|
|
912
942
|
throw new Error("Socket is not open for communication");
|
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.24.0" },
|
|
21
21
|
};
|
|
22
22
|
if (typeof process !== "undefined") {
|
|
23
23
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -802,7 +802,11 @@ class StreamingTranscriber {
|
|
|
802
802
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
803
803
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
804
804
|
}
|
|
805
|
-
if (this.params.
|
|
805
|
+
if (this.params.minTurnSilence) {
|
|
806
|
+
searchParams.set("min_turn_silence", this.params.minTurnSilence.toString());
|
|
807
|
+
}
|
|
808
|
+
else if (this.params.minEndOfTurnSilenceWhenConfident) {
|
|
809
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
806
810
|
searchParams.set("min_end_of_turn_silence_when_confident", this.params.minEndOfTurnSilenceWhenConfident.toString());
|
|
807
811
|
}
|
|
808
812
|
if (this.params.maxTurnSilence) {
|
|
@@ -824,10 +828,16 @@ class StreamingTranscriber {
|
|
|
824
828
|
console.warn("[Deprecation Warning] `keyterms` is deprecated and will be removed in a future release. Please use `keytermsPrompt` instead.");
|
|
825
829
|
searchParams.set("keyterms_prompt", JSON.stringify(this.params.keyterms));
|
|
826
830
|
}
|
|
831
|
+
if (this.params.prompt) {
|
|
832
|
+
searchParams.set("prompt", this.params.prompt);
|
|
833
|
+
}
|
|
827
834
|
if (this.params.filterProfanity) {
|
|
828
835
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
829
836
|
}
|
|
830
837
|
if (this.params.speechModel) {
|
|
838
|
+
if (this.params.speechModel === "u3-pro") {
|
|
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
|
+
}
|
|
831
841
|
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
832
842
|
}
|
|
833
843
|
if (this.params.languageDetection !== undefined) {
|
|
@@ -907,6 +917,26 @@ class StreamingTranscriber {
|
|
|
907
917
|
sendAudio(audio) {
|
|
908
918
|
this.send(audio);
|
|
909
919
|
}
|
|
920
|
+
/**
|
|
921
|
+
* Update the streaming configuration mid-stream.
|
|
922
|
+
* @param config - The configuration parameters to update
|
|
923
|
+
*/
|
|
924
|
+
updateConfiguration(config) {
|
|
925
|
+
const message = {
|
|
926
|
+
type: "UpdateConfiguration",
|
|
927
|
+
...config,
|
|
928
|
+
};
|
|
929
|
+
this.send(JSON.stringify(message));
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Force the current turn to end immediately.
|
|
933
|
+
*/
|
|
934
|
+
forceEndpoint() {
|
|
935
|
+
const message = {
|
|
936
|
+
type: "ForceEndpoint",
|
|
937
|
+
};
|
|
938
|
+
this.send(JSON.stringify(message));
|
|
939
|
+
}
|
|
910
940
|
send(data) {
|
|
911
941
|
if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
|
|
912
942
|
throw new Error("Socket is not open for communication");
|
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.24.0" },
|
|
67
67
|
};
|
|
68
68
|
if (typeof process !== "undefined") {
|
|
69
69
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -893,7 +893,11 @@ class StreamingTranscriber {
|
|
|
893
893
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
894
894
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
895
895
|
}
|
|
896
|
-
if (this.params.
|
|
896
|
+
if (this.params.minTurnSilence) {
|
|
897
|
+
searchParams.set("min_turn_silence", this.params.minTurnSilence.toString());
|
|
898
|
+
}
|
|
899
|
+
else if (this.params.minEndOfTurnSilenceWhenConfident) {
|
|
900
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
897
901
|
searchParams.set("min_end_of_turn_silence_when_confident", this.params.minEndOfTurnSilenceWhenConfident.toString());
|
|
898
902
|
}
|
|
899
903
|
if (this.params.maxTurnSilence) {
|
|
@@ -915,10 +919,16 @@ class StreamingTranscriber {
|
|
|
915
919
|
console.warn("[Deprecation Warning] `keyterms` is deprecated and will be removed in a future release. Please use `keytermsPrompt` instead.");
|
|
916
920
|
searchParams.set("keyterms_prompt", JSON.stringify(this.params.keyterms));
|
|
917
921
|
}
|
|
922
|
+
if (this.params.prompt) {
|
|
923
|
+
searchParams.set("prompt", this.params.prompt);
|
|
924
|
+
}
|
|
918
925
|
if (this.params.filterProfanity) {
|
|
919
926
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
920
927
|
}
|
|
921
928
|
if (this.params.speechModel) {
|
|
929
|
+
if (this.params.speechModel === "u3-pro") {
|
|
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
|
+
}
|
|
922
932
|
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
923
933
|
}
|
|
924
934
|
if (this.params.languageDetection !== undefined) {
|
|
@@ -1001,6 +1011,23 @@ class StreamingTranscriber {
|
|
|
1001
1011
|
sendAudio(audio) {
|
|
1002
1012
|
this.send(audio);
|
|
1003
1013
|
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Update the streaming configuration mid-stream.
|
|
1016
|
+
* @param config - The configuration parameters to update
|
|
1017
|
+
*/
|
|
1018
|
+
updateConfiguration(config) {
|
|
1019
|
+
const message = Object.assign({ type: "UpdateConfiguration" }, config);
|
|
1020
|
+
this.send(JSON.stringify(message));
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Force the current turn to end immediately.
|
|
1024
|
+
*/
|
|
1025
|
+
forceEndpoint() {
|
|
1026
|
+
const message = {
|
|
1027
|
+
type: "ForceEndpoint",
|
|
1028
|
+
};
|
|
1029
|
+
this.send(JSON.stringify(message));
|
|
1030
|
+
}
|
|
1004
1031
|
send(data) {
|
|
1005
1032
|
if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
|
|
1006
1033
|
throw new Error("Socket is not open for communication");
|
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.24.0" },
|
|
65
65
|
};
|
|
66
66
|
if (typeof process !== "undefined") {
|
|
67
67
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -891,7 +891,11 @@ class StreamingTranscriber {
|
|
|
891
891
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
892
892
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
893
893
|
}
|
|
894
|
-
if (this.params.
|
|
894
|
+
if (this.params.minTurnSilence) {
|
|
895
|
+
searchParams.set("min_turn_silence", this.params.minTurnSilence.toString());
|
|
896
|
+
}
|
|
897
|
+
else if (this.params.minEndOfTurnSilenceWhenConfident) {
|
|
898
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
895
899
|
searchParams.set("min_end_of_turn_silence_when_confident", this.params.minEndOfTurnSilenceWhenConfident.toString());
|
|
896
900
|
}
|
|
897
901
|
if (this.params.maxTurnSilence) {
|
|
@@ -913,10 +917,16 @@ class StreamingTranscriber {
|
|
|
913
917
|
console.warn("[Deprecation Warning] `keyterms` is deprecated and will be removed in a future release. Please use `keytermsPrompt` instead.");
|
|
914
918
|
searchParams.set("keyterms_prompt", JSON.stringify(this.params.keyterms));
|
|
915
919
|
}
|
|
920
|
+
if (this.params.prompt) {
|
|
921
|
+
searchParams.set("prompt", this.params.prompt);
|
|
922
|
+
}
|
|
916
923
|
if (this.params.filterProfanity) {
|
|
917
924
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
918
925
|
}
|
|
919
926
|
if (this.params.speechModel) {
|
|
927
|
+
if (this.params.speechModel === "u3-pro") {
|
|
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
|
+
}
|
|
920
930
|
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
921
931
|
}
|
|
922
932
|
if (this.params.languageDetection !== undefined) {
|
|
@@ -999,6 +1009,23 @@ class StreamingTranscriber {
|
|
|
999
1009
|
sendAudio(audio) {
|
|
1000
1010
|
this.send(audio);
|
|
1001
1011
|
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Update the streaming configuration mid-stream.
|
|
1014
|
+
* @param config - The configuration parameters to update
|
|
1015
|
+
*/
|
|
1016
|
+
updateConfiguration(config) {
|
|
1017
|
+
const message = Object.assign({ type: "UpdateConfiguration" }, config);
|
|
1018
|
+
this.send(JSON.stringify(message));
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Force the current turn to end immediately.
|
|
1022
|
+
*/
|
|
1023
|
+
forceEndpoint() {
|
|
1024
|
+
const message = {
|
|
1025
|
+
type: "ForceEndpoint",
|
|
1026
|
+
};
|
|
1027
|
+
this.send(JSON.stringify(message));
|
|
1028
|
+
}
|
|
1002
1029
|
send(data) {
|
|
1003
1030
|
if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
|
|
1004
1031
|
throw new Error("Socket is not open for communication");
|
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.24.0" },
|
|
26
26
|
};
|
|
27
27
|
if (typeof process !== "undefined") {
|
|
28
28
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -801,7 +801,11 @@ class StreamingTranscriber {
|
|
|
801
801
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
802
802
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
803
803
|
}
|
|
804
|
-
if (this.params.
|
|
804
|
+
if (this.params.minTurnSilence) {
|
|
805
|
+
searchParams.set("min_turn_silence", this.params.minTurnSilence.toString());
|
|
806
|
+
}
|
|
807
|
+
else if (this.params.minEndOfTurnSilenceWhenConfident) {
|
|
808
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
805
809
|
searchParams.set("min_end_of_turn_silence_when_confident", this.params.minEndOfTurnSilenceWhenConfident.toString());
|
|
806
810
|
}
|
|
807
811
|
if (this.params.maxTurnSilence) {
|
|
@@ -823,10 +827,16 @@ class StreamingTranscriber {
|
|
|
823
827
|
console.warn("[Deprecation Warning] `keyterms` is deprecated and will be removed in a future release. Please use `keytermsPrompt` instead.");
|
|
824
828
|
searchParams.set("keyterms_prompt", JSON.stringify(this.params.keyterms));
|
|
825
829
|
}
|
|
830
|
+
if (this.params.prompt) {
|
|
831
|
+
searchParams.set("prompt", this.params.prompt);
|
|
832
|
+
}
|
|
826
833
|
if (this.params.filterProfanity) {
|
|
827
834
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
828
835
|
}
|
|
829
836
|
if (this.params.speechModel) {
|
|
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.");
|
|
839
|
+
}
|
|
830
840
|
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
831
841
|
}
|
|
832
842
|
if (this.params.languageDetection !== undefined) {
|
|
@@ -906,6 +916,26 @@ class StreamingTranscriber {
|
|
|
906
916
|
sendAudio(audio) {
|
|
907
917
|
this.send(audio);
|
|
908
918
|
}
|
|
919
|
+
/**
|
|
920
|
+
* Update the streaming configuration mid-stream.
|
|
921
|
+
* @param config - The configuration parameters to update
|
|
922
|
+
*/
|
|
923
|
+
updateConfiguration(config) {
|
|
924
|
+
const message = {
|
|
925
|
+
type: "UpdateConfiguration",
|
|
926
|
+
...config,
|
|
927
|
+
};
|
|
928
|
+
this.send(JSON.stringify(message));
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Force the current turn to end immediately.
|
|
932
|
+
*/
|
|
933
|
+
forceEndpoint() {
|
|
934
|
+
const message = {
|
|
935
|
+
type: "ForceEndpoint",
|
|
936
|
+
};
|
|
937
|
+
this.send(JSON.stringify(message));
|
|
938
|
+
}
|
|
909
939
|
send(data) {
|
|
910
940
|
if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
|
|
911
941
|
throw new Error("Socket is not open for communication");
|
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.24.0" },
|
|
24
24
|
};
|
|
25
25
|
if (typeof process !== "undefined") {
|
|
26
26
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -799,7 +799,11 @@ class StreamingTranscriber {
|
|
|
799
799
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
800
800
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
801
801
|
}
|
|
802
|
-
if (this.params.
|
|
802
|
+
if (this.params.minTurnSilence) {
|
|
803
|
+
searchParams.set("min_turn_silence", this.params.minTurnSilence.toString());
|
|
804
|
+
}
|
|
805
|
+
else if (this.params.minEndOfTurnSilenceWhenConfident) {
|
|
806
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
803
807
|
searchParams.set("min_end_of_turn_silence_when_confident", this.params.minEndOfTurnSilenceWhenConfident.toString());
|
|
804
808
|
}
|
|
805
809
|
if (this.params.maxTurnSilence) {
|
|
@@ -821,10 +825,16 @@ class StreamingTranscriber {
|
|
|
821
825
|
console.warn("[Deprecation Warning] `keyterms` is deprecated and will be removed in a future release. Please use `keytermsPrompt` instead.");
|
|
822
826
|
searchParams.set("keyterms_prompt", JSON.stringify(this.params.keyterms));
|
|
823
827
|
}
|
|
828
|
+
if (this.params.prompt) {
|
|
829
|
+
searchParams.set("prompt", this.params.prompt);
|
|
830
|
+
}
|
|
824
831
|
if (this.params.filterProfanity) {
|
|
825
832
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
826
833
|
}
|
|
827
834
|
if (this.params.speechModel) {
|
|
835
|
+
if (this.params.speechModel === "u3-pro") {
|
|
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
|
+
}
|
|
828
838
|
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
829
839
|
}
|
|
830
840
|
if (this.params.languageDetection !== undefined) {
|
|
@@ -904,6 +914,26 @@ class StreamingTranscriber {
|
|
|
904
914
|
sendAudio(audio) {
|
|
905
915
|
this.send(audio);
|
|
906
916
|
}
|
|
917
|
+
/**
|
|
918
|
+
* Update the streaming configuration mid-stream.
|
|
919
|
+
* @param config - The configuration parameters to update
|
|
920
|
+
*/
|
|
921
|
+
updateConfiguration(config) {
|
|
922
|
+
const message = {
|
|
923
|
+
type: "UpdateConfiguration",
|
|
924
|
+
...config,
|
|
925
|
+
};
|
|
926
|
+
this.send(JSON.stringify(message));
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* Force the current turn to end immediately.
|
|
930
|
+
*/
|
|
931
|
+
forceEndpoint() {
|
|
932
|
+
const message = {
|
|
933
|
+
type: "ForceEndpoint",
|
|
934
|
+
};
|
|
935
|
+
this.send(JSON.stringify(message));
|
|
936
|
+
}
|
|
907
937
|
send(data) {
|
|
908
938
|
if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
|
|
909
939
|
throw new Error("Socket is not open for communication");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StreamingTranscriberParams, AudioData, BeginEvent, TurnEvent } from "../..";
|
|
1
|
+
import { StreamingTranscriberParams, AudioData, BeginEvent, TurnEvent, StreamingUpdateConfiguration } from "../..";
|
|
2
2
|
export declare class StreamingTranscriber {
|
|
3
3
|
private apiKey?;
|
|
4
4
|
private token?;
|
|
@@ -15,6 +15,15 @@ export declare class StreamingTranscriber {
|
|
|
15
15
|
connect(): Promise<BeginEvent>;
|
|
16
16
|
stream(): WritableStream<AudioData>;
|
|
17
17
|
sendAudio(audio: AudioData): void;
|
|
18
|
+
/**
|
|
19
|
+
* Update the streaming configuration mid-stream.
|
|
20
|
+
* @param config - The configuration parameters to update
|
|
21
|
+
*/
|
|
22
|
+
updateConfiguration(config: Omit<StreamingUpdateConfiguration, "type">): void;
|
|
23
|
+
/**
|
|
24
|
+
* Force the current turn to end immediately.
|
|
25
|
+
*/
|
|
26
|
+
forceEndpoint(): void;
|
|
18
27
|
private send;
|
|
19
28
|
close(waitForSessionTermination?: boolean): Promise<void>;
|
|
20
29
|
}
|
|
@@ -1535,6 +1535,15 @@ export type LanguageDetectionOptions = {
|
|
|
1535
1535
|
*/
|
|
1536
1536
|
swiss_german?: boolean | null;
|
|
1537
1537
|
};
|
|
1538
|
+
/**
|
|
1539
|
+
* Options for controlling the behavior of Keyterms Prompting
|
|
1540
|
+
*/
|
|
1541
|
+
export type KeytermsPromptOptions = {
|
|
1542
|
+
/**
|
|
1543
|
+
* Strength of keyterm matching to be applied, either 'standard' or 'high'.
|
|
1544
|
+
*/
|
|
1545
|
+
keyterms_match_strength?: "high" | "standard" | null;
|
|
1546
|
+
};
|
|
1538
1547
|
/**
|
|
1539
1548
|
* The speech model to use for the transcription.
|
|
1540
1549
|
*/
|
|
@@ -2999,6 +3008,10 @@ export type TranscriptOptionalParams = {
|
|
|
2999
3008
|
* The list of key terms used to generate the transcript with the Slam-1 speech model. Can't be used together with `prompt`.
|
|
3000
3009
|
*/
|
|
3001
3010
|
keyterms_prompt?: string[];
|
|
3011
|
+
/**
|
|
3012
|
+
* Advanced options for controlling the behavior of keyterms_prompt
|
|
3013
|
+
*/
|
|
3014
|
+
keyterms_prompt_options?: KeytermsPromptOptions;
|
|
3002
3015
|
/**
|
|
3003
3016
|
* The language of your audio file. Possible values are found in {@link https://www.assemblyai.com/docs/concepts/supported-languages | Supported Languages }.
|
|
3004
3017
|
* The default value is 'en_us'.
|
|
@@ -6,13 +6,18 @@ export type StreamingTranscriberParams = {
|
|
|
6
6
|
sampleRate: number;
|
|
7
7
|
encoding?: AudioEncoding;
|
|
8
8
|
endOfTurnConfidenceThreshold?: number;
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use `minTurnSilence` instead. This parameter will be removed in a future release.
|
|
11
|
+
*/
|
|
9
12
|
minEndOfTurnSilenceWhenConfident?: number;
|
|
13
|
+
minTurnSilence?: number;
|
|
10
14
|
maxTurnSilence?: number;
|
|
11
15
|
vadThreshold?: number;
|
|
12
16
|
formatTurns?: boolean;
|
|
13
17
|
filterProfanity?: boolean;
|
|
14
18
|
keyterms?: string[];
|
|
15
19
|
keytermsPrompt?: string[];
|
|
20
|
+
prompt?: string;
|
|
16
21
|
speechModel?: StreamingSpeechModel;
|
|
17
22
|
languageDetection?: boolean;
|
|
18
23
|
inactivityTimeout?: number;
|
|
@@ -24,7 +29,7 @@ export type StreamingListeners = {
|
|
|
24
29
|
turn?: (event: TurnEvent) => void;
|
|
25
30
|
error?: (error: Error) => void;
|
|
26
31
|
};
|
|
27
|
-
export type StreamingSpeechModel = "universal-streaming-english" | "universal-streaming-multilingual";
|
|
32
|
+
export type StreamingSpeechModel = "universal-streaming-english" | "universal-streaming-multilingual" | "u3-rt-pro" | "u3-pro";
|
|
28
33
|
export type StreamingTokenParams = {
|
|
29
34
|
expires_in_seconds: number;
|
|
30
35
|
max_session_duration_seconds?: number;
|
|
@@ -67,10 +72,17 @@ export type StreamingTerminateSession = {
|
|
|
67
72
|
export type StreamingUpdateConfiguration = {
|
|
68
73
|
type: "UpdateConfiguration";
|
|
69
74
|
end_of_turn_confidence_threshold?: number;
|
|
75
|
+
/**
|
|
76
|
+
* @deprecated Use `min_turn_silence` instead. This parameter will be removed in a future release.
|
|
77
|
+
*/
|
|
70
78
|
min_end_of_turn_silence_when_confident?: number;
|
|
79
|
+
min_turn_silence?: number;
|
|
71
80
|
max_turn_silence?: number;
|
|
72
81
|
vad_threshold?: number;
|
|
73
82
|
format_turns?: boolean;
|
|
83
|
+
keyterms_prompt?: string[];
|
|
84
|
+
prompt?: string;
|
|
85
|
+
filter_profanity?: boolean;
|
|
74
86
|
};
|
|
75
87
|
export type StreamingForceEndpoint = {
|
|
76
88
|
type: "ForceEndpoint";
|
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.24.0" },
|
|
19
19
|
};
|
|
20
20
|
if (typeof process !== "undefined") {
|
|
21
21
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -804,7 +804,11 @@ class StreamingTranscriber {
|
|
|
804
804
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
805
805
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
806
806
|
}
|
|
807
|
-
if (this.params.
|
|
807
|
+
if (this.params.minTurnSilence) {
|
|
808
|
+
searchParams.set("min_turn_silence", this.params.minTurnSilence.toString());
|
|
809
|
+
}
|
|
810
|
+
else if (this.params.minEndOfTurnSilenceWhenConfident) {
|
|
811
|
+
console.warn("[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.");
|
|
808
812
|
searchParams.set("min_end_of_turn_silence_when_confident", this.params.minEndOfTurnSilenceWhenConfident.toString());
|
|
809
813
|
}
|
|
810
814
|
if (this.params.maxTurnSilence) {
|
|
@@ -826,10 +830,16 @@ class StreamingTranscriber {
|
|
|
826
830
|
console.warn("[Deprecation Warning] `keyterms` is deprecated and will be removed in a future release. Please use `keytermsPrompt` instead.");
|
|
827
831
|
searchParams.set("keyterms_prompt", JSON.stringify(this.params.keyterms));
|
|
828
832
|
}
|
|
833
|
+
if (this.params.prompt) {
|
|
834
|
+
searchParams.set("prompt", this.params.prompt);
|
|
835
|
+
}
|
|
829
836
|
if (this.params.filterProfanity) {
|
|
830
837
|
searchParams.set("filter_profanity", this.params.filterProfanity.toString());
|
|
831
838
|
}
|
|
832
839
|
if (this.params.speechModel) {
|
|
840
|
+
if (this.params.speechModel === "u3-pro") {
|
|
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
|
+
}
|
|
833
843
|
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
834
844
|
}
|
|
835
845
|
if (this.params.languageDetection !== undefined) {
|
|
@@ -909,6 +919,26 @@ class StreamingTranscriber {
|
|
|
909
919
|
sendAudio(audio) {
|
|
910
920
|
this.send(audio);
|
|
911
921
|
}
|
|
922
|
+
/**
|
|
923
|
+
* Update the streaming configuration mid-stream.
|
|
924
|
+
* @param config - The configuration parameters to update
|
|
925
|
+
*/
|
|
926
|
+
updateConfiguration(config) {
|
|
927
|
+
const message = {
|
|
928
|
+
type: "UpdateConfiguration",
|
|
929
|
+
...config,
|
|
930
|
+
};
|
|
931
|
+
this.send(JSON.stringify(message));
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* Force the current turn to end immediately.
|
|
935
|
+
*/
|
|
936
|
+
forceEndpoint() {
|
|
937
|
+
const message = {
|
|
938
|
+
type: "ForceEndpoint",
|
|
939
|
+
};
|
|
940
|
+
this.send(JSON.stringify(message));
|
|
941
|
+
}
|
|
912
942
|
send(data) {
|
|
913
943
|
if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
|
|
914
944
|
throw new Error("Socket is not open for communication");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblyai",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.24.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"
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
BeginEvent,
|
|
14
14
|
StreamingEventMessage,
|
|
15
15
|
TurnEvent,
|
|
16
|
+
StreamingUpdateConfiguration,
|
|
17
|
+
StreamingForceEndpoint,
|
|
16
18
|
} from "../..";
|
|
17
19
|
import { StreamingError, StreamingErrorMessages } from "../../utils/errors";
|
|
18
20
|
import { StreamingErrorTypeCodes } from "../../utils/errors/streaming";
|
|
@@ -83,7 +85,15 @@ export class StreamingTranscriber {
|
|
|
83
85
|
);
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
if (this.params.
|
|
88
|
+
if (this.params.minTurnSilence) {
|
|
89
|
+
searchParams.set(
|
|
90
|
+
"min_turn_silence",
|
|
91
|
+
this.params.minTurnSilence.toString(),
|
|
92
|
+
);
|
|
93
|
+
} else if (this.params.minEndOfTurnSilenceWhenConfident) {
|
|
94
|
+
console.warn(
|
|
95
|
+
"[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.",
|
|
96
|
+
);
|
|
87
97
|
searchParams.set(
|
|
88
98
|
"min_end_of_turn_silence_when_confident",
|
|
89
99
|
this.params.minEndOfTurnSilenceWhenConfident.toString(),
|
|
@@ -121,6 +131,10 @@ export class StreamingTranscriber {
|
|
|
121
131
|
searchParams.set("keyterms_prompt", JSON.stringify(this.params.keyterms));
|
|
122
132
|
}
|
|
123
133
|
|
|
134
|
+
if (this.params.prompt) {
|
|
135
|
+
searchParams.set("prompt", this.params.prompt);
|
|
136
|
+
}
|
|
137
|
+
|
|
124
138
|
if (this.params.filterProfanity) {
|
|
125
139
|
searchParams.set(
|
|
126
140
|
"filter_profanity",
|
|
@@ -129,6 +143,11 @@ export class StreamingTranscriber {
|
|
|
129
143
|
}
|
|
130
144
|
|
|
131
145
|
if (this.params.speechModel) {
|
|
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
|
+
);
|
|
150
|
+
}
|
|
132
151
|
searchParams.set("speech_model", this.params.speechModel.toString());
|
|
133
152
|
}
|
|
134
153
|
|
|
@@ -240,6 +259,28 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
|
|
|
240
259
|
this.send(audio);
|
|
241
260
|
}
|
|
242
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Update the streaming configuration mid-stream.
|
|
264
|
+
* @param config - The configuration parameters to update
|
|
265
|
+
*/
|
|
266
|
+
updateConfiguration(config: Omit<StreamingUpdateConfiguration, "type">) {
|
|
267
|
+
const message: StreamingUpdateConfiguration = {
|
|
268
|
+
type: "UpdateConfiguration",
|
|
269
|
+
...config,
|
|
270
|
+
};
|
|
271
|
+
this.send(JSON.stringify(message));
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Force the current turn to end immediately.
|
|
276
|
+
*/
|
|
277
|
+
forceEndpoint() {
|
|
278
|
+
const message: StreamingForceEndpoint = {
|
|
279
|
+
type: "ForceEndpoint",
|
|
280
|
+
};
|
|
281
|
+
this.send(JSON.stringify(message));
|
|
282
|
+
}
|
|
283
|
+
|
|
243
284
|
private send(data: BufferLike) {
|
|
244
285
|
if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
|
|
245
286
|
throw new Error("Socket is not open for communication");
|
|
@@ -1710,6 +1710,16 @@ export type LanguageDetectionOptions = {
|
|
|
1710
1710
|
swiss_german?: boolean | null;
|
|
1711
1711
|
};
|
|
1712
1712
|
|
|
1713
|
+
/**
|
|
1714
|
+
* Options for controlling the behavior of Keyterms Prompting
|
|
1715
|
+
*/
|
|
1716
|
+
export type KeytermsPromptOptions = {
|
|
1717
|
+
/**
|
|
1718
|
+
* Strength of keyterm matching to be applied, either 'standard' or 'high'.
|
|
1719
|
+
*/
|
|
1720
|
+
keyterms_match_strength?: "high" | "standard" | null;
|
|
1721
|
+
};
|
|
1722
|
+
|
|
1713
1723
|
/**
|
|
1714
1724
|
* The speech model to use for the transcription.
|
|
1715
1725
|
*/
|
|
@@ -3298,6 +3308,10 @@ export type TranscriptOptionalParams = {
|
|
|
3298
3308
|
* The list of key terms used to generate the transcript with the Slam-1 speech model. Can't be used together with `prompt`.
|
|
3299
3309
|
*/
|
|
3300
3310
|
keyterms_prompt?: string[];
|
|
3311
|
+
/**
|
|
3312
|
+
* Advanced options for controlling the behavior of keyterms_prompt
|
|
3313
|
+
*/
|
|
3314
|
+
keyterms_prompt_options?: KeytermsPromptOptions;
|
|
3301
3315
|
/**
|
|
3302
3316
|
* The language of your audio file. Possible values are found in {@link https://www.assemblyai.com/docs/concepts/supported-languages | Supported Languages }.
|
|
3303
3317
|
* The default value is 'en_us'.
|
|
@@ -7,13 +7,18 @@ export type StreamingTranscriberParams = {
|
|
|
7
7
|
sampleRate: number;
|
|
8
8
|
encoding?: AudioEncoding;
|
|
9
9
|
endOfTurnConfidenceThreshold?: number;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `minTurnSilence` instead. This parameter will be removed in a future release.
|
|
12
|
+
*/
|
|
10
13
|
minEndOfTurnSilenceWhenConfident?: number;
|
|
14
|
+
minTurnSilence?: number;
|
|
11
15
|
maxTurnSilence?: number;
|
|
12
16
|
vadThreshold?: number;
|
|
13
17
|
formatTurns?: boolean;
|
|
14
18
|
filterProfanity?: boolean;
|
|
15
19
|
keyterms?: string[];
|
|
16
20
|
keytermsPrompt?: string[];
|
|
21
|
+
prompt?: string;
|
|
17
22
|
speechModel?: StreamingSpeechModel;
|
|
18
23
|
languageDetection?: boolean;
|
|
19
24
|
inactivityTimeout?: number;
|
|
@@ -30,7 +35,9 @@ export type StreamingListeners = {
|
|
|
30
35
|
|
|
31
36
|
export type StreamingSpeechModel =
|
|
32
37
|
| "universal-streaming-english"
|
|
33
|
-
| "universal-streaming-multilingual"
|
|
38
|
+
| "universal-streaming-multilingual"
|
|
39
|
+
| "u3-rt-pro"
|
|
40
|
+
| "u3-pro";
|
|
34
41
|
|
|
35
42
|
export type StreamingTokenParams = {
|
|
36
43
|
expires_in_seconds: number;
|
|
@@ -82,10 +89,17 @@ export type StreamingTerminateSession = {
|
|
|
82
89
|
export type StreamingUpdateConfiguration = {
|
|
83
90
|
type: "UpdateConfiguration";
|
|
84
91
|
end_of_turn_confidence_threshold?: number;
|
|
92
|
+
/**
|
|
93
|
+
* @deprecated Use `min_turn_silence` instead. This parameter will be removed in a future release.
|
|
94
|
+
*/
|
|
85
95
|
min_end_of_turn_silence_when_confident?: number;
|
|
96
|
+
min_turn_silence?: number;
|
|
86
97
|
max_turn_silence?: number;
|
|
87
98
|
vad_threshold?: number;
|
|
88
99
|
format_turns?: boolean;
|
|
100
|
+
keyterms_prompt?: string[];
|
|
101
|
+
prompt?: string;
|
|
102
|
+
filter_profanity?: boolean;
|
|
89
103
|
};
|
|
90
104
|
|
|
91
105
|
export type StreamingForceEndpoint = {
|