assemblyai 4.2.0 → 4.2.2

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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.2.2] - 2024-01-29
4
+
5
+ ### Changed
6
+
7
+ - Windows paths passed to `client.transcripts.transcribe` and `client.transcripts.submit` will work as expected.
8
+
9
+ ## [4.2.1] - 2024-01-23
10
+
11
+ ### Added
12
+
13
+ - Add `answer_format` to `LemurActionItemsParams` type
14
+
15
+ ### Changed
16
+
17
+ - Rename `RealtimeService` to `RealtimeTranscriber`, `RealtimeServiceFactory` to `RealtimeTranscriberFactory`, `RealtimeTranscriberFactory.createService()` to `RealtimeTranscriberFactory.transcriber()`. Deprecated aliases are provided for all old types and functions for backwards compatibility.
18
+ - Restrict the type for `redact_pii_audio_quality` from `string` to `RedactPiiAudioQuality` an enum string.
19
+
3
20
  ## [4.2.0] - 2024-01-11
4
21
 
5
22
  ### Added
package/README.md CHANGED
@@ -184,18 +184,18 @@ const { response } = await client.lemur.task({
184
184
  });
185
185
  ```
186
186
 
187
- ## Transcribe in real time
187
+ ## Transcribe in real-time
188
188
 
189
- Create the real-time service.
189
+ Create the real-time transcriber.
190
190
 
191
191
  ```typescript
192
- const rt = client.realtime.createService();
192
+ const rt = client.realtime.transcriber();
193
193
  ```
194
194
 
195
195
  You can also pass in the following options.
196
196
 
197
197
  ```typescript
198
- const rt = client.realtime.createService({
198
+ const rt = client.realtime.transcriber({
199
199
  realtimeUrl: 'wss://localhost/override',
200
200
  apiKey: process.env.ASSEMBLYAI_API_KEY // The API key passed to `AssemblyAI` will be used by default,
201
201
  sampleRate: 16_000,
@@ -207,7 +207,7 @@ You can also generate a temporary auth token for real-time.
207
207
 
208
208
  ```typescript
209
209
  const token = await client.realtime.createTemporaryToken({ expires_in = 60 });
210
- const rt = client.realtime.createService({
210
+ const rt = client.realtime.transcriber({
211
211
  token: token,
212
212
  });
213
213
  ```
@@ -195,7 +195,7 @@
195
195
  }
196
196
 
197
197
  const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
198
- class RealtimeService {
198
+ class RealtimeTranscriber {
199
199
  constructor(params) {
200
200
  var _a, _b;
201
201
  this.listeners = {};
@@ -342,18 +342,29 @@
342
342
  });
343
343
  }
344
344
  }
345
+ /**
346
+ * @deprecated Use RealtimeTranscriber instead
347
+ */
348
+ class RealtimeService extends RealtimeTranscriber {
349
+ }
345
350
 
346
- class RealtimeServiceFactory extends BaseService {
351
+ class RealtimeTranscriberFactory extends BaseService {
347
352
  constructor(params) {
348
353
  super(params);
349
354
  this.rtFactoryParams = params;
350
355
  }
356
+ /**
357
+ * @deprecated Use transcriber(...) instead
358
+ */
351
359
  createService(params) {
360
+ return this.transcriber(params);
361
+ }
362
+ transcriber(params) {
352
363
  const serviceParams = Object.assign({}, params);
353
364
  if (!serviceParams.token && !serviceParams.apiKey) {
354
365
  serviceParams.apiKey = this.rtFactoryParams.apiKey;
355
366
  }
356
- return new RealtimeService(serviceParams);
367
+ return new RealtimeTranscriber(serviceParams);
357
368
  }
358
369
  createTemporaryToken(params) {
359
370
  return __awaiter(this, void 0, void 0, function* () {
@@ -365,6 +376,23 @@
365
376
  });
366
377
  }
367
378
  }
379
+ /**
380
+ * @deprecated Use RealtimeTranscriberFactory instead
381
+ */
382
+ class RealtimeServiceFactory extends RealtimeTranscriberFactory {
383
+ }
384
+
385
+ function getPath(path) {
386
+ if (path.startsWith("http"))
387
+ return null;
388
+ if (path.startsWith("https"))
389
+ return null;
390
+ if (path.startsWith("file://"))
391
+ return path.substring(7);
392
+ if (path.startsWith("file:"))
393
+ return path.substring(5);
394
+ return path;
395
+ }
368
396
 
369
397
  class TranscriptService extends BaseService {
370
398
  constructor(params, files) {
@@ -567,19 +595,6 @@
567
595
  return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
568
596
  }
569
597
  }
570
- function getPath(path) {
571
- let url;
572
- try {
573
- url = new URL(path);
574
- if (url.protocol === "file:")
575
- return url.pathname;
576
- else
577
- return null;
578
- }
579
- catch (_a) {
580
- return path;
581
- }
582
- }
583
598
 
584
599
  const readFile = function (
585
600
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -628,7 +643,7 @@
628
643
  this.files = new FileService(params);
629
644
  this.transcripts = new TranscriptService(params, this.files);
630
645
  this.lemur = new LemurService(params);
631
- this.realtime = new RealtimeServiceFactory(params);
646
+ this.realtime = new RealtimeTranscriberFactory(params);
632
647
  }
633
648
  }
634
649
 
@@ -637,6 +652,8 @@
637
652
  exports.LemurService = LemurService;
638
653
  exports.RealtimeService = RealtimeService;
639
654
  exports.RealtimeServiceFactory = RealtimeServiceFactory;
655
+ exports.RealtimeTranscriber = RealtimeTranscriber;
656
+ exports.RealtimeTranscriberFactory = RealtimeTranscriberFactory;
640
657
  exports.TranscriptService = TranscriptService;
641
658
 
642
659
  }));
