assemblyai
Advanced tools
Comparing version 4.3.4 to 4.4.0
# Changelog | ||
## [4.4.0] - 2024-04-12 | ||
### Added | ||
- Add `disablePartialTranscripts` parameter to `CreateRealtimeTranscriberParams` | ||
- Add `enableExtraSessionInformation` parameter to `CreateRealtimeTranscriberParams` | ||
- Add `session_information` event to `RealtimeTranscriber.on()` | ||
### Updated | ||
- ⚠️ Deprecate `conformer-2` literal for `TranscriptParams.speech_model` property | ||
### Fixed | ||
- Add missing `status` property to `AutoHighlightsResult` | ||
## [4.3.4] - 2024-04-02 | ||
@@ -4,0 +20,0 @@ |
@@ -209,2 +209,4 @@ (function (global, factory) { | ||
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold; | ||
this.enableExtraSessionInformation = params.enableExtraSessionInformation; | ||
this.disablePartialTranscripts = params.disablePartialTranscripts; | ||
if ("token" in params && params.token) | ||
@@ -234,2 +236,8 @@ this.token = params.token; | ||
} | ||
if (this.enableExtraSessionInformation) { | ||
searchParams.set("enable_extra_session_information", this.enableExtraSessionInformation.toString()); | ||
} | ||
if (this.disablePartialTranscripts) { | ||
searchParams.set("disable_partial_transcripts", this.disablePartialTranscripts.toString()); | ||
} | ||
url.search = searchParams.toString(); | ||
@@ -281,3 +289,3 @@ return url; | ||
this.socket.onmessage = ({ data }) => { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; | ||
const message = JSON.parse(data.toString()); | ||
@@ -312,4 +320,8 @@ if ("error" in message) { | ||
} | ||
case "SessionInformation": { | ||
(_p = (_o = this.listeners).session_information) === null || _p === void 0 ? void 0 : _p.call(_o, message); | ||
break; | ||
} | ||
case "SessionTerminated": { | ||
(_o = this.sessionTerminatedResolve) === null || _o === void 0 ? void 0 : _o.call(this); | ||
(_q = this.sessionTerminatedResolve) === null || _q === void 0 ? void 0 : _q.call(this); | ||
break; | ||
@@ -440,2 +452,3 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
deprecateConformer2(params); | ||
const transcript = yield this.submit(params); | ||
@@ -452,2 +465,3 @@ return yield this.waitUntilReady(transcript.id, options); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
deprecateConformer2(params); | ||
let audioUrl; | ||
@@ -494,2 +508,3 @@ let transcriptParams = undefined; | ||
var _a; | ||
deprecateConformer2(params); | ||
const path = getPath(params.audio_url); | ||
@@ -638,2 +653,9 @@ if (path !== null) { | ||
} | ||
function deprecateConformer2(params) { | ||
if (!params) | ||
return; | ||
if (params.speech_model === "conformer-2") { | ||
console.warn("The speech_model conformer-2 option is deprecated and will stop working in the near future. Use best or nano instead."); | ||
} | ||
} | ||
@@ -640,0 +662,0 @@ const readFile = function ( |
@@ -1,1 +0,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,o){function r(e){try{c(i.next(e))}catch(e){o(e)}}function a(e){try{c(i.throw(e))}catch(e){o(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(r,a)}c((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class s{constructor(e){this.params=e}fetch(e,s){return t(this,void 0,void 0,(function*(){var t;(s=null!=s?s:{}).headers=null!==(t=s.headers)&&void 0!==t?t:{},s.headers=Object.assign({Authorization:this.params.apiKey,"Content-Type":"application/json"},s.headers),e.startsWith("http")||(e=this.params.baseUrl+e);const i=yield fetch(e,s);if(i.status>=400){let e;const t=yield i.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: ${i.status} ${i.statusText}`)}return i}))}fetchJson(e,s){return t(this,void 0,void 0,(function*(){return(yield this.fetch(e,s)).json()}))}}class i extends s{summary(e){return this.fetchJson("/lemur/v3/generate/summary",{method:"POST",body:JSON.stringify(e)})}questionAnswer(e){return this.fetchJson("/lemur/v3/generate/question-answer",{method:"POST",body:JSON.stringify(e)})}actionItems(e){return this.fetchJson("/lemur/v3/generate/action-items",{method:"POST",body:JSON.stringify(e)})}task(e){return this.fetchJson("/lemur/v3/generate/task",{method:"POST",body:JSON.stringify(e)})}purgeRequestData(e){return this.fetchJson(`/lemur/v3/${e}`,{method:"DELETE"})}}const{WritableStream:n}="undefined"!=typeof window?window:"undefined"!=typeof global?global:globalThis;var o=null;"undefined"!=typeof WebSocket?o=WebSocket:"undefined"!=typeof MozWebSocket?o=MozWebSocket:"undefined"!=typeof global?o=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window?o=window.WebSocket||window.MozWebSocket:"undefined"!=typeof self&&(o=self.WebSocket||self.MozWebSocket);var r,a=o;!function(e){e[e.BadSampleRate=4e3]="BadSampleRate",e[e.AuthFailed=4001]="AuthFailed",e[e.InsufficientFundsOrFreeAccount=4002]="InsufficientFundsOrFreeAccount",e[e.NonexistentSessionId=4004]="NonexistentSessionId",e[e.SessionExpired=4008]="SessionExpired",e[e.ClosedSession=4010]="ClosedSession",e[e.RateLimited=4029]="RateLimited",e[e.UniqueSessionViolation=4030]="UniqueSessionViolation",e[e.SessionTimeout=4031]="SessionTimeout",e[e.AudioTooShort=4032]="AudioTooShort",e[e.AudioTooLong=4033]="AudioTooLong",e[e.BadJson=4100]="BadJson",e[e.BadSchema=4101]="BadSchema",e[e.TooManyStreams=4102]="TooManyStreams",e[e.Reconnected=4103]="Reconnected",e[e.ReconnectAttemptsExhausted=1013]="ReconnectAttemptsExhausted"}(r||(r={}));const c={[r.BadSampleRate]:"Sample rate must be a positive integer",[r.AuthFailed]:"Not Authorized",[r.InsufficientFundsOrFreeAccount]:"Insufficient funds or you are using a free account. This feature is paid-only and requires you to add a credit card. Please visit https://assemblyai.com/dashboard/ to add a credit card to your account.",[r.NonexistentSessionId]:"Session ID does not exist",[r.SessionExpired]:"Session has expired",[r.ClosedSession]:"Session is closed",[r.RateLimited]:"Rate limited",[r.UniqueSessionViolation]:"Unique session violation",[r.SessionTimeout]:"Session Timeout",[r.AudioTooShort]:"Audio too short",[r.AudioTooLong]:"Audio too long",[r.BadJson]:"Bad JSON",[r.BadSchema]:"Bad schema",[r.TooManyStreams]:"Too many streams",[r.Reconnected]:"Reconnected",[r.ReconnectAttemptsExhausted]:"Reconnect attempts exhausted"};class l extends Error{}const d='{"terminate_session":true}';class h{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,"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),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=new a(t.toString()):this.socket=new a(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 r&&(t=c[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,o,r,a,c,d,h,u,f,p,m;const y=JSON.parse(t.toString());if("error"in y)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new l(y.error));else switch(y.message_type){case"SessionBegins":{const t={sessionId:y.session_id,expiresAt:new Date(y.expires_at)};e(t),null===(o=(n=this.listeners).open)||void 0===o||o.call(n,t);break}case"PartialTranscript":y.created=new Date(y.created),null===(a=(r=this.listeners).transcript)||void 0===a||a.call(r,y),null===(d=(c=this.listeners)["transcript.partial"])||void 0===d||d.call(c,y);break;case"FinalTranscript":y.created=new Date(y.created),null===(u=(h=this.listeners).transcript)||void 0===u||u.call(h,y),null===(p=(f=this.listeners)["transcript.final"])||void 0===p||p.call(f,y);break;case"SessionTerminated":null===(m=this.sessionTerminatedResolve)||void 0===m||m.call(this)}}}))}sendAudio(e){this.send(e)}stream(){return new n({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!==a.OPEN)throw new Error("Socket is not open for communication");this.socket.send(e)}close(){return t(this,arguments,void 0,(function*(e=!0){if(this.socket){if(this.socket.readyState===a.OPEN)if(e){const e=new Promise((e=>{this.sessionTerminatedResolve=e}));this.socket.send(d),yield e}else this.socket.send(d);"removeAllListeners"in this.socket&&this.socket.removeAllListeners(),this.socket.close()}this.listeners={},this.socket=void 0}))}}class u extends s{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 h(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 f(e){return e.startsWith("http")||e.startsWith("https")?null:e.startsWith("file://")?e.substring(7):e.startsWith("file:")?e.substring(5):e}class p extends s{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=f(i);t=null!==e?yield this.files.upload(e):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=f(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,o=null!==(i=null==s?void 0:s.pollingTimeout)&&void 0!==i?i:-1,r=Date.now();for(;;){const t=yield this.get(e);if("completed"===t.status||"error"===t.status)return t;if(o>0&&Date.now()-r>o)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.fetchJson(`/v2/transcript/${e}/redacted-audio`)}}class m extends s{upload(e){return t(this,void 0,void 0,(function*(){let s;s="string"==typeof 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}))}}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 m(e),this.transcripts=new p(e,this.files),this.lemur=new i(e),this.realtime=new u(e)}},e.FileService=m,e.LemurService=i,e.RealtimeService=class extends h{},e.RealtimeServiceFactory=class extends u{},e.RealtimeTranscriber=h,e.RealtimeTranscriberFactory=u,e.TranscriptService=p})); | ||
!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,o){function r(e){try{c(i.next(e))}catch(e){o(e)}}function a(e){try{c(i.throw(e))}catch(e){o(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(r,a)}c((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class s{constructor(e){this.params=e}fetch(e,s){return t(this,void 0,void 0,(function*(){var t;(s=null!=s?s:{}).headers=null!==(t=s.headers)&&void 0!==t?t:{},s.headers=Object.assign({Authorization:this.params.apiKey,"Content-Type":"application/json"},s.headers),e.startsWith("http")||(e=this.params.baseUrl+e);const i=yield fetch(e,s);if(i.status>=400){let e;const t=yield i.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: ${i.status} ${i.statusText}`)}return i}))}fetchJson(e,s){return t(this,void 0,void 0,(function*(){return(yield this.fetch(e,s)).json()}))}}class i extends s{summary(e){return this.fetchJson("/lemur/v3/generate/summary",{method:"POST",body:JSON.stringify(e)})}questionAnswer(e){return this.fetchJson("/lemur/v3/generate/question-answer",{method:"POST",body:JSON.stringify(e)})}actionItems(e){return this.fetchJson("/lemur/v3/generate/action-items",{method:"POST",body:JSON.stringify(e)})}task(e){return this.fetchJson("/lemur/v3/generate/task",{method:"POST",body:JSON.stringify(e)})}purgeRequestData(e){return this.fetchJson(`/lemur/v3/${e}`,{method:"DELETE"})}}const{WritableStream:n}="undefined"!=typeof window?window:"undefined"!=typeof global?global:globalThis;var o=null;"undefined"!=typeof WebSocket?o=WebSocket:"undefined"!=typeof MozWebSocket?o=MozWebSocket:"undefined"!=typeof global?o=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window?o=window.WebSocket||window.MozWebSocket:"undefined"!=typeof self&&(o=self.WebSocket||self.MozWebSocket);var r,a=o;!function(e){e[e.BadSampleRate=4e3]="BadSampleRate",e[e.AuthFailed=4001]="AuthFailed",e[e.InsufficientFundsOrFreeAccount=4002]="InsufficientFundsOrFreeAccount",e[e.NonexistentSessionId=4004]="NonexistentSessionId",e[e.SessionExpired=4008]="SessionExpired",e[e.ClosedSession=4010]="ClosedSession",e[e.RateLimited=4029]="RateLimited",e[e.UniqueSessionViolation=4030]="UniqueSessionViolation",e[e.SessionTimeout=4031]="SessionTimeout",e[e.AudioTooShort=4032]="AudioTooShort",e[e.AudioTooLong=4033]="AudioTooLong",e[e.BadJson=4100]="BadJson",e[e.BadSchema=4101]="BadSchema",e[e.TooManyStreams=4102]="TooManyStreams",e[e.Reconnected=4103]="Reconnected",e[e.ReconnectAttemptsExhausted=1013]="ReconnectAttemptsExhausted"}(r||(r={}));const c={[r.BadSampleRate]:"Sample rate must be a positive integer",[r.AuthFailed]:"Not Authorized",[r.InsufficientFundsOrFreeAccount]:"Insufficient funds or you are using a free account. This feature is paid-only and requires you to add a credit card. Please visit https://assemblyai.com/dashboard/ to add a credit card to your account.",[r.NonexistentSessionId]:"Session ID does not exist",[r.SessionExpired]:"Session has expired",[r.ClosedSession]:"Session is closed",[r.RateLimited]:"Rate limited",[r.UniqueSessionViolation]:"Unique session violation",[r.SessionTimeout]:"Session Timeout",[r.AudioTooShort]:"Audio too short",[r.AudioTooLong]:"Audio too long",[r.BadJson]:"Bad JSON",[r.BadSchema]:"Bad schema",[r.TooManyStreams]:"Too many streams",[r.Reconnected]:"Reconnected",[r.ReconnectAttemptsExhausted]:"Reconnect attempts exhausted"};class l extends Error{}const d='{"terminate_session":true}';class h{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.enableExtraSessionInformation=e.enableExtraSessionInformation,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),this.enableExtraSessionInformation&&t.set("enable_extra_session_information",this.enableExtraSessionInformation.toString()),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=new a(t.toString()):this.socket=new a(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 r&&(t=c[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,o,r,a,c,d,h,u,f,p,m,y,S;const v=JSON.parse(t.toString());if("error"in v)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new l(v.error));else switch(v.message_type){case"SessionBegins":{const t={sessionId:v.session_id,expiresAt:new Date(v.expires_at)};e(t),null===(o=(n=this.listeners).open)||void 0===o||o.call(n,t);break}case"PartialTranscript":v.created=new Date(v.created),null===(a=(r=this.listeners).transcript)||void 0===a||a.call(r,v),null===(d=(c=this.listeners)["transcript.partial"])||void 0===d||d.call(c,v);break;case"FinalTranscript":v.created=new Date(v.created),null===(u=(h=this.listeners).transcript)||void 0===u||u.call(h,v),null===(p=(f=this.listeners)["transcript.final"])||void 0===p||p.call(f,v);break;case"SessionInformation":null===(y=(m=this.listeners).session_information)||void 0===y||y.call(m,v);break;case"SessionTerminated":null===(S=this.sessionTerminatedResolve)||void 0===S||S.call(this)}}}))}sendAudio(e){this.send(e)}stream(){return new n({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!==a.OPEN)throw new Error("Socket is not open for communication");this.socket.send(e)}close(){return t(this,arguments,void 0,(function*(e=!0){if(this.socket){if(this.socket.readyState===a.OPEN)if(e){const e=new Promise((e=>{this.sessionTerminatedResolve=e}));this.socket.send(d),yield e}else this.socket.send(d);"removeAllListeners"in this.socket&&this.socket.removeAllListeners(),this.socket.close()}this.listeners={},this.socket=void 0}))}}class u extends s{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 h(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 f(e){return e.startsWith("http")||e.startsWith("https")?null:e.startsWith("file://")?e.substring(7):e.startsWith("file:")?e.substring(5):e}class p extends s{constructor(e,t){super(e),this.files=t}transcribe(e,s){return t(this,void 0,void 0,(function*(){m(e);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(m(e),"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=f(i);t=null!==e?yield this.files.upload(e):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;m(e);const i=f(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,o=null!==(i=null==s?void 0:s.pollingTimeout)&&void 0!==i?i:-1,r=Date.now();for(;;){const t=yield this.get(e);if("completed"===t.status||"error"===t.status)return t;if(o>0&&Date.now()-r>o)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.fetchJson(`/v2/transcript/${e}/redacted-audio`)}}function m(e){e&&"conformer-2"===e.speech_model&&console.warn("The speech_model conformer-2 option is deprecated and will stop working in the near future. Use best or nano instead.")}class y extends s{upload(e){return t(this,void 0,void 0,(function*(){let s;s="string"==typeof 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}))}}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 y(e),this.transcripts=new p(e,this.files),this.lemur=new i(e),this.realtime=new u(e)}},e.FileService=y,e.LemurService=i,e.RealtimeService=class extends h{},e.RealtimeServiceFactory=class extends u{},e.RealtimeTranscriber=h,e.RealtimeTranscriberFactory=u,e.TranscriptService=p})); |
@@ -1,2 +0,2 @@ | ||
import { RealtimeTranscriberParams, RealtimeTranscript, PartialTranscript, FinalTranscript, SessionBeginsEventData, AudioData } from "../.."; | ||
import { RealtimeTranscriberParams, RealtimeTranscript, PartialTranscript, FinalTranscript, SessionBeginsEventData, AudioData, SessionInformation } from "../.."; | ||
export declare class RealtimeTranscriber { | ||
@@ -10,2 +10,4 @@ private realtimeUrl; | ||
private endUtteranceSilenceThreshold?; | ||
private enableExtraSessionInformation?; | ||
private disablePartialTranscripts?; | ||
private socket?; | ||
@@ -20,2 +22,3 @@ private listeners; | ||
on(event: "transcript.final", listener: (transcript: FinalTranscript) => void): void; | ||
on(event: "session_information", listener: (info: SessionInformation) => void): void; | ||
on(event: "error", listener: (error: Error) => void): void; | ||
@@ -22,0 +25,0 @@ on(event: "close", listener: (code: number, reason: string) => void): void; |
@@ -19,2 +19,5 @@ /** | ||
}; | ||
/** | ||
* Transcript text at the end of an utterance with punctuation and casing. | ||
*/ | ||
export type FinalTranscript = RealtimeBaseTranscript & { | ||
@@ -43,3 +46,6 @@ /** | ||
}; | ||
export type MessageType = "SessionBegins" | "PartialTranscript" | "FinalTranscript" | "SessionTerminated"; | ||
export type MessageType = "SessionBegins" | "PartialTranscript" | "FinalTranscript" | "SessionInformation" | "SessionTerminated"; | ||
/** | ||
* As you send audio data to the API, the API immediately starts responding with Partial Transcript results. | ||
*/ | ||
export type PartialTranscript = RealtimeBaseTranscript & { | ||
@@ -84,8 +90,14 @@ /** | ||
}; | ||
/** | ||
* Error message | ||
*/ | ||
export type RealtimeError = { | ||
error: string; | ||
}; | ||
export type RealtimeMessage = SessionBegins | PartialTranscript | FinalTranscript | SessionTerminated | RealtimeError; | ||
export type RealtimeMessage = SessionBegins | PartialTranscript | FinalTranscript | SessionInformation | SessionTerminated | RealtimeError; | ||
export type RealtimeTranscript = PartialTranscript | FinalTranscript; | ||
export type RealtimeTranscriptType = "PartialTranscript" | "FinalTranscript"; | ||
/** | ||
* Session start | ||
*/ | ||
export type SessionBegins = RealtimeBaseMessage & { | ||
@@ -105,2 +117,20 @@ /** | ||
}; | ||
/** | ||
* Information about the session | ||
* Information about the session that is concluding. | ||
* This message is sent at the end of the session, before the SessionTerminated message. | ||
*/ | ||
export type SessionInformation = RealtimeBaseMessage & { | ||
/** | ||
* The total duration of the audio in seconds | ||
*/ | ||
audio_duration_seconds: number; | ||
/** | ||
* Describes the type of the message | ||
*/ | ||
message_type: "SessionInformation"; | ||
}; | ||
/** | ||
* Session terminated | ||
*/ | ||
export type SessionTerminated = RealtimeBaseMessage & { | ||
@@ -112,2 +142,5 @@ /** | ||
}; | ||
/** | ||
* Terminate session | ||
*/ | ||
export type TerminateSession = { | ||
@@ -114,0 +147,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import { AudioEncoding, FinalTranscript, PartialTranscript, RealtimeTranscript, RealtimeTranscriptType } from "../asyncapi.generated"; | ||
import { AudioEncoding, FinalTranscript, PartialTranscript, RealtimeTranscript, RealtimeTranscriptType, SessionInformation } from "../asyncapi.generated"; | ||
type CreateRealtimeTranscriberParams = { | ||
@@ -23,2 +23,14 @@ /** | ||
endUtteranceSilenceThreshold?: number; | ||
/** | ||
* Disable partial transcripts. | ||
* Set to `true` to not receive partial transcripts. Defaults to `false`. | ||
* @defaultValue false | ||
*/ | ||
disablePartialTranscripts?: boolean; | ||
/** | ||
* Enable extra session information. | ||
* Set to `true` to receive the `session_information` message before the session ends. Defaults to `false`. | ||
* @defaultValue false | ||
*/ | ||
enableExtraSessionInformation?: boolean; | ||
} & ({ | ||
@@ -61,2 +73,14 @@ /** | ||
endUtteranceSilenceThreshold?: number; | ||
/** | ||
* Disable partial transcripts. | ||
* Set to `true` to not receive partial transcripts. Defaults to `false`. | ||
* @defaultValue false | ||
*/ | ||
disablePartialTranscripts?: boolean; | ||
/** | ||
* Enable extra session information. | ||
* Set to `true` to receive the `session_information` message before the session ends. Defaults to `false`. | ||
* @defaultValue false | ||
*/ | ||
enableExtraSessionInformation?: boolean; | ||
} & ({ | ||
@@ -78,3 +102,3 @@ /** | ||
type RealtimeServiceParams = RealtimeTranscriberParams; | ||
type RealtimeEvents = "open" | "close" | "transcript" | "transcript.partial" | "transcript.final" | "error"; | ||
type RealtimeEvents = "open" | "close" | "transcript" | "transcript.partial" | "transcript.final" | "session_information" | "error"; | ||
type SessionBeginsEventData = { | ||
@@ -90,2 +114,3 @@ sessionId: string; | ||
"transcript.final"?: (transcript: FinalTranscript) => void; | ||
session_information?: (info: SessionInformation) => void; | ||
error?: (error: Error) => void; | ||
@@ -92,0 +117,0 @@ }; |
{ | ||
"name": "assemblyai", | ||
"version": "4.3.4", | ||
"version": "4.4.0", | ||
"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.", | ||
@@ -72,5 +72,8 @@ "engines": { | ||
"lint": "eslint -c .eslintrc.json '{src,tests}/**/*.{js,ts}' && publint && tsc --noEmit -p tsconfig.json", | ||
"test": "jest --config jest.config.js", | ||
"test": "pnpm run test:unit && pnpm run test:integration", | ||
"test:unit": "jest --config jest.unit.config.js", | ||
"test:integration": "jest --config jest.integration.config.js --testTimeout 360000", | ||
"format": "prettier '**/*' --write", | ||
"generate-types": "tsx ./scripts/generate-types.ts && pnpm format", | ||
"generate:types": "tsx ./scripts/generate-types.ts && prettier 'src/types/*.generated.ts' --write", | ||
"generate:reference": "typedoc", | ||
"copybara:dry-run": "./copybara.sh dry_run --init-history", | ||
@@ -129,3 +132,4 @@ "copybara:pr": "./copybara.sh sync_out --init-history" | ||
"typescript": "^5.4.2", | ||
"typedoc": "^0.25.12" | ||
"typedoc": "^0.25.12", | ||
"typedoc-plugin-extras": "^3.0.0" | ||
}, | ||
@@ -132,0 +136,0 @@ "dependencies": { |
@@ -22,2 +22,3 @@ <img src="https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/assemblyai.png?raw=true" width="500"/> | ||
Visit the [AssemblyAI documentation](https://www.assemblyai.com/docs) for step-by-step instructions and a lot more details about our AI models and API. | ||
Explore the [SDK API reference](https://assemblyai.github.io/assemblyai-node-sdk/) for more details on the SDK types, functions, and classes. | ||
@@ -24,0 +25,0 @@ ## Quickstart |
@@ -15,2 +15,3 @@ import { WritableStream } from "#streams"; | ||
AudioData, | ||
SessionInformation, | ||
} from "../.."; | ||
@@ -53,2 +54,5 @@ import { | ||
private endUtteranceSilenceThreshold?: number; | ||
private enableExtraSessionInformation?: boolean; | ||
private disablePartialTranscripts?: boolean; | ||
private socket?: WebSocket; | ||
@@ -64,2 +68,4 @@ private listeners: RealtimeListeners = {}; | ||
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold; | ||
this.enableExtraSessionInformation = params.enableExtraSessionInformation; | ||
this.disablePartialTranscripts = params.disablePartialTranscripts; | ||
if ("token" in params && params.token) this.token = params.token; | ||
@@ -91,2 +97,14 @@ if ("apiKey" in params && params.apiKey) this.apiKey = params.apiKey; | ||
} | ||
if (this.enableExtraSessionInformation) { | ||
searchParams.set( | ||
"enable_extra_session_information", | ||
this.enableExtraSessionInformation.toString(), | ||
); | ||
} | ||
if (this.disablePartialTranscripts) { | ||
searchParams.set( | ||
"disable_partial_transcripts", | ||
this.disablePartialTranscripts.toString(), | ||
); | ||
} | ||
url.search = searchParams.toString(); | ||
@@ -110,2 +128,6 @@ | ||
): void; | ||
on( | ||
event: "session_information", | ||
listener: (info: SessionInformation) => void, | ||
): void; | ||
on(event: "error", listener: (error: Error) => void): void; | ||
@@ -191,2 +213,6 @@ on(event: "close", listener: (code: number, reason: string) => void): void; | ||
} | ||
case "SessionInformation": { | ||
this.listeners.session_information?.(message); | ||
break; | ||
} | ||
case "SessionTerminated": { | ||
@@ -193,0 +219,0 @@ this.sessionTerminatedResolve?.(); |
@@ -18,2 +18,3 @@ import { BaseService } from "../base"; | ||
SubmitParams, | ||
SpeechModel, | ||
} from "../.."; | ||
@@ -41,2 +42,3 @@ import { FileService } from "../files"; | ||
): Promise<Transcript> { | ||
deprecateConformer2(params); | ||
const transcript = await this.submit(params); | ||
@@ -52,2 +54,3 @@ return await this.waitUntilReady(transcript.id, options); | ||
async submit(params: SubmitParams): Promise<Transcript> { | ||
deprecateConformer2(params); | ||
let audioUrl; | ||
@@ -93,2 +96,3 @@ let transcriptParams: TranscriptParams | undefined = undefined; | ||
): Promise<Transcript> { | ||
deprecateConformer2(params); | ||
const path = getPath(params.audio_url); | ||
@@ -253,1 +257,10 @@ if (path !== null) { | ||
} | ||
function deprecateConformer2(params: { speech_model?: SpeechModel | null }) { | ||
if (!params) return; | ||
if (params.speech_model === "conformer-2") { | ||
console.warn( | ||
"The speech_model conformer-2 option is deprecated and will stop working in the near future. Use best or nano instead.", | ||
); | ||
} | ||
} |
@@ -40,2 +40,5 @@ // this file is generated by typescript/scripts/generate-types.ts | ||
/** | ||
* Transcript text at the end of an utterance with punctuation and casing. | ||
*/ | ||
export type FinalTranscript = RealtimeBaseTranscript & { | ||
@@ -70,4 +73,8 @@ /** | ||
| "FinalTranscript" | ||
| "SessionInformation" | ||
| "SessionTerminated"; | ||
/** | ||
* As you send audio data to the API, the API immediately starts responding with Partial Transcript results. | ||
*/ | ||
export type PartialTranscript = RealtimeBaseTranscript & { | ||
@@ -115,2 +122,5 @@ /** | ||
/** | ||
* Error message | ||
*/ | ||
export type RealtimeError = { | ||
@@ -124,2 +134,3 @@ error: string; | ||
| FinalTranscript | ||
| SessionInformation | ||
| SessionTerminated | ||
@@ -132,2 +143,5 @@ | RealtimeError; | ||
/** | ||
* Session start | ||
*/ | ||
export type SessionBegins = RealtimeBaseMessage & { | ||
@@ -148,2 +162,21 @@ /** | ||
/** | ||
* Information about the session | ||
* Information about the session that is concluding. | ||
* This message is sent at the end of the session, before the SessionTerminated message. | ||
*/ | ||
export type SessionInformation = RealtimeBaseMessage & { | ||
/** | ||
* The total duration of the audio in seconds | ||
*/ | ||
audio_duration_seconds: number; | ||
/** | ||
* Describes the type of the message | ||
*/ | ||
message_type: "SessionInformation"; | ||
}; | ||
/** | ||
* Session terminated | ||
*/ | ||
export type SessionTerminated = RealtimeBaseMessage & { | ||
@@ -156,2 +189,5 @@ /** | ||
/** | ||
* Terminate session | ||
*/ | ||
export type TerminateSession = { | ||
@@ -158,0 +194,0 @@ /** |
@@ -7,2 +7,3 @@ import { | ||
RealtimeTranscriptType, | ||
SessionInformation, | ||
} from "../asyncapi.generated"; | ||
@@ -31,2 +32,14 @@ | ||
endUtteranceSilenceThreshold?: number; | ||
/** | ||
* Disable partial transcripts. | ||
* Set to `true` to not receive partial transcripts. Defaults to `false`. | ||
* @defaultValue false | ||
*/ | ||
disablePartialTranscripts?: boolean; | ||
/** | ||
* Enable extra session information. | ||
* Set to `true` to receive the `session_information` message before the session ends. Defaults to `false`. | ||
* @defaultValue false | ||
*/ | ||
enableExtraSessionInformation?: boolean; | ||
} & ( | ||
@@ -74,2 +87,14 @@ | { | ||
endUtteranceSilenceThreshold?: number; | ||
/** | ||
* Disable partial transcripts. | ||
* Set to `true` to not receive partial transcripts. Defaults to `false`. | ||
* @defaultValue false | ||
*/ | ||
disablePartialTranscripts?: boolean; | ||
/** | ||
* Enable extra session information. | ||
* Set to `true` to receive the `session_information` message before the session ends. Defaults to `false`. | ||
* @defaultValue false | ||
*/ | ||
enableExtraSessionInformation?: boolean; | ||
} & ( | ||
@@ -102,2 +127,3 @@ | { | ||
| "transcript.final" | ||
| "session_information" | ||
| "error"; | ||
@@ -116,2 +142,3 @@ | ||
"transcript.final"?: (transcript: FinalTranscript) => void; | ||
session_information?: (info: SessionInformation) => void; | ||
error?: (error: Error) => void; | ||
@@ -118,0 +145,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
484904
12973
347
29