assemblyai 4.3.1 → 4.3.3
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 +27 -0
- package/README.md +165 -89
- package/dist/assemblyai.umd.js +62 -56
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/bun.mjs +57 -51
- package/dist/deno.mjs +57 -51
- package/dist/index.cjs +62 -56
- package/dist/index.mjs +62 -56
- package/dist/node.cjs +57 -51
- package/dist/node.mjs +57 -51
- package/dist/services/base.d.ts +1 -1
- package/dist/services/files/index.d.ts +2 -2
- package/dist/services/index.d.ts +1 -1
- package/dist/services/lemur/index.d.ts +1 -1
- package/dist/services/realtime/service.d.ts +2 -2
- package/dist/services/transcripts/index.d.ts +26 -26
- package/dist/types/asyncapi.generated.d.ts +60 -39
- package/dist/types/openapi.generated.d.ts +740 -347
- package/dist/types/services/index.d.ts +0 -1
- package/dist/types/transcripts/index.d.ts +14 -5
- package/package.json +26 -25
- package/src/polyfills/fs/index.ts +2 -2
- package/src/polyfills/fs/node.ts +1 -1
- package/src/polyfills/streams/index.ts +2 -2
- package/src/services/base.ts +3 -3
- package/src/services/files/index.ts +2 -2
- package/src/services/index.ts +1 -1
- package/src/services/lemur/index.ts +5 -5
- package/src/services/realtime/factory.ts +1 -1
- package/src/services/realtime/service.ts +7 -8
- package/src/services/transcripts/index.ts +59 -63
- package/src/types/asyncapi.generated.ts +64 -42
- package/src/types/openapi.generated.ts +748 -352
- package/src/types/services/index.ts +0 -1
- package/src/types/transcripts/index.ts +17 -7
- package/dist/types/services/abstractions.d.ts +0 -52
- package/src/types/services/abstractions.ts +0 -56
|
@@ -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){var i;return t(this,void 0,void 0,(function*(){(s=null!=s?s:{}).headers=null!==(i=s.headers)&&void 0!==i?i:{},s.headers=Object.assign({Authorization:this.params.apiKey,"Content-Type":"application/json"},s.headers),e.startsWith("http")||(e=this.params.baseUrl+e);const t=yield fetch(e,s);if(t.status>=400){let e;const s=yield t.text();if(s){try{e=JSON.parse(s)}catch(e){}if(null==e?void 0:e.error)throw new Error(e.error);throw new Error(s)}throw new Error(`HTTP Error: ${t.status} ${t.statusText}`)}return t}))}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(e=!0){return t(this,void 0,void 0,(function*(){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*(){const{audio:t}=e,s=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"]);let i;if("string"==typeof t){const e=f(t);i=null!==e?yield this.files.upload(e):t}else i=yield this.files.upload(t);return yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(Object.assign(Object.assign({},s),{audio_url:i}))})}))}create(e,s){var i;return t(this,void 0,void 0,(function*(){const t=f(e.audio_url);if(null!==t){const s=yield this.files.upload(t);e.audio_url=s}const n=yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(e)});return null===(i=null==s?void 0:s.poll)||void 0===i||i?yield this.waitUntilReady(n.id,s):n}))}waitUntilReady(e,s){var i,n;return t(this,void 0,void 0,(function*(){const t=null!==(i=null==s?void 0:s.pollingInterval)&&void 0!==i?i:3e3,o=null!==(n=null==s?void 0:s.pollingTimeout)&&void 0!==n?n:-1,r=Date.now();for(;;){const s=yield this.get(e);if("completed"===s.status||"error"===s.status)return s;if(o>0&&Date.now()-r>o)throw new Error("Polling timeout");yield new Promise((e=>setTimeout(e,t)))}}))}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,s="srt",i){return t(this,void 0,void 0,(function*(){let t=`/v2/transcript/${e}/${s}`;if(i){const e=new URLSearchParams;e.set("chars_per_caption",i.toString()),t+=`?${e.toString()}`}const n=yield this.fetch(t);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}));
|
|
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}));
|
package/dist/bun.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import WebSocket from '#ws';
|
|
|
6
6
|
class BaseService {
|
|
7
7
|
/**
|
|
8
8
|
* Create a new service.
|
|
9
|
-
* @param params The parameters to use for the service.
|
|
9
|
+
* @param params - The parameters to use for the service.
|
|
10
10
|
*/
|
|
11
11
|
constructor(params) {
|
|
12
12
|
this.params = params;
|
|
@@ -73,7 +73,7 @@ class LemurService extends BaseService {
|
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* Delete the data for a previously submitted LeMUR request.
|
|
76
|
-
* @param id ID of the LeMUR request
|
|
76
|
+
* @param id - ID of the LeMUR request
|
|
77
77
|
*/
|
|
78
78
|
purgeRequestData(id) {
|
|
79
79
|
return this.fetchJson(`/lemur/v3/${id}`, {
|
|
@@ -136,11 +136,10 @@ class RealtimeTranscriber {
|
|
|
136
136
|
constructor(params) {
|
|
137
137
|
this.listeners = {};
|
|
138
138
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
139
|
-
this.sampleRate = params.sampleRate ??
|
|
139
|
+
this.sampleRate = params.sampleRate ?? 16_000;
|
|
140
140
|
this.wordBoost = params.wordBoost;
|
|
141
141
|
this.encoding = params.encoding;
|
|
142
|
-
this.endUtteranceSilenceThreshold =
|
|
143
|
-
params.endUtteranceSilenceThreshold;
|
|
142
|
+
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
144
143
|
if ("token" in params && params.token)
|
|
145
144
|
this.token = params.token;
|
|
146
145
|
if ("apiKey" in params && params.apiKey)
|
|
@@ -264,8 +263,8 @@ class RealtimeTranscriber {
|
|
|
264
263
|
}
|
|
265
264
|
/**
|
|
266
265
|
* Configure the threshold for how long to wait before ending an utterance. Default is 700ms.
|
|
267
|
-
* @param threshold The duration of the end utterance silence threshold in milliseconds
|
|
268
|
-
*
|
|
266
|
+
* @param threshold - The duration of the end utterance silence threshold in milliseconds.
|
|
267
|
+
* This value must be an integer between 0 and 20_000.
|
|
269
268
|
*/
|
|
270
269
|
configureEndUtteranceSilenceThreshold(threshold) {
|
|
271
270
|
this.send(`{"end_utterance_silence_threshold":${threshold}}`);
|
|
@@ -355,8 +354,8 @@ class TranscriptService extends BaseService {
|
|
|
355
354
|
}
|
|
356
355
|
/**
|
|
357
356
|
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
|
|
358
|
-
* @param params The parameters to transcribe an audio file.
|
|
359
|
-
* @param options The options to transcribe an audio file.
|
|
357
|
+
* @param params - The parameters to transcribe an audio file.
|
|
358
|
+
* @param options - The options to transcribe an audio file.
|
|
360
359
|
* @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
|
|
361
360
|
*/
|
|
362
361
|
async transcribe(params, options) {
|
|
@@ -365,37 +364,44 @@ class TranscriptService extends BaseService {
|
|
|
365
364
|
}
|
|
366
365
|
/**
|
|
367
366
|
* Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
|
|
368
|
-
* @param params The parameters to start the transcription of an audio file.
|
|
367
|
+
* @param params - The parameters to start the transcription of an audio file.
|
|
369
368
|
* @returns A promise that resolves to the queued transcript.
|
|
370
369
|
*/
|
|
371
370
|
async submit(params) {
|
|
372
|
-
const { audio, ...createParams } = params;
|
|
373
371
|
let audioUrl;
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
372
|
+
let transcriptParams = undefined;
|
|
373
|
+
if ("audio" in params) {
|
|
374
|
+
const { audio, ...audioTranscriptParams } = params;
|
|
375
|
+
if (typeof audio === "string") {
|
|
376
|
+
const path = getPath(audio);
|
|
377
|
+
if (path !== null) {
|
|
378
|
+
// audio is local path, upload local file
|
|
379
|
+
audioUrl = await this.files.upload(path);
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
// audio is not a local path, assume it's a URL
|
|
383
|
+
audioUrl = audio;
|
|
384
|
+
}
|
|
379
385
|
}
|
|
380
386
|
else {
|
|
381
|
-
// audio is
|
|
382
|
-
audioUrl = audio;
|
|
387
|
+
// audio is of uploadable type
|
|
388
|
+
audioUrl = await this.files.upload(audio);
|
|
383
389
|
}
|
|
390
|
+
transcriptParams = { ...audioTranscriptParams, audio_url: audioUrl };
|
|
384
391
|
}
|
|
385
392
|
else {
|
|
386
|
-
|
|
387
|
-
audioUrl = await this.files.upload(audio);
|
|
393
|
+
transcriptParams = params;
|
|
388
394
|
}
|
|
389
395
|
const data = await this.fetchJson("/v2/transcript", {
|
|
390
396
|
method: "POST",
|
|
391
|
-
body: JSON.stringify(
|
|
397
|
+
body: JSON.stringify(transcriptParams),
|
|
392
398
|
});
|
|
393
399
|
return data;
|
|
394
400
|
}
|
|
395
401
|
/**
|
|
396
402
|
* Create a transcript.
|
|
397
|
-
* @param params The parameters to create a transcript.
|
|
398
|
-
* @param options The options used for creating the new transcript.
|
|
403
|
+
* @param params - The parameters to create a transcript.
|
|
404
|
+
* @param options - The options used for creating the new transcript.
|
|
399
405
|
* @returns A promise that resolves to the transcript.
|
|
400
406
|
* @deprecated Use `transcribe` instead to transcribe a audio file that includes polling, or `submit` to transcribe a audio file without polling.
|
|
401
407
|
*/
|
|
@@ -416,12 +422,12 @@ class TranscriptService extends BaseService {
|
|
|
416
422
|
}
|
|
417
423
|
/**
|
|
418
424
|
* Wait until the transcript ready, either the status is "completed" or "error".
|
|
419
|
-
* @param transcriptId The ID of the transcript.
|
|
420
|
-
* @param options The options to wait until the transcript is ready.
|
|
425
|
+
* @param transcriptId - The ID of the transcript.
|
|
426
|
+
* @param options - The options to wait until the transcript is ready.
|
|
421
427
|
* @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
|
|
422
428
|
*/
|
|
423
429
|
async waitUntilReady(transcriptId, options) {
|
|
424
|
-
const pollingInterval = options?.pollingInterval ??
|
|
430
|
+
const pollingInterval = options?.pollingInterval ?? 3_000;
|
|
425
431
|
const pollingTimeout = options?.pollingTimeout ?? -1;
|
|
426
432
|
const startTime = Date.now();
|
|
427
433
|
// eslint-disable-next-line no-constant-condition
|
|
@@ -441,7 +447,7 @@ class TranscriptService extends BaseService {
|
|
|
441
447
|
}
|
|
442
448
|
/**
|
|
443
449
|
* Retrieve a transcript.
|
|
444
|
-
* @param id The identifier of the transcript.
|
|
450
|
+
* @param id - The identifier of the transcript.
|
|
445
451
|
* @returns A promise that resolves to the transcript.
|
|
446
452
|
*/
|
|
447
453
|
get(id) {
|
|
@@ -449,17 +455,17 @@ class TranscriptService extends BaseService {
|
|
|
449
455
|
}
|
|
450
456
|
/**
|
|
451
457
|
* Retrieves a page of transcript listings.
|
|
452
|
-
* @param
|
|
458
|
+
* @param params - The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
|
|
453
459
|
*/
|
|
454
|
-
async list(
|
|
460
|
+
async list(params) {
|
|
455
461
|
let url = "/v2/transcript";
|
|
456
|
-
if (typeof
|
|
457
|
-
url =
|
|
462
|
+
if (typeof params === "string") {
|
|
463
|
+
url = params;
|
|
458
464
|
}
|
|
459
|
-
else if (
|
|
460
|
-
url = `${url}?${new URLSearchParams(Object.keys(
|
|
465
|
+
else if (params) {
|
|
466
|
+
url = `${url}?${new URLSearchParams(Object.keys(params).map((key) => [
|
|
461
467
|
key,
|
|
462
|
-
|
|
468
|
+
params[key]?.toString() || "",
|
|
463
469
|
]))}`;
|
|
464
470
|
}
|
|
465
471
|
const data = await this.fetchJson(url);
|
|
@@ -473,7 +479,7 @@ class TranscriptService extends BaseService {
|
|
|
473
479
|
}
|
|
474
480
|
/**
|
|
475
481
|
* Delete a transcript
|
|
476
|
-
* @param id The identifier of the transcript.
|
|
482
|
+
* @param id - The identifier of the transcript.
|
|
477
483
|
* @returns A promise that resolves to the transcript.
|
|
478
484
|
*/
|
|
479
485
|
delete(id) {
|
|
@@ -482,9 +488,9 @@ class TranscriptService extends BaseService {
|
|
|
482
488
|
/**
|
|
483
489
|
* Search through the transcript for a specific set of keywords.
|
|
484
490
|
* You can search for individual words, numbers, or phrases containing up to five words or numbers.
|
|
485
|
-
* @param id The identifier of the transcript.
|
|
486
|
-
* @param words Keywords to search for.
|
|
487
|
-
* @
|
|
491
|
+
* @param id - The identifier of the transcript.
|
|
492
|
+
* @param words - Keywords to search for.
|
|
493
|
+
* @returns A promise that resolves to the sentences.
|
|
488
494
|
*/
|
|
489
495
|
wordSearch(id, words) {
|
|
490
496
|
const params = new URLSearchParams({ words: words.join(",") });
|
|
@@ -492,26 +498,26 @@ class TranscriptService extends BaseService {
|
|
|
492
498
|
}
|
|
493
499
|
/**
|
|
494
500
|
* Retrieve all sentences of a transcript.
|
|
495
|
-
* @param id The identifier of the transcript.
|
|
496
|
-
* @
|
|
501
|
+
* @param id - The identifier of the transcript.
|
|
502
|
+
* @returns A promise that resolves to the sentences.
|
|
497
503
|
*/
|
|
498
504
|
sentences(id) {
|
|
499
505
|
return this.fetchJson(`/v2/transcript/${id}/sentences`);
|
|
500
506
|
}
|
|
501
507
|
/**
|
|
502
508
|
* Retrieve all paragraphs of a transcript.
|
|
503
|
-
* @param id The identifier of the transcript.
|
|
504
|
-
* @
|
|
509
|
+
* @param id - The identifier of the transcript.
|
|
510
|
+
* @returns A promise that resolves to the paragraphs.
|
|
505
511
|
*/
|
|
506
512
|
paragraphs(id) {
|
|
507
513
|
return this.fetchJson(`/v2/transcript/${id}/paragraphs`);
|
|
508
514
|
}
|
|
509
515
|
/**
|
|
510
516
|
* Retrieve subtitles of a transcript.
|
|
511
|
-
* @param id The identifier of the transcript.
|
|
512
|
-
* @param format The format of the subtitles.
|
|
513
|
-
* @param chars_per_caption The maximum number of characters per caption.
|
|
514
|
-
* @
|
|
517
|
+
* @param id - The identifier of the transcript.
|
|
518
|
+
* @param format - The format of the subtitles.
|
|
519
|
+
* @param chars_per_caption - The maximum number of characters per caption.
|
|
520
|
+
* @returns A promise that resolves to the subtitles text.
|
|
515
521
|
*/
|
|
516
522
|
async subtitles(id, format = "srt", chars_per_caption) {
|
|
517
523
|
let url = `/v2/transcript/${id}/${format}`;
|
|
@@ -525,8 +531,8 @@ class TranscriptService extends BaseService {
|
|
|
525
531
|
}
|
|
526
532
|
/**
|
|
527
533
|
* Retrieve redactions of a transcript.
|
|
528
|
-
* @param id The identifier of the transcript.
|
|
529
|
-
* @
|
|
534
|
+
* @param id - The identifier of the transcript.
|
|
535
|
+
* @returns A promise that resolves to the subtitles text.
|
|
530
536
|
*/
|
|
531
537
|
redactions(id) {
|
|
532
538
|
return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
|
|
@@ -538,8 +544,8 @@ const readFile = async (path) => Bun.file(path).stream();
|
|
|
538
544
|
class FileService extends BaseService {
|
|
539
545
|
/**
|
|
540
546
|
* Upload a local file to AssemblyAI.
|
|
541
|
-
* @param input The local file path to upload, or a stream or buffer of the file to upload.
|
|
542
|
-
* @
|
|
547
|
+
* @param input - The local file path to upload, or a stream or buffer of the file to upload.
|
|
548
|
+
* @returns A promise that resolves to the uploaded file URL.
|
|
543
549
|
*/
|
|
544
550
|
async upload(input) {
|
|
545
551
|
let fileData;
|
|
@@ -563,7 +569,7 @@ const defaultBaseUrl = "https://api.assemblyai.com";
|
|
|
563
569
|
class AssemblyAI {
|
|
564
570
|
/**
|
|
565
571
|
* Create a new AssemblyAI client.
|
|
566
|
-
* @param params The parameters for the service, including the API key and base URL, if any.
|
|
572
|
+
* @param params - The parameters for the service, including the API key and base URL, if any.
|
|
567
573
|
*/
|
|
568
574
|
constructor(params) {
|
|
569
575
|
params.baseUrl = params.baseUrl || defaultBaseUrl;
|
package/dist/deno.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import WebSocket from '#ws';
|
|
|
6
6
|
class BaseService {
|
|
7
7
|
/**
|
|
8
8
|
* Create a new service.
|
|
9
|
-
* @param params The parameters to use for the service.
|
|
9
|
+
* @param params - The parameters to use for the service.
|
|
10
10
|
*/
|
|
11
11
|
constructor(params) {
|
|
12
12
|
this.params = params;
|
|
@@ -73,7 +73,7 @@ class LemurService extends BaseService {
|
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* Delete the data for a previously submitted LeMUR request.
|
|
76
|
-
* @param id ID of the LeMUR request
|
|
76
|
+
* @param id - ID of the LeMUR request
|
|
77
77
|
*/
|
|
78
78
|
purgeRequestData(id) {
|
|
79
79
|
return this.fetchJson(`/lemur/v3/${id}`, {
|
|
@@ -136,11 +136,10 @@ class RealtimeTranscriber {
|
|
|
136
136
|
constructor(params) {
|
|
137
137
|
this.listeners = {};
|
|
138
138
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
139
|
-
this.sampleRate = params.sampleRate ??
|
|
139
|
+
this.sampleRate = params.sampleRate ?? 16_000;
|
|
140
140
|
this.wordBoost = params.wordBoost;
|
|
141
141
|
this.encoding = params.encoding;
|
|
142
|
-
this.endUtteranceSilenceThreshold =
|
|
143
|
-
params.endUtteranceSilenceThreshold;
|
|
142
|
+
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
144
143
|
if ("token" in params && params.token)
|
|
145
144
|
this.token = params.token;
|
|
146
145
|
if ("apiKey" in params && params.apiKey)
|
|
@@ -264,8 +263,8 @@ class RealtimeTranscriber {
|
|
|
264
263
|
}
|
|
265
264
|
/**
|
|
266
265
|
* Configure the threshold for how long to wait before ending an utterance. Default is 700ms.
|
|
267
|
-
* @param threshold The duration of the end utterance silence threshold in milliseconds
|
|
268
|
-
*
|
|
266
|
+
* @param threshold - The duration of the end utterance silence threshold in milliseconds.
|
|
267
|
+
* This value must be an integer between 0 and 20_000.
|
|
269
268
|
*/
|
|
270
269
|
configureEndUtteranceSilenceThreshold(threshold) {
|
|
271
270
|
this.send(`{"end_utterance_silence_threshold":${threshold}}`);
|
|
@@ -355,8 +354,8 @@ class TranscriptService extends BaseService {
|
|
|
355
354
|
}
|
|
356
355
|
/**
|
|
357
356
|
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
|
|
358
|
-
* @param params The parameters to transcribe an audio file.
|
|
359
|
-
* @param options The options to transcribe an audio file.
|
|
357
|
+
* @param params - The parameters to transcribe an audio file.
|
|
358
|
+
* @param options - The options to transcribe an audio file.
|
|
360
359
|
* @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
|
|
361
360
|
*/
|
|
362
361
|
async transcribe(params, options) {
|
|
@@ -365,37 +364,44 @@ class TranscriptService extends BaseService {
|
|
|
365
364
|
}
|
|
366
365
|
/**
|
|
367
366
|
* Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
|
|
368
|
-
* @param params The parameters to start the transcription of an audio file.
|
|
367
|
+
* @param params - The parameters to start the transcription of an audio file.
|
|
369
368
|
* @returns A promise that resolves to the queued transcript.
|
|
370
369
|
*/
|
|
371
370
|
async submit(params) {
|
|
372
|
-
const { audio, ...createParams } = params;
|
|
373
371
|
let audioUrl;
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
372
|
+
let transcriptParams = undefined;
|
|
373
|
+
if ("audio" in params) {
|
|
374
|
+
const { audio, ...audioTranscriptParams } = params;
|
|
375
|
+
if (typeof audio === "string") {
|
|
376
|
+
const path = getPath(audio);
|
|
377
|
+
if (path !== null) {
|
|
378
|
+
// audio is local path, upload local file
|
|
379
|
+
audioUrl = await this.files.upload(path);
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
// audio is not a local path, assume it's a URL
|
|
383
|
+
audioUrl = audio;
|
|
384
|
+
}
|
|
379
385
|
}
|
|
380
386
|
else {
|
|
381
|
-
// audio is
|
|
382
|
-
audioUrl = audio;
|
|
387
|
+
// audio is of uploadable type
|
|
388
|
+
audioUrl = await this.files.upload(audio);
|
|
383
389
|
}
|
|
390
|
+
transcriptParams = { ...audioTranscriptParams, audio_url: audioUrl };
|
|
384
391
|
}
|
|
385
392
|
else {
|
|
386
|
-
|
|
387
|
-
audioUrl = await this.files.upload(audio);
|
|
393
|
+
transcriptParams = params;
|
|
388
394
|
}
|
|
389
395
|
const data = await this.fetchJson("/v2/transcript", {
|
|
390
396
|
method: "POST",
|
|
391
|
-
body: JSON.stringify(
|
|
397
|
+
body: JSON.stringify(transcriptParams),
|
|
392
398
|
});
|
|
393
399
|
return data;
|
|
394
400
|
}
|
|
395
401
|
/**
|
|
396
402
|
* Create a transcript.
|
|
397
|
-
* @param params The parameters to create a transcript.
|
|
398
|
-
* @param options The options used for creating the new transcript.
|
|
403
|
+
* @param params - The parameters to create a transcript.
|
|
404
|
+
* @param options - The options used for creating the new transcript.
|
|
399
405
|
* @returns A promise that resolves to the transcript.
|
|
400
406
|
* @deprecated Use `transcribe` instead to transcribe a audio file that includes polling, or `submit` to transcribe a audio file without polling.
|
|
401
407
|
*/
|
|
@@ -416,12 +422,12 @@ class TranscriptService extends BaseService {
|
|
|
416
422
|
}
|
|
417
423
|
/**
|
|
418
424
|
* Wait until the transcript ready, either the status is "completed" or "error".
|
|
419
|
-
* @param transcriptId The ID of the transcript.
|
|
420
|
-
* @param options The options to wait until the transcript is ready.
|
|
425
|
+
* @param transcriptId - The ID of the transcript.
|
|
426
|
+
* @param options - The options to wait until the transcript is ready.
|
|
421
427
|
* @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
|
|
422
428
|
*/
|
|
423
429
|
async waitUntilReady(transcriptId, options) {
|
|
424
|
-
const pollingInterval = options?.pollingInterval ??
|
|
430
|
+
const pollingInterval = options?.pollingInterval ?? 3_000;
|
|
425
431
|
const pollingTimeout = options?.pollingTimeout ?? -1;
|
|
426
432
|
const startTime = Date.now();
|
|
427
433
|
// eslint-disable-next-line no-constant-condition
|
|
@@ -441,7 +447,7 @@ class TranscriptService extends BaseService {
|
|
|
441
447
|
}
|
|
442
448
|
/**
|
|
443
449
|
* Retrieve a transcript.
|
|
444
|
-
* @param id The identifier of the transcript.
|
|
450
|
+
* @param id - The identifier of the transcript.
|
|
445
451
|
* @returns A promise that resolves to the transcript.
|
|
446
452
|
*/
|
|
447
453
|
get(id) {
|
|
@@ -449,17 +455,17 @@ class TranscriptService extends BaseService {
|
|
|
449
455
|
}
|
|
450
456
|
/**
|
|
451
457
|
* Retrieves a page of transcript listings.
|
|
452
|
-
* @param
|
|
458
|
+
* @param params - The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
|
|
453
459
|
*/
|
|
454
|
-
async list(
|
|
460
|
+
async list(params) {
|
|
455
461
|
let url = "/v2/transcript";
|
|
456
|
-
if (typeof
|
|
457
|
-
url =
|
|
462
|
+
if (typeof params === "string") {
|
|
463
|
+
url = params;
|
|
458
464
|
}
|
|
459
|
-
else if (
|
|
460
|
-
url = `${url}?${new URLSearchParams(Object.keys(
|
|
465
|
+
else if (params) {
|
|
466
|
+
url = `${url}?${new URLSearchParams(Object.keys(params).map((key) => [
|
|
461
467
|
key,
|
|
462
|
-
|
|
468
|
+
params[key]?.toString() || "",
|
|
463
469
|
]))}`;
|
|
464
470
|
}
|
|
465
471
|
const data = await this.fetchJson(url);
|
|
@@ -473,7 +479,7 @@ class TranscriptService extends BaseService {
|
|
|
473
479
|
}
|
|
474
480
|
/**
|
|
475
481
|
* Delete a transcript
|
|
476
|
-
* @param id The identifier of the transcript.
|
|
482
|
+
* @param id - The identifier of the transcript.
|
|
477
483
|
* @returns A promise that resolves to the transcript.
|
|
478
484
|
*/
|
|
479
485
|
delete(id) {
|
|
@@ -482,9 +488,9 @@ class TranscriptService extends BaseService {
|
|
|
482
488
|
/**
|
|
483
489
|
* Search through the transcript for a specific set of keywords.
|
|
484
490
|
* You can search for individual words, numbers, or phrases containing up to five words or numbers.
|
|
485
|
-
* @param id The identifier of the transcript.
|
|
486
|
-
* @param words Keywords to search for.
|
|
487
|
-
* @
|
|
491
|
+
* @param id - The identifier of the transcript.
|
|
492
|
+
* @param words - Keywords to search for.
|
|
493
|
+
* @returns A promise that resolves to the sentences.
|
|
488
494
|
*/
|
|
489
495
|
wordSearch(id, words) {
|
|
490
496
|
const params = new URLSearchParams({ words: words.join(",") });
|
|
@@ -492,26 +498,26 @@ class TranscriptService extends BaseService {
|
|
|
492
498
|
}
|
|
493
499
|
/**
|
|
494
500
|
* Retrieve all sentences of a transcript.
|
|
495
|
-
* @param id The identifier of the transcript.
|
|
496
|
-
* @
|
|
501
|
+
* @param id - The identifier of the transcript.
|
|
502
|
+
* @returns A promise that resolves to the sentences.
|
|
497
503
|
*/
|
|
498
504
|
sentences(id) {
|
|
499
505
|
return this.fetchJson(`/v2/transcript/${id}/sentences`);
|
|
500
506
|
}
|
|
501
507
|
/**
|
|
502
508
|
* Retrieve all paragraphs of a transcript.
|
|
503
|
-
* @param id The identifier of the transcript.
|
|
504
|
-
* @
|
|
509
|
+
* @param id - The identifier of the transcript.
|
|
510
|
+
* @returns A promise that resolves to the paragraphs.
|
|
505
511
|
*/
|
|
506
512
|
paragraphs(id) {
|
|
507
513
|
return this.fetchJson(`/v2/transcript/${id}/paragraphs`);
|
|
508
514
|
}
|
|
509
515
|
/**
|
|
510
516
|
* Retrieve subtitles of a transcript.
|
|
511
|
-
* @param id The identifier of the transcript.
|
|
512
|
-
* @param format The format of the subtitles.
|
|
513
|
-
* @param chars_per_caption The maximum number of characters per caption.
|
|
514
|
-
* @
|
|
517
|
+
* @param id - The identifier of the transcript.
|
|
518
|
+
* @param format - The format of the subtitles.
|
|
519
|
+
* @param chars_per_caption - The maximum number of characters per caption.
|
|
520
|
+
* @returns A promise that resolves to the subtitles text.
|
|
515
521
|
*/
|
|
516
522
|
async subtitles(id, format = "srt", chars_per_caption) {
|
|
517
523
|
let url = `/v2/transcript/${id}/${format}`;
|
|
@@ -525,8 +531,8 @@ class TranscriptService extends BaseService {
|
|
|
525
531
|
}
|
|
526
532
|
/**
|
|
527
533
|
* Retrieve redactions of a transcript.
|
|
528
|
-
* @param id The identifier of the transcript.
|
|
529
|
-
* @
|
|
534
|
+
* @param id - The identifier of the transcript.
|
|
535
|
+
* @returns A promise that resolves to the subtitles text.
|
|
530
536
|
*/
|
|
531
537
|
redactions(id) {
|
|
532
538
|
return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
|
|
@@ -538,8 +544,8 @@ const readFile = async (path) => (await Deno.open(path)).readable;
|
|
|
538
544
|
class FileService extends BaseService {
|
|
539
545
|
/**
|
|
540
546
|
* Upload a local file to AssemblyAI.
|
|
541
|
-
* @param input The local file path to upload, or a stream or buffer of the file to upload.
|
|
542
|
-
* @
|
|
547
|
+
* @param input - The local file path to upload, or a stream or buffer of the file to upload.
|
|
548
|
+
* @returns A promise that resolves to the uploaded file URL.
|
|
543
549
|
*/
|
|
544
550
|
async upload(input) {
|
|
545
551
|
let fileData;
|
|
@@ -563,7 +569,7 @@ const defaultBaseUrl = "https://api.assemblyai.com";
|
|
|
563
569
|
class AssemblyAI {
|
|
564
570
|
/**
|
|
565
571
|
* Create a new AssemblyAI client.
|
|
566
|
-
* @param params The parameters for the service, including the API key and base URL, if any.
|
|
572
|
+
* @param params - The parameters for the service, including the API key and base URL, if any.
|
|
567
573
|
*/
|
|
568
574
|
constructor(params) {
|
|
569
575
|
params.baseUrl = params.baseUrl || defaultBaseUrl;
|