@@ -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(o,n){function r(e){try{c(i.next(e))}catch(e){n(e)}}function a(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?o(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:o}="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.binaryType="arraybuffer",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,o;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(o=(i=this.listeners).error)||void 0===o||o.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,o,n,r,a,c,d,u,h,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===(n=(o=this.listeners).open)||void 0===n||n.call(o,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");this.socket.send(e)}stream(){return new o({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 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 o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(s[i[o]]=e[i[o]])}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 o=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(o.id,s):o}))}waitUntilReady(e,s){var i,o;return t(this,void 0,void 0,(function*(){const t=null!==(i=null==s?void 0:s.pollingInterval)&&void 0!==i?i:3e3,n=null!==(o=null==s?void 0:s.pollingTimeout)&&void 0!==o?o:-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",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 o=yield this.fetch(t);return yield o.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 i(e),this.realtime=new u(e)}},e.FileService=p,e.LemurService=i,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,i){return new(s||(s=Promise))((function(o,n){function r(e){try{c(i.next(e))}catch(e){n(e)}}function a(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?o(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:o}="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.binaryType="arraybuffer",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,o;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(o=(i=this.listeners).error)||void 0===o||o.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,o,n,r,a,c,d,u,h,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===(n=(o=this.listeners).open)||void 0===n||n.call(o,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");this.socket.send(e)}stream(){return new o({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 this.transcriber(e)}transcriber(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}))}}function h(e){return e.startsWith("http")||e.startsWith("https")?null:e.startsWith("file://")?e.substring(7):e.startsWith("file:")?e.substring(5):e}class f 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 o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(s[i[o]]=e[i[o]])}return s}(e,["audio"]);let i;if("string"==typeof t){const e=h(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=h(e.audio_url);if(null!==t){const s=yield this.files.upload(t);e.audio_url=s}const o=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(o.id,s):o}))}waitUntilReady(e,s){var i,o;return t(this,void 0,void 0,(function*(){const t=null!==(i=null==s?void 0:s.pollingInterval)&&void 0!==i?i:3e3,n=null!==(o=null==s?void 0:s.pollingTimeout)&&void 0!==o?o:-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",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 o=yield this.fetch(t);return yield o.text()}))}redactions(e){return this.fetchJson(`/v2/transcript/${e}/redacted-audio`)}}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 f(e,this.files),this.lemur=new i(e),this.realtime=new u(e)}},e.FileService=p,e.LemurService=i,e.RealtimeService=class extends d{},e.RealtimeServiceFactory=class extends u{},e.RealtimeTranscriber=d,e.RealtimeTranscriberFactory=u,e.TranscriptService=f}));
package/dist/bun.mjs CHANGED
@@ -130,7 +130,7 @@ class RealtimeError extends Error {
130
130
  }
131
131
 
132
132
  const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
133
- class RealtimeService {
133
+ class RealtimeTranscriber {
134
134
  constructor(params) {
135
135
  this.listeners = {};
136
136
  this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
@@ -271,18 +271,29 @@ class RealtimeService {
271
271
  this.socket = undefined;
272
272
  }
273
273
  }
274
+ /**
275
+ * @deprecated Use RealtimeTranscriber instead
276
+ */
277
+ class RealtimeService extends RealtimeTranscriber {
278
+ }
274
279
 
275
- class RealtimeServiceFactory extends BaseService {
280
+ class RealtimeTranscriberFactory extends BaseService {
276
281
  constructor(params) {
277
282
  super(params);
278
283
  this.rtFactoryParams = params;
279
284
  }
285
+ /**
286
+ * @deprecated Use transcriber(...) instead
287
+ */
280
288
  createService(params) {
289
+ return this.transcriber(params);
290
+ }
291
+ transcriber(params) {
281
292
  const serviceParams = { ...params };
282
293
  if (!serviceParams.token && !serviceParams.apiKey) {
283
294
  serviceParams.apiKey = this.rtFactoryParams.apiKey;
284
295
  }
285
- return new RealtimeService(serviceParams);
296
+ return new RealtimeTranscriber(serviceParams);
286
297
  }
287
298
  async createTemporaryToken(params) {
288
299
  const data = await this.fetchJson("/v2/realtime/token", {
@@ -292,6 +303,23 @@ class RealtimeServiceFactory extends BaseService {
292
303
  return data.token;
293
304
  }
294
305
  }
306
+ /**
307
+ * @deprecated Use RealtimeTranscriberFactory instead
308
+ */
309
+ class RealtimeServiceFactory extends RealtimeTranscriberFactory {
310
+ }
311
+
312
+ function getPath(path) {
313
+ if (path.startsWith("http"))
314
+ return null;
315
+ if (path.startsWith("https"))
316
+ return null;
317
+ if (path.startsWith("file://"))
318
+ return path.substring(7);
319
+ if (path.startsWith("file:"))
320
+ return path.substring(5);
321
+ return path;
322
+ }
295
323
 
296
324
  class TranscriptService extends BaseService {
297
325
  constructor(params, files) {
@@ -477,19 +505,6 @@ class TranscriptService extends BaseService {
477
505
  return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
478
506
  }
479
507
  }
480
- function getPath(path) {
481
- let url;
482
- try {
483
- url = new URL(path);
484
- if (url.protocol === "file:")
485
- return url.pathname;
486
- else
487
- return null;
488
- }
489
- catch {
490
- return path;
491
- }
492
- }
493
508
 
494
509
  const readFile = async (path) => Bun.file(path).stream();
495
510
 
@@ -530,8 +545,8 @@ class AssemblyAI {
530
545
  this.files = new FileService(params);
531
546
  this.transcripts = new TranscriptService(params, this.files);
532
547
  this.lemur = new LemurService(params);
533
- this.realtime = new RealtimeServiceFactory(params);
548
+ this.realtime = new RealtimeTranscriberFactory(params);
534
549
  }
535
550
  }
536
551
 
537
- export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, TranscriptService };
552
+ export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, RealtimeTranscriber, RealtimeTranscriberFactory, TranscriptService };
package/dist/deno.mjs CHANGED
@@ -130,7 +130,7 @@ class RealtimeError extends Error {
130
130
  }
131
131
 
132
132
  const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
133
- class RealtimeService {
133
+ class RealtimeTranscriber {
134
134
  constructor(params) {
135
135
  this.listeners = {};
136
136
  this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
@@ -271,18 +271,29 @@ class RealtimeService {
271
271
  this.socket = undefined;
272
272
  }
273
273
  }
274
+ /**
275
+ * @deprecated Use RealtimeTranscriber instead
276
+ */
277
+ class RealtimeService extends RealtimeTranscriber {
278
+ }
274
279
 
275
- class RealtimeServiceFactory extends BaseService {
280
+ class RealtimeTranscriberFactory extends BaseService {
276
281
  constructor(params) {
277
282
  super(params);
278
283
  this.rtFactoryParams = params;
279
284
  }
285
+ /**
286
+ * @deprecated Use transcriber(...) instead
287
+ */
280
288
  createService(params) {
289
+ return this.transcriber(params);
290
+ }
291
+ transcriber(params) {
281
292
  const serviceParams = { ...params };
282
293
  if (!serviceParams.token && !serviceParams.apiKey) {
283
294
  serviceParams.apiKey = this.rtFactoryParams.apiKey;
284
295
  }
285
- return new RealtimeService(serviceParams);
296
+ return new RealtimeTranscriber(serviceParams);
286
297
  }
287
298
  async createTemporaryToken(params) {
288
299
  const data = await this.fetchJson("/v2/realtime/token", {
@@ -292,6 +303,23 @@ class RealtimeServiceFactory extends BaseService {
292
303
  return data.token;
293
304
  }
294
305
  }
306
+ /**
307
+ * @deprecated Use RealtimeTranscriberFactory instead
308
+ */
309
+ class RealtimeServiceFactory extends RealtimeTranscriberFactory {
310
+ }
311
+
312
+ function getPath(path) {
313
+ if (path.startsWith("http"))
314
+ return null;
315
+ if (path.startsWith("https"))
316
+ return null;
317
+ if (path.startsWith("file://"))
318
+ return path.substring(7);
319
+ if (path.startsWith("file:"))
320
+ return path.substring(5);
321
+ return path;
322
+ }
295
323
 
296
324
  class TranscriptService extends BaseService {
297
325
  constructor(params, files) {
@@ -477,19 +505,6 @@ class TranscriptService extends BaseService {
477
505
  return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
478
506
  }
479
507
  }
480
- function getPath(path) {
481
- let url;
482
- try {
483
- url = new URL(path);
484
- if (url.protocol === "file:")
485
- return url.pathname;
486
- else
487
- return null;
488
- }
489
- catch {
490
- return path;
491
- }
492
- }
493
508
 
494
509
  const readFile = async (path) => (await Deno.open(path)).readable;
495
510
 
@@ -530,8 +545,8 @@ class AssemblyAI {
530
545
  this.files = new FileService(params);
531
546
  this.transcripts = new TranscriptService(params, this.files);
532
547
  this.lemur = new LemurService(params);
533
- this.realtime = new RealtimeServiceFactory(params);
548
+ this.realtime = new RealtimeTranscriberFactory(params);
534
549
  }
535
550
  }
536
551
 
537
- export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, TranscriptService };
552
+ export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, RealtimeTranscriber, RealtimeTranscriberFactory, TranscriptService };
package/dist/index.cjs CHANGED
@@ -177,7 +177,7 @@ class RealtimeError extends Error {
177
177
  }
178
178
 
179
179
  const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
180
- class RealtimeService {
180
+ class RealtimeTranscriber {
181
181
  constructor(params) {
182
182
  var _a, _b;
183
183
  this.listeners = {};
@@ -324,18 +324,29 @@ class RealtimeService {
324
324
  });
325
325
  }
326
326
  }
327
+ /**
328
+ * @deprecated Use RealtimeTranscriber instead
329
+ */
330
+ class RealtimeService extends RealtimeTranscriber {
331
+ }
327
332
 
328
- class RealtimeServiceFactory extends BaseService {
333
+ class RealtimeTranscriberFactory extends BaseService {
329
334
  constructor(params) {
330
335
  super(params);
331
336
  this.rtFactoryParams = params;
332
337
  }
338
+ /**
339
+ * @deprecated Use transcriber(...) instead
340
+ */
333
341
  createService(params) {
342
+ return this.transcriber(params);
343
+ }
344
+ transcriber(params) {
334
345
  const serviceParams = Object.assign({}, params);
335
346
  if (!serviceParams.token && !serviceParams.apiKey) {
336
347
  serviceParams.apiKey = this.rtFactoryParams.apiKey;
337
348
  }
338
- return new RealtimeService(serviceParams);
349
+ return new RealtimeTranscriber(serviceParams);
339
350
  }
340
351
  createTemporaryToken(params) {
341
352
  return __awaiter(this, void 0, void 0, function* () {
@@ -347,6 +358,23 @@ class RealtimeServiceFactory extends BaseService {
347
358
  });
348
359
  }
349
360
  }
361
+ /**
362
+ * @deprecated Use RealtimeTranscriberFactory instead
363
+ */
364
+ class RealtimeServiceFactory extends RealtimeTranscriberFactory {
365
+ }
366
+
367
+ function getPath(path) {
368
+ if (path.startsWith("http"))
369
+ return null;
370
+ if (path.startsWith("https"))
371
+ return null;
372
+ if (path.startsWith("file://"))
373
+ return path.substring(7);
374
+ if (path.startsWith("file:"))
375
+ return path.substring(5);
376
+ return path;
377
+ }
350
378
 
351
379
  class TranscriptService extends BaseService {
352
380
  constructor(params, files) {
@@ -549,19 +577,6 @@ class TranscriptService extends BaseService {
549
577
  return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
550
578
  }
551
579
  }
552
- function getPath(path) {
553
- let url;
554
- try {
555
- url = new URL(path);
556
- if (url.protocol === "file:")
557
- return url.pathname;
558
- else
559
- return null;
560
- }
561
- catch (_a) {
562
- return path;
563
- }
564
- }
565
580
 
566
581
  const readFile = function (
567
582
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -610,7 +625,7 @@ class AssemblyAI {
610
625
  this.files = new FileService(params);
611
626
  this.transcripts = new TranscriptService(params, this.files);
612
627
  this.lemur = new LemurService(params);
613
- this.realtime = new RealtimeServiceFactory(params);
628
+ this.realtime = new RealtimeTranscriberFactory(params);
614
629
  }
615
630
  }
616
631
 
@@ -619,4 +634,6 @@ exports.FileService = FileService;
619
634
  exports.LemurService = LemurService;
620
635
  exports.RealtimeService = RealtimeService;
621
636
  exports.RealtimeServiceFactory = RealtimeServiceFactory;
637
+ exports.RealtimeTranscriber = RealtimeTranscriber;
638
+ exports.RealtimeTranscriberFactory = RealtimeTranscriberFactory;
622
639
  exports.TranscriptService = TranscriptService;
package/dist/index.mjs CHANGED
@@ -175,7 +175,7 @@ class RealtimeError extends Error {
175
175
  }
176
176
 
177
177
  const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
178
- class RealtimeService {
178
+ class RealtimeTranscriber {
179
179
  constructor(params) {
180
180
  var _a, _b;
181
181
  this.listeners = {};
@@ -322,18 +322,29 @@ class RealtimeService {
322
322
  });
323
323
  }
324
324
  }
325
+ /**
326
+ * @deprecated Use RealtimeTranscriber instead
327
+ */
328
+ class RealtimeService extends RealtimeTranscriber {
329
+ }
325
330
 
326
- class RealtimeServiceFactory extends BaseService {
331
+ class RealtimeTranscriberFactory extends BaseService {
327
332
  constructor(params) {
328
333
  super(params);
329
334
  this.rtFactoryParams = params;
330
335
  }
336
+ /**
337
+ * @deprecated Use transcriber(...) instead
338
+ */
331
339
  createService(params) {
340
+ return this.transcriber(params);
341
+ }
342
+ transcriber(params) {
332
343
  const serviceParams = Object.assign({}, params);
333
344
  if (!serviceParams.token && !serviceParams.apiKey) {
334
345
  serviceParams.apiKey = this.rtFactoryParams.apiKey;
335
346
  }
336
- return new RealtimeService(serviceParams);
347
+ return new RealtimeTranscriber(serviceParams);
337
348
  }
338
349
  createTemporaryToken(params) {
339
350
  return __awaiter(this, void 0, void 0, function* () {
@@ -345,6 +356,23 @@ class RealtimeServiceFactory extends BaseService {
345
356
  });
346
357
  }
347
358
  }
359
+ /**
360
+ * @deprecated Use RealtimeTranscriberFactory instead
361
+ */
362
+ class RealtimeServiceFactory extends RealtimeTranscriberFactory {
363
+ }
364
+
365
+ function getPath(path) {
366
+ if (path.startsWith("http"))
367
+ return null;
368
+ if (path.startsWith("https"))
369
+ return null;
370
+ if (path.startsWith("file://"))
371
+ return path.substring(7);
372
+ if (path.startsWith("file:"))
373
+ return path.substring(5);
374
+ return path;
375
+ }
348
376
 
349
377
  class TranscriptService extends BaseService {
350
378
  constructor(params, files) {
@@ -547,19 +575,6 @@ class TranscriptService extends BaseService {
547
575
  return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
548
576
  }
549
577
  }
550
- function getPath(path) {
551
- let url;
552
- try {
553
- url = new URL(path);
554
- if (url.protocol === "file:")
555
- return url.pathname;
556
- else
557
- return null;
558
- }
559
- catch (_a) {
560
- return path;
561
- }
562
- }
563
578
 
564
579
  const readFile = function (
565
580
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -608,8 +623,8 @@ class AssemblyAI {
608
623
  this.files = new FileService(params);
609
624
  this.transcripts = new TranscriptService(params, this.files);
610
625
  this.lemur = new LemurService(params);
611
- this.realtime = new RealtimeServiceFactory(params);
626
+ this.realtime = new RealtimeTranscriberFactory(params);
612
627
  }
613
628
  }
614
629
 
615
- export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, TranscriptService };
630
+ export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, RealtimeTranscriber, RealtimeTranscriberFactory, TranscriptService };