assemblyai 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -1
- package/dist/assemblyai.umd.js +11 -8
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/bun.mjs +11 -8
- package/dist/deno.mjs +11 -8
- package/dist/index.cjs +11 -8
- package/dist/index.mjs +11 -8
- package/dist/node.cjs +11 -8
- package/dist/node.mjs +11 -8
- package/dist/services/realtime/service.d.ts +1 -0
- package/dist/types/asyncapi.generated.d.ts +10 -1
- package/dist/types/helpers/index.d.ts +1 -0
- package/dist/types/openapi.generated.d.ts +1990 -68
- package/dist/types/realtime/index.d.ts +3 -1
- package/package.json +1 -1
- package/src/services/realtime/factory.ts +4 -4
- package/src/services/realtime/service.ts +8 -2
- package/src/types/asyncapi.generated.ts +13 -1
- package/src/types/helpers/index.ts +4 -0
- package/src/types/openapi.generated.ts +1995 -68
- package/src/types/realtime/index.ts +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [4.
|
|
3
|
+
## [4.1.0] - 2023-12-22
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Add `"anthropic/claude-2-1"` to `LemurModel` type
|
|
8
|
+
- Add `encoding` option to the real-time service and factory. `encoding` can be `"pcm_s16le"` or `"pcm_mulaw"`.
|
|
9
|
+
- `"pcm_mulaw"` is a newly supported audio encoding for the real-time service.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Allow any string into `final_model` for LeMUR requests
|
|
14
|
+
|
|
15
|
+
## [4.0.1] - 2023-12-14
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- Add `"assemblyai/mistral-7b"` to `LemurModel` type
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- Update types with `@example`
|
|
24
|
+
- Update types with `Format: uuid` if applicable
|
|
25
|
+
|
|
26
|
+
## [4.0.0] - 2023-12-08
|
|
4
27
|
|
|
5
28
|
### Added
|
|
6
29
|
|
package/dist/assemblyai.umd.js
CHANGED
|
@@ -202,11 +202,12 @@
|
|
|
202
202
|
this.realtimeUrl = (_a = params.realtimeUrl) !== null && _a !== void 0 ? _a : defaultRealtimeUrl;
|
|
203
203
|
this.sampleRate = (_b = params.sampleRate) !== null && _b !== void 0 ? _b : 16000;
|
|
204
204
|
this.wordBoost = params.wordBoost;
|
|
205
|
-
|
|
206
|
-
this.apiKey = params.apiKey;
|
|
205
|
+
this.encoding = params.encoding;
|
|
207
206
|
if ("token" in params && params.token)
|
|
208
207
|
this.token = params.token;
|
|
209
|
-
if (
|
|
208
|
+
if ("apiKey" in params && params.apiKey)
|
|
209
|
+
this.apiKey = params.apiKey;
|
|
210
|
+
if (!(this.token || this.apiKey)) {
|
|
210
211
|
throw new Error("API key or temporary token is required.");
|
|
211
212
|
}
|
|
212
213
|
}
|
|
@@ -223,6 +224,9 @@
|
|
|
223
224
|
if (this.wordBoost && this.wordBoost.length > 0) {
|
|
224
225
|
searchParams.set("word_boost", JSON.stringify(this.wordBoost));
|
|
225
226
|
}
|
|
227
|
+
if (this.encoding) {
|
|
228
|
+
searchParams.set("encoding", this.encoding);
|
|
229
|
+
}
|
|
226
230
|
url.search = searchParams.toString();
|
|
227
231
|
return url;
|
|
228
232
|
}
|
|
@@ -356,12 +360,11 @@
|
|
|
356
360
|
this.rtFactoryParams = params;
|
|
357
361
|
}
|
|
358
362
|
createService(params) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
params.apiKey = this.rtFactoryParams.apiKey;
|
|
363
|
+
const serviceParams = Object.assign({}, params);
|
|
364
|
+
if (!serviceParams.token && !serviceParams.apiKey) {
|
|
365
|
+
serviceParams.apiKey = this.rtFactoryParams.apiKey;
|
|
363
366
|
}
|
|
364
|
-
return new RealtimeService(
|
|
367
|
+
return new RealtimeService(serviceParams);
|
|
365
368
|
}
|
|
366
369
|
createTemporaryToken(params) {
|
|
367
370
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -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,o){return new(s||(s=Promise))((function(i,n){function r(e){try{c(o.next(e))}catch(e){n(e)}}function a(e){try{c(o.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,a)}c((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class s{constructor(e){this.params=e}fetch(e,s){var o;return t(this,void 0,void 0,(function*(){(s=null!=s?s:{}).headers=null!==(o=s.headers)&&void 0!==o?o:{},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 o 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:i}="undefined"!=typeof window?window:"undefined"!=typeof global?global:globalThis;var n=null;"undefined"!=typeof WebSocket?n=WebSocket:"undefined"!=typeof MozWebSocket?n=MozWebSocket:"undefined"!=typeof global?n=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window?n=window.WebSocket||window.MozWebSocket:"undefined"!=typeof self&&(n=self.WebSocket||self.MozWebSocket);var r,a=n;!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{}class d{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,"apiKey"in e&&e.apiKey&&(this.apiKey=e.apiKey),"token"in e&&e.token&&(this.token=e.token),!this.apiKey&&!this.token)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)),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.onclose=({code:e,reason:t})=>{var s,o;t||e in r&&(t=c[e]),null===(o=(s=this.listeners).close)||void 0===o||o.call(s,e,t)},this.socket.onerror=e=>{var t,s,o,i;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(i=(o=this.listeners).error)||void 0===i||i.call(o,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,o,i,n,r,a,c,d,u,h,f,p,m;const y=JSON.parse(t.toString());if("error"in y)null===(o=(s=this.listeners).error)||void 0===o||o.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===(n=(i=this.listeners).open)||void 0===n||n.call(i,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===(h=(u=this.listeners).transcript)||void 0===h||h.call(u,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){if(!this.socket||this.socket.readyState!==a.OPEN)throw new Error("Socket is not open for communication");let t;t="undefined"!=typeof Buffer?Buffer.from(e).toString("base64"):btoa(new Uint8Array(e).reduce(((e,t)=>e+String.fromCharCode(t)),""));const s={audio_data:t};this.socket.send(JSON.stringify(s))}stream(){return new i({write:e=>{this.sendAudio(e)}})}close(e=!0){return t(this,void 0,void 0,(function*(){if(this.socket){if(this.socket.readyState===a.OPEN){const t='{"terminate_session": true}';if(e){const e=new Promise((e=>{this.sessionTerminatedResolve=e}));this.socket.send(t),yield e}else this.socket.send(t)}"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 e?"token"in e||e.apiKey||(e.apiKey=this.rtFactoryParams.apiKey):e={apiKey:this.rtFactoryParams.apiKey},new d(e)}createTemporaryToken(e){return t(this,void 0,void 0,(function*(){return(yield this.fetchJson("/v2/realtime/token",{method:"POST",body:JSON.stringify(e)})).token}))}}class h 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 o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(s[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(s[o[i]]=e[o[i]])}return s}(e,["audio"]);let o;if("string"==typeof t){const e=f(t);o=null!==e?yield this.files.upload(e):t}else o=yield this.files.upload(t);return yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(Object.assign(Object.assign({},s),{audio_url:o}))})}))}create(e,s){var o;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 i=yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(e)});return null===(o=null==s?void 0:s.poll)||void 0===o||o?yield this.waitUntilReady(i.id,s):i}))}waitUntilReady(e,s){var o,i;return t(this,void 0,void 0,(function*(){const t=null!==(o=null==s?void 0:s.pollingInterval)&&void 0!==o?o:3e3,n=null!==(i=null==s?void 0:s.pollingTimeout)&&void 0!==i?i:-1,r=Date.now();for(;;){const s=yield this.get(e);if("completed"===s.status||"error"===s.status)return s;if(n>0&&Date.now()-r>n)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",o){return t(this,void 0,void 0,(function*(){let t=`/v2/transcript/${e}/${s}`;if(o){const e=new URLSearchParams;e.set("chars_per_caption",o.toString()),t+=`?${e.toString()}`}const i=yield this.fetch(t);return yield i.text()}))}redactions(e){return this.fetchJson(`/v2/transcript/${e}/redacted-audio`)}}function f(e){let t;try{return t=new URL(e),"file:"===t.protocol?t.pathname:null}catch(t){return e}}class p 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 p(e),this.transcripts=new h(e,this.files),this.lemur=new o(e),this.realtime=new u(e)}},e.FileService=p,e.LemurService=o,e.RealtimeService=d,e.RealtimeServiceFactory=u,e.TranscriptService=h}));
|
|
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,o){return new(s||(s=Promise))((function(i,n){function r(e){try{c(o.next(e))}catch(e){n(e)}}function a(e){try{c(o.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,a)}c((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class s{constructor(e){this.params=e}fetch(e,s){var o;return t(this,void 0,void 0,(function*(){(s=null!=s?s:{}).headers=null!==(o=s.headers)&&void 0!==o?o:{},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 o 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:i}="undefined"!=typeof window?window:"undefined"!=typeof global?global:globalThis;var n=null;"undefined"!=typeof WebSocket?n=WebSocket:"undefined"!=typeof MozWebSocket?n=MozWebSocket:"undefined"!=typeof global?n=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window?n=window.WebSocket||window.MozWebSocket:"undefined"!=typeof self&&(n=self.WebSocket||self.MozWebSocket);var r,a=n;!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{}class d{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,"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.onclose=({code:e,reason:t})=>{var s,o;t||e in r&&(t=c[e]),null===(o=(s=this.listeners).close)||void 0===o||o.call(s,e,t)},this.socket.onerror=e=>{var t,s,o,i;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(i=(o=this.listeners).error)||void 0===i||i.call(o,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,o,i,n,r,a,c,d,u,h,f,p,m;const y=JSON.parse(t.toString());if("error"in y)null===(o=(s=this.listeners).error)||void 0===o||o.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===(n=(i=this.listeners).open)||void 0===n||n.call(i,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===(h=(u=this.listeners).transcript)||void 0===h||h.call(u,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){if(!this.socket||this.socket.readyState!==a.OPEN)throw new Error("Socket is not open for communication");let t;t="undefined"!=typeof Buffer?Buffer.from(e).toString("base64"):btoa(new Uint8Array(e).reduce(((e,t)=>e+String.fromCharCode(t)),""));const s={audio_data:t};this.socket.send(JSON.stringify(s))}stream(){return new i({write:e=>{this.sendAudio(e)}})}close(e=!0){return t(this,void 0,void 0,(function*(){if(this.socket){if(this.socket.readyState===a.OPEN){const t='{"terminate_session": true}';if(e){const e=new Promise((e=>{this.sessionTerminatedResolve=e}));this.socket.send(t),yield e}else this.socket.send(t)}"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){const t=Object.assign({},e);return t.token||t.apiKey||(t.apiKey=this.rtFactoryParams.apiKey),new d(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}))}}class h 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 o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(s[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(s[o[i]]=e[o[i]])}return s}(e,["audio"]);let o;if("string"==typeof t){const e=f(t);o=null!==e?yield this.files.upload(e):t}else o=yield this.files.upload(t);return yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(Object.assign(Object.assign({},s),{audio_url:o}))})}))}create(e,s){var o;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 i=yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(e)});return null===(o=null==s?void 0:s.poll)||void 0===o||o?yield this.waitUntilReady(i.id,s):i}))}waitUntilReady(e,s){var o,i;return t(this,void 0,void 0,(function*(){const t=null!==(o=null==s?void 0:s.pollingInterval)&&void 0!==o?o:3e3,n=null!==(i=null==s?void 0:s.pollingTimeout)&&void 0!==i?i:-1,r=Date.now();for(;;){const s=yield this.get(e);if("completed"===s.status||"error"===s.status)return s;if(n>0&&Date.now()-r>n)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",o){return t(this,void 0,void 0,(function*(){let t=`/v2/transcript/${e}/${s}`;if(o){const e=new URLSearchParams;e.set("chars_per_caption",o.toString()),t+=`?${e.toString()}`}const i=yield this.fetch(t);return yield i.text()}))}redactions(e){return this.fetchJson(`/v2/transcript/${e}/redacted-audio`)}}function f(e){let t;try{return t=new URL(e),"file:"===t.protocol?t.pathname:null}catch(t){return e}}class p 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 p(e),this.transcripts=new h(e,this.files),this.lemur=new o(e),this.realtime=new u(e)}},e.FileService=p,e.LemurService=o,e.RealtimeService=d,e.RealtimeServiceFactory=u,e.TranscriptService=h}));
|
package/dist/bun.mjs
CHANGED
|
@@ -136,11 +136,12 @@ class RealtimeService {
|
|
|
136
136
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
137
137
|
this.sampleRate = params.sampleRate ?? 16000;
|
|
138
138
|
this.wordBoost = params.wordBoost;
|
|
139
|
-
|
|
140
|
-
this.apiKey = params.apiKey;
|
|
139
|
+
this.encoding = params.encoding;
|
|
141
140
|
if ("token" in params && params.token)
|
|
142
141
|
this.token = params.token;
|
|
143
|
-
if (
|
|
142
|
+
if ("apiKey" in params && params.apiKey)
|
|
143
|
+
this.apiKey = params.apiKey;
|
|
144
|
+
if (!(this.token || this.apiKey)) {
|
|
144
145
|
throw new Error("API key or temporary token is required.");
|
|
145
146
|
}
|
|
146
147
|
}
|
|
@@ -157,6 +158,9 @@ class RealtimeService {
|
|
|
157
158
|
if (this.wordBoost && this.wordBoost.length > 0) {
|
|
158
159
|
searchParams.set("word_boost", JSON.stringify(this.wordBoost));
|
|
159
160
|
}
|
|
161
|
+
if (this.encoding) {
|
|
162
|
+
searchParams.set("encoding", this.encoding);
|
|
163
|
+
}
|
|
160
164
|
url.search = searchParams.toString();
|
|
161
165
|
return url;
|
|
162
166
|
}
|
|
@@ -285,12 +289,11 @@ class RealtimeServiceFactory extends BaseService {
|
|
|
285
289
|
this.rtFactoryParams = params;
|
|
286
290
|
}
|
|
287
291
|
createService(params) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
params.apiKey = this.rtFactoryParams.apiKey;
|
|
292
|
+
const serviceParams = { ...params };
|
|
293
|
+
if (!serviceParams.token && !serviceParams.apiKey) {
|
|
294
|
+
serviceParams.apiKey = this.rtFactoryParams.apiKey;
|
|
292
295
|
}
|
|
293
|
-
return new RealtimeService(
|
|
296
|
+
return new RealtimeService(serviceParams);
|
|
294
297
|
}
|
|
295
298
|
async createTemporaryToken(params) {
|
|
296
299
|
const data = await this.fetchJson("/v2/realtime/token", {
|
package/dist/deno.mjs
CHANGED
|
@@ -136,11 +136,12 @@ class RealtimeService {
|
|
|
136
136
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
137
137
|
this.sampleRate = params.sampleRate ?? 16000;
|
|
138
138
|
this.wordBoost = params.wordBoost;
|
|
139
|
-
|
|
140
|
-
this.apiKey = params.apiKey;
|
|
139
|
+
this.encoding = params.encoding;
|
|
141
140
|
if ("token" in params && params.token)
|
|
142
141
|
this.token = params.token;
|
|
143
|
-
if (
|
|
142
|
+
if ("apiKey" in params && params.apiKey)
|
|
143
|
+
this.apiKey = params.apiKey;
|
|
144
|
+
if (!(this.token || this.apiKey)) {
|
|
144
145
|
throw new Error("API key or temporary token is required.");
|
|
145
146
|
}
|
|
146
147
|
}
|
|
@@ -157,6 +158,9 @@ class RealtimeService {
|
|
|
157
158
|
if (this.wordBoost && this.wordBoost.length > 0) {
|
|
158
159
|
searchParams.set("word_boost", JSON.stringify(this.wordBoost));
|
|
159
160
|
}
|
|
161
|
+
if (this.encoding) {
|
|
162
|
+
searchParams.set("encoding", this.encoding);
|
|
163
|
+
}
|
|
160
164
|
url.search = searchParams.toString();
|
|
161
165
|
return url;
|
|
162
166
|
}
|
|
@@ -285,12 +289,11 @@ class RealtimeServiceFactory extends BaseService {
|
|
|
285
289
|
this.rtFactoryParams = params;
|
|
286
290
|
}
|
|
287
291
|
createService(params) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
params.apiKey = this.rtFactoryParams.apiKey;
|
|
292
|
+
const serviceParams = { ...params };
|
|
293
|
+
if (!serviceParams.token && !serviceParams.apiKey) {
|
|
294
|
+
serviceParams.apiKey = this.rtFactoryParams.apiKey;
|
|
292
295
|
}
|
|
293
|
-
return new RealtimeService(
|
|
296
|
+
return new RealtimeService(serviceParams);
|
|
294
297
|
}
|
|
295
298
|
async createTemporaryToken(params) {
|
|
296
299
|
const data = await this.fetchJson("/v2/realtime/token", {
|
package/dist/index.cjs
CHANGED
|
@@ -184,11 +184,12 @@ class RealtimeService {
|
|
|
184
184
|
this.realtimeUrl = (_a = params.realtimeUrl) !== null && _a !== void 0 ? _a : defaultRealtimeUrl;
|
|
185
185
|
this.sampleRate = (_b = params.sampleRate) !== null && _b !== void 0 ? _b : 16000;
|
|
186
186
|
this.wordBoost = params.wordBoost;
|
|
187
|
-
|
|
188
|
-
this.apiKey = params.apiKey;
|
|
187
|
+
this.encoding = params.encoding;
|
|
189
188
|
if ("token" in params && params.token)
|
|
190
189
|
this.token = params.token;
|
|
191
|
-
if (
|
|
190
|
+
if ("apiKey" in params && params.apiKey)
|
|
191
|
+
this.apiKey = params.apiKey;
|
|
192
|
+
if (!(this.token || this.apiKey)) {
|
|
192
193
|
throw new Error("API key or temporary token is required.");
|
|
193
194
|
}
|
|
194
195
|
}
|
|
@@ -205,6 +206,9 @@ class RealtimeService {
|
|
|
205
206
|
if (this.wordBoost && this.wordBoost.length > 0) {
|
|
206
207
|
searchParams.set("word_boost", JSON.stringify(this.wordBoost));
|
|
207
208
|
}
|
|
209
|
+
if (this.encoding) {
|
|
210
|
+
searchParams.set("encoding", this.encoding);
|
|
211
|
+
}
|
|
208
212
|
url.search = searchParams.toString();
|
|
209
213
|
return url;
|
|
210
214
|
}
|
|
@@ -338,12 +342,11 @@ class RealtimeServiceFactory extends BaseService {
|
|
|
338
342
|
this.rtFactoryParams = params;
|
|
339
343
|
}
|
|
340
344
|
createService(params) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
params.apiKey = this.rtFactoryParams.apiKey;
|
|
345
|
+
const serviceParams = Object.assign({}, params);
|
|
346
|
+
if (!serviceParams.token && !serviceParams.apiKey) {
|
|
347
|
+
serviceParams.apiKey = this.rtFactoryParams.apiKey;
|
|
345
348
|
}
|
|
346
|
-
return new RealtimeService(
|
|
349
|
+
return new RealtimeService(serviceParams);
|
|
347
350
|
}
|
|
348
351
|
createTemporaryToken(params) {
|
|
349
352
|
return __awaiter(this, void 0, void 0, function* () {
|
package/dist/index.mjs
CHANGED
|
@@ -182,11 +182,12 @@ class RealtimeService {
|
|
|
182
182
|
this.realtimeUrl = (_a = params.realtimeUrl) !== null && _a !== void 0 ? _a : defaultRealtimeUrl;
|
|
183
183
|
this.sampleRate = (_b = params.sampleRate) !== null && _b !== void 0 ? _b : 16000;
|
|
184
184
|
this.wordBoost = params.wordBoost;
|
|
185
|
-
|
|
186
|
-
this.apiKey = params.apiKey;
|
|
185
|
+
this.encoding = params.encoding;
|
|
187
186
|
if ("token" in params && params.token)
|
|
188
187
|
this.token = params.token;
|
|
189
|
-
if (
|
|
188
|
+
if ("apiKey" in params && params.apiKey)
|
|
189
|
+
this.apiKey = params.apiKey;
|
|
190
|
+
if (!(this.token || this.apiKey)) {
|
|
190
191
|
throw new Error("API key or temporary token is required.");
|
|
191
192
|
}
|
|
192
193
|
}
|
|
@@ -203,6 +204,9 @@ class RealtimeService {
|
|
|
203
204
|
if (this.wordBoost && this.wordBoost.length > 0) {
|
|
204
205
|
searchParams.set("word_boost", JSON.stringify(this.wordBoost));
|
|
205
206
|
}
|
|
207
|
+
if (this.encoding) {
|
|
208
|
+
searchParams.set("encoding", this.encoding);
|
|
209
|
+
}
|
|
206
210
|
url.search = searchParams.toString();
|
|
207
211
|
return url;
|
|
208
212
|
}
|
|
@@ -336,12 +340,11 @@ class RealtimeServiceFactory extends BaseService {
|
|
|
336
340
|
this.rtFactoryParams = params;
|
|
337
341
|
}
|
|
338
342
|
createService(params) {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
params.apiKey = this.rtFactoryParams.apiKey;
|
|
343
|
+
const serviceParams = Object.assign({}, params);
|
|
344
|
+
if (!serviceParams.token && !serviceParams.apiKey) {
|
|
345
|
+
serviceParams.apiKey = this.rtFactoryParams.apiKey;
|
|
343
346
|
}
|
|
344
|
-
return new RealtimeService(
|
|
347
|
+
return new RealtimeService(serviceParams);
|
|
345
348
|
}
|
|
346
349
|
createTemporaryToken(params) {
|
|
347
350
|
return __awaiter(this, void 0, void 0, function* () {
|
package/dist/node.cjs
CHANGED
|
@@ -135,11 +135,12 @@ class RealtimeService {
|
|
|
135
135
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
136
136
|
this.sampleRate = params.sampleRate ?? 16000;
|
|
137
137
|
this.wordBoost = params.wordBoost;
|
|
138
|
-
|
|
139
|
-
this.apiKey = params.apiKey;
|
|
138
|
+
this.encoding = params.encoding;
|
|
140
139
|
if ("token" in params && params.token)
|
|
141
140
|
this.token = params.token;
|
|
142
|
-
if (
|
|
141
|
+
if ("apiKey" in params && params.apiKey)
|
|
142
|
+
this.apiKey = params.apiKey;
|
|
143
|
+
if (!(this.token || this.apiKey)) {
|
|
143
144
|
throw new Error("API key or temporary token is required.");
|
|
144
145
|
}
|
|
145
146
|
}
|
|
@@ -156,6 +157,9 @@ class RealtimeService {
|
|
|
156
157
|
if (this.wordBoost && this.wordBoost.length > 0) {
|
|
157
158
|
searchParams.set("word_boost", JSON.stringify(this.wordBoost));
|
|
158
159
|
}
|
|
160
|
+
if (this.encoding) {
|
|
161
|
+
searchParams.set("encoding", this.encoding);
|
|
162
|
+
}
|
|
159
163
|
url.search = searchParams.toString();
|
|
160
164
|
return url;
|
|
161
165
|
}
|
|
@@ -284,12 +288,11 @@ class RealtimeServiceFactory extends BaseService {
|
|
|
284
288
|
this.rtFactoryParams = params;
|
|
285
289
|
}
|
|
286
290
|
createService(params) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
params.apiKey = this.rtFactoryParams.apiKey;
|
|
291
|
+
const serviceParams = { ...params };
|
|
292
|
+
if (!serviceParams.token && !serviceParams.apiKey) {
|
|
293
|
+
serviceParams.apiKey = this.rtFactoryParams.apiKey;
|
|
291
294
|
}
|
|
292
|
-
return new RealtimeService(
|
|
295
|
+
return new RealtimeService(serviceParams);
|
|
293
296
|
}
|
|
294
297
|
async createTemporaryToken(params) {
|
|
295
298
|
const data = await this.fetchJson("/v2/realtime/token", {
|
package/dist/node.mjs
CHANGED
|
@@ -133,11 +133,12 @@ class RealtimeService {
|
|
|
133
133
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
134
134
|
this.sampleRate = params.sampleRate ?? 16000;
|
|
135
135
|
this.wordBoost = params.wordBoost;
|
|
136
|
-
|
|
137
|
-
this.apiKey = params.apiKey;
|
|
136
|
+
this.encoding = params.encoding;
|
|
138
137
|
if ("token" in params && params.token)
|
|
139
138
|
this.token = params.token;
|
|
140
|
-
if (
|
|
139
|
+
if ("apiKey" in params && params.apiKey)
|
|
140
|
+
this.apiKey = params.apiKey;
|
|
141
|
+
if (!(this.token || this.apiKey)) {
|
|
141
142
|
throw new Error("API key or temporary token is required.");
|
|
142
143
|
}
|
|
143
144
|
}
|
|
@@ -154,6 +155,9 @@ class RealtimeService {
|
|
|
154
155
|
if (this.wordBoost && this.wordBoost.length > 0) {
|
|
155
156
|
searchParams.set("word_boost", JSON.stringify(this.wordBoost));
|
|
156
157
|
}
|
|
158
|
+
if (this.encoding) {
|
|
159
|
+
searchParams.set("encoding", this.encoding);
|
|
160
|
+
}
|
|
157
161
|
url.search = searchParams.toString();
|
|
158
162
|
return url;
|
|
159
163
|
}
|
|
@@ -282,12 +286,11 @@ class RealtimeServiceFactory extends BaseService {
|
|
|
282
286
|
this.rtFactoryParams = params;
|
|
283
287
|
}
|
|
284
288
|
createService(params) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
params.apiKey = this.rtFactoryParams.apiKey;
|
|
289
|
+
const serviceParams = { ...params };
|
|
290
|
+
if (!serviceParams.token && !serviceParams.apiKey) {
|
|
291
|
+
serviceParams.apiKey = this.rtFactoryParams.apiKey;
|
|
289
292
|
}
|
|
290
|
-
return new RealtimeService(
|
|
293
|
+
return new RealtimeService(serviceParams);
|
|
291
294
|
}
|
|
292
295
|
async createTemporaryToken(params) {
|
|
293
296
|
const data = await this.fetchJson("/v2/realtime/token", {
|
|
@@ -2,6 +2,12 @@ export type AudioData = {
|
|
|
2
2
|
/** @description Base64 encoded raw audio data */
|
|
3
3
|
audio_data: string;
|
|
4
4
|
};
|
|
5
|
+
/**
|
|
6
|
+
* @description The encoding of the audio data
|
|
7
|
+
* @default pcm_s16le
|
|
8
|
+
* @enum {string}
|
|
9
|
+
*/
|
|
10
|
+
export type AudioEncoding = "pcm_s16le" | "pcm_mulaw";
|
|
5
11
|
export type FinalTranscript = RealtimeBaseTranscript & {
|
|
6
12
|
/**
|
|
7
13
|
* @description Describes the type of message
|
|
@@ -61,7 +67,10 @@ export type SessionBegins = RealtimeBaseMessage & {
|
|
|
61
67
|
* @constant
|
|
62
68
|
*/
|
|
63
69
|
message_type: "SessionBegins";
|
|
64
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Format: uuid
|
|
72
|
+
* @description Unique identifier for the established session
|
|
73
|
+
*/
|
|
65
74
|
session_id: string;
|
|
66
75
|
};
|
|
67
76
|
export type SessionTerminated = RealtimeBaseMessage & {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type LiteralUnion<LiteralType, BaseType> = LiteralType | (BaseType & Record<never, never>);
|