assemblyai 4.4.0 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -2
- package/dist/assemblyai.umd.js +1 -4
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/bun.mjs +1 -4
- package/dist/deno.mjs +1 -4
- package/dist/index.cjs +1 -4
- package/dist/index.mjs +1 -4
- package/dist/node.cjs +1 -4
- package/dist/node.mjs +1 -4
- package/dist/services/realtime/service.d.ts +0 -1
- package/dist/types/realtime/index.d.ts +4 -2
- package/package.json +1 -1
- package/src/services/realtime/service.ts +3 -8
- package/src/types/realtime/index.ts +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.4.1] - 2024-04-16
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Deprecate `enableExtraSessionInformation` parameter in `CreateRealtimeTranscriberParams` type
|
|
8
|
+
|
|
3
9
|
## [4.4.0] - 2024-04-12
|
|
4
10
|
|
|
5
11
|
### Added
|
|
@@ -8,7 +14,7 @@
|
|
|
8
14
|
- Add `enableExtraSessionInformation` parameter to `CreateRealtimeTranscriberParams`
|
|
9
15
|
- Add `session_information` event to `RealtimeTranscriber.on()`
|
|
10
16
|
|
|
11
|
-
###
|
|
17
|
+
### Changed
|
|
12
18
|
|
|
13
19
|
- ⚠️ Deprecate `conformer-2` literal for `TranscriptParams.speech_model` property
|
|
14
20
|
|
|
@@ -23,7 +29,7 @@
|
|
|
23
29
|
- `SpeechModel.Best` enum
|
|
24
30
|
- `TranscriptListItem.error` property
|
|
25
31
|
|
|
26
|
-
###
|
|
32
|
+
### Changed
|
|
27
33
|
|
|
28
34
|
- Make `PageDetails.prev_url` nullable
|
|
29
35
|
- Rename Realtime to Streaming inside code documentation
|
package/dist/assemblyai.umd.js
CHANGED
|
@@ -206,7 +206,6 @@
|
|
|
206
206
|
this.wordBoost = params.wordBoost;
|
|
207
207
|
this.encoding = params.encoding;
|
|
208
208
|
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
209
|
-
this.enableExtraSessionInformation = params.enableExtraSessionInformation;
|
|
210
209
|
this.disablePartialTranscripts = params.disablePartialTranscripts;
|
|
211
210
|
if ("token" in params && params.token)
|
|
212
211
|
this.token = params.token;
|
|
@@ -232,9 +231,7 @@
|
|
|
232
231
|
if (this.encoding) {
|
|
233
232
|
searchParams.set("encoding", this.encoding);
|
|
234
233
|
}
|
|
235
|
-
|
|
236
|
-
searchParams.set("enable_extra_session_information", this.enableExtraSessionInformation.toString());
|
|
237
|
-
}
|
|
234
|
+
searchParams.set("enable_extra_session_information", "true");
|
|
238
235
|
if (this.disablePartialTranscripts) {
|
|
239
236
|
searchParams.set("disable_partial_transcripts", this.disablePartialTranscripts.toString());
|
|
240
237
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).assemblyai={})}(this,(function(e){"use strict";function t(e,t,s,i){return new(s||(s=Promise))((function(n,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
|
+
!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.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=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}));
|
package/dist/bun.mjs
CHANGED
|
@@ -140,7 +140,6 @@ class RealtimeTranscriber {
|
|
|
140
140
|
this.wordBoost = params.wordBoost;
|
|
141
141
|
this.encoding = params.encoding;
|
|
142
142
|
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
143
|
-
this.enableExtraSessionInformation = params.enableExtraSessionInformation;
|
|
144
143
|
this.disablePartialTranscripts = params.disablePartialTranscripts;
|
|
145
144
|
if ("token" in params && params.token)
|
|
146
145
|
this.token = params.token;
|
|
@@ -166,9 +165,7 @@ class RealtimeTranscriber {
|
|
|
166
165
|
if (this.encoding) {
|
|
167
166
|
searchParams.set("encoding", this.encoding);
|
|
168
167
|
}
|
|
169
|
-
|
|
170
|
-
searchParams.set("enable_extra_session_information", this.enableExtraSessionInformation.toString());
|
|
171
|
-
}
|
|
168
|
+
searchParams.set("enable_extra_session_information", "true");
|
|
172
169
|
if (this.disablePartialTranscripts) {
|
|
173
170
|
searchParams.set("disable_partial_transcripts", this.disablePartialTranscripts.toString());
|
|
174
171
|
}
|
package/dist/deno.mjs
CHANGED
|
@@ -140,7 +140,6 @@ class RealtimeTranscriber {
|
|
|
140
140
|
this.wordBoost = params.wordBoost;
|
|
141
141
|
this.encoding = params.encoding;
|
|
142
142
|
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
143
|
-
this.enableExtraSessionInformation = params.enableExtraSessionInformation;
|
|
144
143
|
this.disablePartialTranscripts = params.disablePartialTranscripts;
|
|
145
144
|
if ("token" in params && params.token)
|
|
146
145
|
this.token = params.token;
|
|
@@ -166,9 +165,7 @@ class RealtimeTranscriber {
|
|
|
166
165
|
if (this.encoding) {
|
|
167
166
|
searchParams.set("encoding", this.encoding);
|
|
168
167
|
}
|
|
169
|
-
|
|
170
|
-
searchParams.set("enable_extra_session_information", this.enableExtraSessionInformation.toString());
|
|
171
|
-
}
|
|
168
|
+
searchParams.set("enable_extra_session_information", "true");
|
|
172
169
|
if (this.disablePartialTranscripts) {
|
|
173
170
|
searchParams.set("disable_partial_transcripts", this.disablePartialTranscripts.toString());
|
|
174
171
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -188,7 +188,6 @@ class RealtimeTranscriber {
|
|
|
188
188
|
this.wordBoost = params.wordBoost;
|
|
189
189
|
this.encoding = params.encoding;
|
|
190
190
|
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
191
|
-
this.enableExtraSessionInformation = params.enableExtraSessionInformation;
|
|
192
191
|
this.disablePartialTranscripts = params.disablePartialTranscripts;
|
|
193
192
|
if ("token" in params && params.token)
|
|
194
193
|
this.token = params.token;
|
|
@@ -214,9 +213,7 @@ class RealtimeTranscriber {
|
|
|
214
213
|
if (this.encoding) {
|
|
215
214
|
searchParams.set("encoding", this.encoding);
|
|
216
215
|
}
|
|
217
|
-
|
|
218
|
-
searchParams.set("enable_extra_session_information", this.enableExtraSessionInformation.toString());
|
|
219
|
-
}
|
|
216
|
+
searchParams.set("enable_extra_session_information", "true");
|
|
220
217
|
if (this.disablePartialTranscripts) {
|
|
221
218
|
searchParams.set("disable_partial_transcripts", this.disablePartialTranscripts.toString());
|
|
222
219
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -186,7 +186,6 @@ class RealtimeTranscriber {
|
|
|
186
186
|
this.wordBoost = params.wordBoost;
|
|
187
187
|
this.encoding = params.encoding;
|
|
188
188
|
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
189
|
-
this.enableExtraSessionInformation = params.enableExtraSessionInformation;
|
|
190
189
|
this.disablePartialTranscripts = params.disablePartialTranscripts;
|
|
191
190
|
if ("token" in params && params.token)
|
|
192
191
|
this.token = params.token;
|
|
@@ -212,9 +211,7 @@ class RealtimeTranscriber {
|
|
|
212
211
|
if (this.encoding) {
|
|
213
212
|
searchParams.set("encoding", this.encoding);
|
|
214
213
|
}
|
|
215
|
-
|
|
216
|
-
searchParams.set("enable_extra_session_information", this.enableExtraSessionInformation.toString());
|
|
217
|
-
}
|
|
214
|
+
searchParams.set("enable_extra_session_information", "true");
|
|
218
215
|
if (this.disablePartialTranscripts) {
|
|
219
216
|
searchParams.set("disable_partial_transcripts", this.disablePartialTranscripts.toString());
|
|
220
217
|
}
|
package/dist/node.cjs
CHANGED
|
@@ -139,7 +139,6 @@ class RealtimeTranscriber {
|
|
|
139
139
|
this.wordBoost = params.wordBoost;
|
|
140
140
|
this.encoding = params.encoding;
|
|
141
141
|
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
142
|
-
this.enableExtraSessionInformation = params.enableExtraSessionInformation;
|
|
143
142
|
this.disablePartialTranscripts = params.disablePartialTranscripts;
|
|
144
143
|
if ("token" in params && params.token)
|
|
145
144
|
this.token = params.token;
|
|
@@ -165,9 +164,7 @@ class RealtimeTranscriber {
|
|
|
165
164
|
if (this.encoding) {
|
|
166
165
|
searchParams.set("encoding", this.encoding);
|
|
167
166
|
}
|
|
168
|
-
|
|
169
|
-
searchParams.set("enable_extra_session_information", this.enableExtraSessionInformation.toString());
|
|
170
|
-
}
|
|
167
|
+
searchParams.set("enable_extra_session_information", "true");
|
|
171
168
|
if (this.disablePartialTranscripts) {
|
|
172
169
|
searchParams.set("disable_partial_transcripts", this.disablePartialTranscripts.toString());
|
|
173
170
|
}
|
package/dist/node.mjs
CHANGED
|
@@ -137,7 +137,6 @@ class RealtimeTranscriber {
|
|
|
137
137
|
this.wordBoost = params.wordBoost;
|
|
138
138
|
this.encoding = params.encoding;
|
|
139
139
|
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
140
|
-
this.enableExtraSessionInformation = params.enableExtraSessionInformation;
|
|
141
140
|
this.disablePartialTranscripts = params.disablePartialTranscripts;
|
|
142
141
|
if ("token" in params && params.token)
|
|
143
142
|
this.token = params.token;
|
|
@@ -163,9 +162,7 @@ class RealtimeTranscriber {
|
|
|
163
162
|
if (this.encoding) {
|
|
164
163
|
searchParams.set("encoding", this.encoding);
|
|
165
164
|
}
|
|
166
|
-
|
|
167
|
-
searchParams.set("enable_extra_session_information", this.enableExtraSessionInformation.toString());
|
|
168
|
-
}
|
|
165
|
+
searchParams.set("enable_extra_session_information", "true");
|
|
169
166
|
if (this.disablePartialTranscripts) {
|
|
170
167
|
searchParams.set("disable_partial_transcripts", this.disablePartialTranscripts.toString());
|
|
171
168
|
}
|
|
@@ -29,7 +29,8 @@ type CreateRealtimeTranscriberParams = {
|
|
|
29
29
|
/**
|
|
30
30
|
* Enable extra session information.
|
|
31
31
|
* Set to `true` to receive the `session_information` message before the session ends. Defaults to `false`.
|
|
32
|
-
* @defaultValue
|
|
32
|
+
* @defaultValue true
|
|
33
|
+
* @deprecated This parameter is now ignored and will be removed. Session information will always be sent.
|
|
33
34
|
*/
|
|
34
35
|
enableExtraSessionInformation?: boolean;
|
|
35
36
|
} & ({
|
|
@@ -78,7 +79,8 @@ type RealtimeTranscriberParams = {
|
|
|
78
79
|
/**
|
|
79
80
|
* Enable extra session information.
|
|
80
81
|
* Set to `true` to receive the `session_information` message before the session ends. Defaults to `false`.
|
|
81
|
-
* @defaultValue
|
|
82
|
+
* @defaultValue true
|
|
83
|
+
* @deprecated This parameter is now ignored and will be removed. Session information will always be sent.
|
|
82
84
|
*/
|
|
83
85
|
enableExtraSessionInformation?: boolean;
|
|
84
86
|
} & ({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblyai",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.1",
|
|
4
4
|
"description": "The AssemblyAI JavaScript SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription, as well as the latest LeMUR models.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18"
|
|
@@ -50,7 +50,6 @@ export class RealtimeTranscriber {
|
|
|
50
50
|
private apiKey?: string;
|
|
51
51
|
private token?: string;
|
|
52
52
|
private endUtteranceSilenceThreshold?: number;
|
|
53
|
-
private enableExtraSessionInformation?: boolean;
|
|
54
53
|
private disablePartialTranscripts?: boolean;
|
|
55
54
|
|
|
56
55
|
private socket?: WebSocket;
|
|
@@ -63,7 +62,6 @@ export class RealtimeTranscriber {
|
|
|
63
62
|
this.wordBoost = params.wordBoost;
|
|
64
63
|
this.encoding = params.encoding;
|
|
65
64
|
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
66
|
-
this.enableExtraSessionInformation = params.enableExtraSessionInformation;
|
|
67
65
|
this.disablePartialTranscripts = params.disablePartialTranscripts;
|
|
68
66
|
if ("token" in params && params.token) this.token = params.token;
|
|
69
67
|
if ("apiKey" in params && params.apiKey) this.apiKey = params.apiKey;
|
|
@@ -91,12 +89,9 @@ export class RealtimeTranscriber {
|
|
|
91
89
|
if (this.encoding) {
|
|
92
90
|
searchParams.set("encoding", this.encoding);
|
|
93
91
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
this.enableExtraSessionInformation.toString(),
|
|
98
|
-
);
|
|
99
|
-
}
|
|
92
|
+
|
|
93
|
+
searchParams.set("enable_extra_session_information", "true");
|
|
94
|
+
|
|
100
95
|
if (this.disablePartialTranscripts) {
|
|
101
96
|
searchParams.set(
|
|
102
97
|
"disable_partial_transcripts",
|
|
@@ -37,7 +37,8 @@ type CreateRealtimeTranscriberParams = {
|
|
|
37
37
|
/**
|
|
38
38
|
* Enable extra session information.
|
|
39
39
|
* Set to `true` to receive the `session_information` message before the session ends. Defaults to `false`.
|
|
40
|
-
* @defaultValue
|
|
40
|
+
* @defaultValue true
|
|
41
|
+
* @deprecated This parameter is now ignored and will be removed. Session information will always be sent.
|
|
41
42
|
*/
|
|
42
43
|
enableExtraSessionInformation?: boolean;
|
|
43
44
|
} & (
|
|
@@ -91,7 +92,8 @@ type RealtimeTranscriberParams = {
|
|
|
91
92
|
/**
|
|
92
93
|
* Enable extra session information.
|
|
93
94
|
* Set to `true` to receive the `session_information` message before the session ends. Defaults to `false`.
|
|
94
|
-
* @defaultValue
|
|
95
|
+
* @defaultValue true
|
|
96
|
+
* @deprecated This parameter is now ignored and will be removed. Session information will always be sent.
|
|
95
97
|
*/
|
|
96
98
|
enableExtraSessionInformation?: boolean;
|
|
97
99
|
} & (
|