assemblyai 4.2.0-beta.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +5 -5
- package/dist/assemblyai.umd.js +22 -4
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/bun.mjs +21 -5
- package/dist/deno.mjs +21 -5
- package/dist/index.cjs +22 -4
- package/dist/index.mjs +21 -5
- package/dist/node.cjs +22 -4
- package/dist/node.mjs +21 -5
- package/dist/polyfills/streams/node.d.ts +1 -0
- package/dist/services/index.d.ts +3 -3
- package/dist/services/realtime/factory.d.ts +12 -3
- package/dist/services/realtime/service.d.ts +10 -5
- package/dist/types/asyncapi.generated.d.ts +5 -4
- package/dist/types/openapi.generated.d.ts +20 -4
- package/dist/types/realtime/index.d.ts +11 -3
- package/docs/compat.md +5 -5
- package/package.json +2 -2
- package/src/services/index.ts +10 -3
- package/src/services/realtime/factory.ts +18 -5
- package/src/services/realtime/service.ts +13 -7
- package/src/types/asyncapi.generated.ts +5 -4
- package/src/types/openapi.generated.ts +21 -4
- package/src/types/realtime/index.ts +14 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.2.1] - 2024-01-23
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Add `answer_format` to `LemurActionItemsParams` type
|
|
7
|
+
|
|
8
|
+
### Changed
|
|
9
|
+
- 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.
|
|
10
|
+
- Restrict the type for `redact_pii_audio_quality` from `string` to `RedactPiiAudioQuality` an enum string.
|
|
11
|
+
|
|
3
12
|
## [4.2.0] - 2024-01-11
|
|
4
13
|
|
|
5
14
|
### 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
|
|
187
|
+
## Transcribe in real-time
|
|
188
188
|
|
|
189
|
-
Create the real-time
|
|
189
|
+
Create the real-time transcriber.
|
|
190
190
|
|
|
191
191
|
```typescript
|
|
192
|
-
const rt = client.realtime.
|
|
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.
|
|
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.
|
|
210
|
+
const rt = client.realtime.transcriber({
|
|
211
211
|
token: token,
|
|
212
212
|
});
|
|
213
213
|
```
|
package/dist/assemblyai.umd.js
CHANGED
|
@@ -195,7 +195,7 @@
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
198
|
-
class
|
|
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
|
|
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
|
|
367
|
+
return new RealtimeTranscriber(serviceParams);
|
|
357
368
|
}
|
|
358
369
|
createTemporaryToken(params) {
|
|
359
370
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -365,6 +376,11 @@
|
|
|
365
376
|
});
|
|
366
377
|
}
|
|
367
378
|
}
|
|
379
|
+
/**
|
|
380
|
+
* @deprecated Use RealtimeTranscriberFactory instead
|
|
381
|
+
*/
|
|
382
|
+
class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
383
|
+
}
|
|
368
384
|
|
|
369
385
|
class TranscriptService extends BaseService {
|
|
370
386
|
constructor(params, files) {
|
|
@@ -628,7 +644,7 @@
|
|
|
628
644
|
this.files = new FileService(params);
|
|
629
645
|
this.transcripts = new TranscriptService(params, this.files);
|
|
630
646
|
this.lemur = new LemurService(params);
|
|
631
|
-
this.realtime = new
|
|
647
|
+
this.realtime = new RealtimeTranscriberFactory(params);
|
|
632
648
|
}
|
|
633
649
|
}
|
|
634
650
|
|
|
@@ -637,6 +653,8 @@
|
|
|
637
653
|
exports.LemurService = LemurService;
|
|
638
654
|
exports.RealtimeService = RealtimeService;
|
|
639
655
|
exports.RealtimeServiceFactory = RealtimeServiceFactory;
|
|
656
|
+
exports.RealtimeTranscriber = RealtimeTranscriber;
|
|
657
|
+
exports.RealtimeTranscriberFactory = RealtimeTranscriberFactory;
|
|
640
658
|
exports.TranscriptService = TranscriptService;
|
|
641
659
|
|
|
642
660
|
}));
|
|
@@ -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}))}}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=class extends d{},e.RealtimeServiceFactory=class extends u{},e.RealtimeTranscriber=d,e.RealtimeTranscriberFactory=u,e.TranscriptService=h}));
|
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
|
|
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
|
|
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
|
|
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,11 @@ 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
|
+
}
|
|
295
311
|
|
|
296
312
|
class TranscriptService extends BaseService {
|
|
297
313
|
constructor(params, files) {
|
|
@@ -530,8 +546,8 @@ class AssemblyAI {
|
|
|
530
546
|
this.files = new FileService(params);
|
|
531
547
|
this.transcripts = new TranscriptService(params, this.files);
|
|
532
548
|
this.lemur = new LemurService(params);
|
|
533
|
-
this.realtime = new
|
|
549
|
+
this.realtime = new RealtimeTranscriberFactory(params);
|
|
534
550
|
}
|
|
535
551
|
}
|
|
536
552
|
|
|
537
|
-
export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, TranscriptService };
|
|
553
|
+
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
|
|
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
|
|
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
|
|
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,11 @@ 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
|
+
}
|
|
295
311
|
|
|
296
312
|
class TranscriptService extends BaseService {
|
|
297
313
|
constructor(params, files) {
|
|
@@ -530,8 +546,8 @@ class AssemblyAI {
|
|
|
530
546
|
this.files = new FileService(params);
|
|
531
547
|
this.transcripts = new TranscriptService(params, this.files);
|
|
532
548
|
this.lemur = new LemurService(params);
|
|
533
|
-
this.realtime = new
|
|
549
|
+
this.realtime = new RealtimeTranscriberFactory(params);
|
|
534
550
|
}
|
|
535
551
|
}
|
|
536
552
|
|
|
537
|
-
export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, TranscriptService };
|
|
553
|
+
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
|
|
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
|
|
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
|
|
349
|
+
return new RealtimeTranscriber(serviceParams);
|
|
339
350
|
}
|
|
340
351
|
createTemporaryToken(params) {
|
|
341
352
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -347,6 +358,11 @@ class RealtimeServiceFactory extends BaseService {
|
|
|
347
358
|
});
|
|
348
359
|
}
|
|
349
360
|
}
|
|
361
|
+
/**
|
|
362
|
+
* @deprecated Use RealtimeTranscriberFactory instead
|
|
363
|
+
*/
|
|
364
|
+
class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
365
|
+
}
|
|
350
366
|
|
|
351
367
|
class TranscriptService extends BaseService {
|
|
352
368
|
constructor(params, files) {
|
|
@@ -610,7 +626,7 @@ class AssemblyAI {
|
|
|
610
626
|
this.files = new FileService(params);
|
|
611
627
|
this.transcripts = new TranscriptService(params, this.files);
|
|
612
628
|
this.lemur = new LemurService(params);
|
|
613
|
-
this.realtime = new
|
|
629
|
+
this.realtime = new RealtimeTranscriberFactory(params);
|
|
614
630
|
}
|
|
615
631
|
}
|
|
616
632
|
|
|
@@ -619,4 +635,6 @@ exports.FileService = FileService;
|
|
|
619
635
|
exports.LemurService = LemurService;
|
|
620
636
|
exports.RealtimeService = RealtimeService;
|
|
621
637
|
exports.RealtimeServiceFactory = RealtimeServiceFactory;
|
|
638
|
+
exports.RealtimeTranscriber = RealtimeTranscriber;
|
|
639
|
+
exports.RealtimeTranscriberFactory = RealtimeTranscriberFactory;
|
|
622
640
|
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
|
|
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
|
|
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
|
|
347
|
+
return new RealtimeTranscriber(serviceParams);
|
|
337
348
|
}
|
|
338
349
|
createTemporaryToken(params) {
|
|
339
350
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -345,6 +356,11 @@ class RealtimeServiceFactory extends BaseService {
|
|
|
345
356
|
});
|
|
346
357
|
}
|
|
347
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* @deprecated Use RealtimeTranscriberFactory instead
|
|
361
|
+
*/
|
|
362
|
+
class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
363
|
+
}
|
|
348
364
|
|
|
349
365
|
class TranscriptService extends BaseService {
|
|
350
366
|
constructor(params, files) {
|
|
@@ -608,8 +624,8 @@ class AssemblyAI {
|
|
|
608
624
|
this.files = new FileService(params);
|
|
609
625
|
this.transcripts = new TranscriptService(params, this.files);
|
|
610
626
|
this.lemur = new LemurService(params);
|
|
611
|
-
this.realtime = new
|
|
627
|
+
this.realtime = new RealtimeTranscriberFactory(params);
|
|
612
628
|
}
|
|
613
629
|
}
|
|
614
630
|
|
|
615
|
-
export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, TranscriptService };
|
|
631
|
+
export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, RealtimeTranscriber, RealtimeTranscriberFactory, TranscriptService };
|
package/dist/node.cjs
CHANGED
|
@@ -129,7 +129,7 @@ class RealtimeError extends Error {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
132
|
-
class
|
|
132
|
+
class RealtimeTranscriber {
|
|
133
133
|
constructor(params) {
|
|
134
134
|
this.listeners = {};
|
|
135
135
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
@@ -270,18 +270,29 @@ class RealtimeService {
|
|
|
270
270
|
this.socket = undefined;
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* @deprecated Use RealtimeTranscriber instead
|
|
275
|
+
*/
|
|
276
|
+
class RealtimeService extends RealtimeTranscriber {
|
|
277
|
+
}
|
|
273
278
|
|
|
274
|
-
class
|
|
279
|
+
class RealtimeTranscriberFactory extends BaseService {
|
|
275
280
|
constructor(params) {
|
|
276
281
|
super(params);
|
|
277
282
|
this.rtFactoryParams = params;
|
|
278
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* @deprecated Use transcriber(...) instead
|
|
286
|
+
*/
|
|
279
287
|
createService(params) {
|
|
288
|
+
return this.transcriber(params);
|
|
289
|
+
}
|
|
290
|
+
transcriber(params) {
|
|
280
291
|
const serviceParams = { ...params };
|
|
281
292
|
if (!serviceParams.token && !serviceParams.apiKey) {
|
|
282
293
|
serviceParams.apiKey = this.rtFactoryParams.apiKey;
|
|
283
294
|
}
|
|
284
|
-
return new
|
|
295
|
+
return new RealtimeTranscriber(serviceParams);
|
|
285
296
|
}
|
|
286
297
|
async createTemporaryToken(params) {
|
|
287
298
|
const data = await this.fetchJson("/v2/realtime/token", {
|
|
@@ -291,6 +302,11 @@ class RealtimeServiceFactory extends BaseService {
|
|
|
291
302
|
return data.token;
|
|
292
303
|
}
|
|
293
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* @deprecated Use RealtimeTranscriberFactory instead
|
|
307
|
+
*/
|
|
308
|
+
class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
309
|
+
}
|
|
294
310
|
|
|
295
311
|
class TranscriptService extends BaseService {
|
|
296
312
|
constructor(params, files) {
|
|
@@ -529,7 +545,7 @@ class AssemblyAI {
|
|
|
529
545
|
this.files = new FileService(params);
|
|
530
546
|
this.transcripts = new TranscriptService(params, this.files);
|
|
531
547
|
this.lemur = new LemurService(params);
|
|
532
|
-
this.realtime = new
|
|
548
|
+
this.realtime = new RealtimeTranscriberFactory(params);
|
|
533
549
|
}
|
|
534
550
|
}
|
|
535
551
|
|
|
@@ -538,4 +554,6 @@ exports.FileService = FileService;
|
|
|
538
554
|
exports.LemurService = LemurService;
|
|
539
555
|
exports.RealtimeService = RealtimeService;
|
|
540
556
|
exports.RealtimeServiceFactory = RealtimeServiceFactory;
|
|
557
|
+
exports.RealtimeTranscriber = RealtimeTranscriber;
|
|
558
|
+
exports.RealtimeTranscriberFactory = RealtimeTranscriberFactory;
|
|
541
559
|
exports.TranscriptService = TranscriptService;
|
package/dist/node.mjs
CHANGED
|
@@ -127,7 +127,7 @@ class RealtimeError extends Error {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
130
|
-
class
|
|
130
|
+
class RealtimeTranscriber {
|
|
131
131
|
constructor(params) {
|
|
132
132
|
this.listeners = {};
|
|
133
133
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
@@ -268,18 +268,29 @@ class RealtimeService {
|
|
|
268
268
|
this.socket = undefined;
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* @deprecated Use RealtimeTranscriber instead
|
|
273
|
+
*/
|
|
274
|
+
class RealtimeService extends RealtimeTranscriber {
|
|
275
|
+
}
|
|
271
276
|
|
|
272
|
-
class
|
|
277
|
+
class RealtimeTranscriberFactory extends BaseService {
|
|
273
278
|
constructor(params) {
|
|
274
279
|
super(params);
|
|
275
280
|
this.rtFactoryParams = params;
|
|
276
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* @deprecated Use transcriber(...) instead
|
|
284
|
+
*/
|
|
277
285
|
createService(params) {
|
|
286
|
+
return this.transcriber(params);
|
|
287
|
+
}
|
|
288
|
+
transcriber(params) {
|
|
278
289
|
const serviceParams = { ...params };
|
|
279
290
|
if (!serviceParams.token && !serviceParams.apiKey) {
|
|
280
291
|
serviceParams.apiKey = this.rtFactoryParams.apiKey;
|
|
281
292
|
}
|
|
282
|
-
return new
|
|
293
|
+
return new RealtimeTranscriber(serviceParams);
|
|
283
294
|
}
|
|
284
295
|
async createTemporaryToken(params) {
|
|
285
296
|
const data = await this.fetchJson("/v2/realtime/token", {
|
|
@@ -289,6 +300,11 @@ class RealtimeServiceFactory extends BaseService {
|
|
|
289
300
|
return data.token;
|
|
290
301
|
}
|
|
291
302
|
}
|
|
303
|
+
/**
|
|
304
|
+
* @deprecated Use RealtimeTranscriberFactory instead
|
|
305
|
+
*/
|
|
306
|
+
class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
307
|
+
}
|
|
292
308
|
|
|
293
309
|
class TranscriptService extends BaseService {
|
|
294
310
|
constructor(params, files) {
|
|
@@ -527,8 +543,8 @@ class AssemblyAI {
|
|
|
527
543
|
this.files = new FileService(params);
|
|
528
544
|
this.transcripts = new TranscriptService(params, this.files);
|
|
529
545
|
this.lemur = new LemurService(params);
|
|
530
|
-
this.realtime = new
|
|
546
|
+
this.realtime = new RealtimeTranscriberFactory(params);
|
|
531
547
|
}
|
|
532
548
|
}
|
|
533
549
|
|
|
534
|
-
export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, TranscriptService };
|
|
550
|
+
export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, RealtimeTranscriber, RealtimeTranscriberFactory, TranscriptService };
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseServiceParams } from "..";
|
|
2
2
|
import { LemurService } from "./lemur";
|
|
3
|
-
import { RealtimeService, RealtimeServiceFactory } from "./realtime";
|
|
3
|
+
import { RealtimeTranscriber, RealtimeTranscriberFactory, RealtimeService, RealtimeServiceFactory } from "./realtime";
|
|
4
4
|
import { TranscriptService } from "./transcripts";
|
|
5
5
|
import { FileService } from "./files";
|
|
6
6
|
declare class AssemblyAI {
|
|
@@ -19,11 +19,11 @@ declare class AssemblyAI {
|
|
|
19
19
|
/**
|
|
20
20
|
* The realtime service.
|
|
21
21
|
*/
|
|
22
|
-
realtime:
|
|
22
|
+
realtime: RealtimeTranscriberFactory;
|
|
23
23
|
/**
|
|
24
24
|
* Create a new AssemblyAI client.
|
|
25
25
|
* @param params The parameters for the service, including the API key and base URL, if any.
|
|
26
26
|
*/
|
|
27
27
|
constructor(params: BaseServiceParams);
|
|
28
28
|
}
|
|
29
|
-
export { AssemblyAI, LemurService, RealtimeServiceFactory, RealtimeService, TranscriptService, FileService, };
|
|
29
|
+
export { AssemblyAI, LemurService, RealtimeTranscriberFactory, RealtimeTranscriber, RealtimeServiceFactory, RealtimeService, TranscriptService, FileService, };
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import { BaseServiceParams, RealtimeTokenParams, CreateRealtimeServiceParams } from "../..";
|
|
2
|
-
import { RealtimeService } from "./service";
|
|
1
|
+
import { BaseServiceParams, RealtimeTokenParams, CreateRealtimeTranscriberParams, CreateRealtimeServiceParams } from "../..";
|
|
2
|
+
import { RealtimeService, RealtimeTranscriber } from "./service";
|
|
3
3
|
import { BaseService } from "../base";
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class RealtimeTranscriberFactory extends BaseService {
|
|
5
5
|
private rtFactoryParams;
|
|
6
6
|
constructor(params: BaseServiceParams);
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use transcriber(...) instead
|
|
9
|
+
*/
|
|
7
10
|
createService(params?: CreateRealtimeServiceParams): RealtimeService;
|
|
11
|
+
transcriber(params?: CreateRealtimeTranscriberParams): RealtimeTranscriber;
|
|
8
12
|
createTemporaryToken(params: RealtimeTokenParams): Promise<string>;
|
|
9
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use RealtimeTranscriberFactory instead
|
|
16
|
+
*/
|
|
17
|
+
export declare class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
18
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class
|
|
1
|
+
import { RealtimeTranscriberParams, RealtimeTranscript, PartialTranscript, FinalTranscript, SessionBeginsEventData, AudioData } from "../..";
|
|
2
|
+
export declare class RealtimeTranscriber {
|
|
3
3
|
private realtimeUrl;
|
|
4
4
|
private sampleRate;
|
|
5
5
|
private wordBoost?;
|
|
@@ -9,7 +9,7 @@ export declare class RealtimeService {
|
|
|
9
9
|
private socket?;
|
|
10
10
|
private listeners;
|
|
11
11
|
private sessionTerminatedResolve?;
|
|
12
|
-
constructor(params:
|
|
12
|
+
constructor(params: RealtimeTranscriberParams);
|
|
13
13
|
private connectionUrl;
|
|
14
14
|
on(event: "open", listener: (event: SessionBeginsEventData) => void): void;
|
|
15
15
|
on(event: "transcript", listener: (transcript: RealtimeTranscript) => void): void;
|
|
@@ -18,7 +18,12 @@ export declare class RealtimeService {
|
|
|
18
18
|
on(event: "error", listener: (error: Error) => void): void;
|
|
19
19
|
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
20
20
|
connect(): Promise<SessionBeginsEventData>;
|
|
21
|
-
sendAudio(audio:
|
|
22
|
-
stream(): WritableStream<
|
|
21
|
+
sendAudio(audio: AudioData): void;
|
|
22
|
+
stream(): WritableStream<AudioData>;
|
|
23
23
|
close(waitForSessionTermination?: boolean): Promise<void>;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Use RealtimeTranscriber instead
|
|
27
|
+
*/
|
|
28
|
+
export declare class RealtimeService extends RealtimeTranscriber {
|
|
29
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Format: binary
|
|
3
|
+
* @description Binary audio data
|
|
4
|
+
*/
|
|
5
|
+
export type AudioData = ArrayBufferLike;
|
|
5
6
|
/**
|
|
6
7
|
* @description The encoding of the audio data
|
|
7
8
|
* @default pcm_s16le
|
|
@@ -425,12 +425,21 @@ export type Error = {
|
|
|
425
425
|
* "64nygnr62k-405c-4ae8-8a6b-d90b40ff3cce"
|
|
426
426
|
* ],
|
|
427
427
|
* "context": "This is an interview about wildfires.",
|
|
428
|
+
* "answer_format": "Bullet Points",
|
|
428
429
|
* "final_model": "default",
|
|
429
430
|
* "temperature": 0,
|
|
430
431
|
* "max_output_size": 3000
|
|
431
432
|
* }
|
|
432
433
|
*/
|
|
433
|
-
export type LemurActionItemsParams = LemurBaseParams
|
|
434
|
+
export type LemurActionItemsParams = LemurBaseParams & {
|
|
435
|
+
/**
|
|
436
|
+
* @description How you want the action items to be returned. This can be any text.
|
|
437
|
+
* Defaults to "Bullet Points".
|
|
438
|
+
*
|
|
439
|
+
* @default Bullet Points
|
|
440
|
+
*/
|
|
441
|
+
answer_format?: string;
|
|
442
|
+
};
|
|
434
443
|
/**
|
|
435
444
|
* @example {
|
|
436
445
|
* "request_id": "5e1b27c2-691f-4414-8bc5-f14678442f9e",
|
|
@@ -825,6 +834,13 @@ export type RedactedAudioResponse = {
|
|
|
825
834
|
* @enum {string}
|
|
826
835
|
*/
|
|
827
836
|
export type RedactedAudioStatus = "redacted_audio_ready";
|
|
837
|
+
/**
|
|
838
|
+
* @description Controls the filetype of the audio created by redact_pii_audio. Currently supports mp3 (default) and wav. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
|
|
839
|
+
* @default mp3
|
|
840
|
+
* @example mp3
|
|
841
|
+
* @enum {string}
|
|
842
|
+
*/
|
|
843
|
+
export type RedactPiiAudioQuality = "mp3" | "wav";
|
|
828
844
|
/**
|
|
829
845
|
* @example {
|
|
830
846
|
* "sentences": [
|
|
@@ -1954,7 +1970,7 @@ export type Transcript = {
|
|
|
1954
1970
|
* @description The audio quality of the PII-redacted audio file, if redact_pii_audio is enabled.
|
|
1955
1971
|
* See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more information.
|
|
1956
1972
|
*/
|
|
1957
|
-
redact_pii_audio_quality?:
|
|
1973
|
+
redact_pii_audio_quality?: RedactPiiAudioQuality | null;
|
|
1958
1974
|
/**
|
|
1959
1975
|
* @description The list of PII Redaction policies that were enabled, if PII Redaction is enabled.
|
|
1960
1976
|
* See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more information.
|
|
@@ -2097,7 +2113,7 @@ export type TranscriptList = {
|
|
|
2097
2113
|
*/
|
|
2098
2114
|
export type TranscriptListItem = {
|
|
2099
2115
|
audio_url: string;
|
|
2100
|
-
completed
|
|
2116
|
+
completed: Date | null;
|
|
2101
2117
|
created: Date;
|
|
2102
2118
|
/** Format: uuid */
|
|
2103
2119
|
id: string;
|
|
@@ -2198,7 +2214,7 @@ export type TranscriptOptionalParams = {
|
|
|
2198
2214
|
* @description Controls the filetype of the audio created by redact_pii_audio. Currently supports mp3 (default) and wav. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
|
|
2199
2215
|
* @default mp3
|
|
2200
2216
|
*/
|
|
2201
|
-
redact_pii_audio_quality?:
|
|
2217
|
+
redact_pii_audio_quality?: RedactPiiAudioQuality;
|
|
2202
2218
|
/** @description The list of PII Redaction policies to enable. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details. */
|
|
2203
2219
|
redact_pii_policies?: PiiPolicy[];
|
|
2204
2220
|
/** @description The replacement logic for detected PII, can be "entity_type" or "hash". See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AudioEncoding, FinalTranscript, PartialTranscript, RealtimeTranscript, RealtimeTranscriptType } from "../asyncapi.generated";
|
|
2
|
-
type
|
|
2
|
+
type CreateRealtimeTranscriberParams = {
|
|
3
3
|
realtimeUrl?: string;
|
|
4
4
|
sampleRate?: number;
|
|
5
5
|
wordBoost?: string[];
|
|
@@ -9,7 +9,11 @@ type CreateRealtimeServiceParams = {
|
|
|
9
9
|
} | {
|
|
10
10
|
token: string;
|
|
11
11
|
});
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use CreateRealtimeTranscriberParams instead
|
|
14
|
+
*/
|
|
15
|
+
type CreateRealtimeServiceParams = CreateRealtimeTranscriberParams;
|
|
16
|
+
type RealtimeTranscriberParams = {
|
|
13
17
|
realtimeUrl?: string;
|
|
14
18
|
sampleRate?: number;
|
|
15
19
|
wordBoost?: string[];
|
|
@@ -19,6 +23,10 @@ type RealtimeServiceParams = {
|
|
|
19
23
|
} | {
|
|
20
24
|
token: string;
|
|
21
25
|
});
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Use RealtimeTranscriberParams instead
|
|
28
|
+
*/
|
|
29
|
+
type RealtimeServiceParams = RealtimeTranscriberParams;
|
|
22
30
|
type RealtimeEvents = "open" | "close" | "transcript" | "transcript.partial" | "transcript.final" | "error";
|
|
23
31
|
type SessionBeginsEventData = {
|
|
24
32
|
sessionId: string;
|
|
@@ -35,4 +43,4 @@ type RealtimeListeners = {
|
|
|
35
43
|
type RealtimeTokenParams = {
|
|
36
44
|
expires_in: number;
|
|
37
45
|
};
|
|
38
|
-
export type { CreateRealtimeServiceParams, RealtimeServiceParams, RealtimeEvents, RealtimeTranscriptType, SessionBeginsEventData, RealtimeListeners, RealtimeTokenParams, };
|
|
46
|
+
export type { CreateRealtimeTranscriberParams, RealtimeTranscriberParams, CreateRealtimeServiceParams, RealtimeServiceParams, RealtimeEvents, RealtimeTranscriptType, SessionBeginsEventData, RealtimeListeners, RealtimeTokenParams, };
|
package/docs/compat.md
CHANGED
|
@@ -13,7 +13,7 @@ If you do use an older version of Node.js like version 16, you'll need to polyfi
|
|
|
13
13
|
To make the SDK compatible with the browser, the SDK aims to use web standards as much as possible.
|
|
14
14
|
However, there are still incompatibilities between Node.js and the browser.
|
|
15
15
|
|
|
16
|
-
- `
|
|
16
|
+
- `RealtimeTranscriber` doesn't support the AssemblyAI API key in the browser.
|
|
17
17
|
Instead, you have to generate a temporary auth token using `client.realtime.createTemporaryToken`, and pass in the resulting token to the real-time transcriber.
|
|
18
18
|
|
|
19
19
|
Generate a temporary auth token on the server.
|
|
@@ -31,16 +31,16 @@ However, there are still incompatibilities between Node.js and the browser.
|
|
|
31
31
|
> If you embed the API key on the client, everyone can see it and use it for themselves.
|
|
32
32
|
|
|
33
33
|
Then pass the token via an API to the client.
|
|
34
|
-
On the client, create an instance of `
|
|
34
|
+
On the client, create an instance of `RealtimeTranscriber` using the token.
|
|
35
35
|
|
|
36
36
|
```js
|
|
37
|
-
import {
|
|
37
|
+
import { RealtimeTranscriber } from "assemblyai";
|
|
38
38
|
// or the following if you're using UMD
|
|
39
|
-
// const {
|
|
39
|
+
// const { RealtimeTranscriber } = assemblyai;
|
|
40
40
|
|
|
41
41
|
const token = getToken(); // getToken is a function for you to implement
|
|
42
42
|
|
|
43
|
-
const rt = new
|
|
43
|
+
const rt = new RealtimeTranscriber({
|
|
44
44
|
token: token,
|
|
45
45
|
});
|
|
46
46
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblyai",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "The AssemblyAI JavaScript SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription, as well as the latest LeMUR models.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18"
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"url": "git+https://github.com/AssemblyAI/assemblyai-node-sdk.git"
|
|
62
62
|
},
|
|
63
63
|
"publishConfig": {
|
|
64
|
-
"tag": "
|
|
64
|
+
"tag": "latest",
|
|
65
65
|
"access": "public",
|
|
66
66
|
"registry": "https://registry.npmjs.org/"
|
|
67
67
|
},
|
package/src/services/index.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { BaseServiceParams } from "..";
|
|
2
2
|
import { LemurService } from "./lemur";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
RealtimeTranscriber,
|
|
5
|
+
RealtimeTranscriberFactory,
|
|
6
|
+
RealtimeService,
|
|
7
|
+
RealtimeServiceFactory,
|
|
8
|
+
} from "./realtime";
|
|
4
9
|
import { TranscriptService } from "./transcripts";
|
|
5
10
|
import { FileService } from "./files";
|
|
6
11
|
|
|
@@ -25,7 +30,7 @@ class AssemblyAI {
|
|
|
25
30
|
/**
|
|
26
31
|
* The realtime service.
|
|
27
32
|
*/
|
|
28
|
-
public realtime:
|
|
33
|
+
public realtime: RealtimeTranscriberFactory;
|
|
29
34
|
|
|
30
35
|
/**
|
|
31
36
|
* Create a new AssemblyAI client.
|
|
@@ -38,13 +43,15 @@ class AssemblyAI {
|
|
|
38
43
|
this.files = new FileService(params);
|
|
39
44
|
this.transcripts = new TranscriptService(params, this.files);
|
|
40
45
|
this.lemur = new LemurService(params);
|
|
41
|
-
this.realtime = new
|
|
46
|
+
this.realtime = new RealtimeTranscriberFactory(params);
|
|
42
47
|
}
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
export {
|
|
46
51
|
AssemblyAI,
|
|
47
52
|
LemurService,
|
|
53
|
+
RealtimeTranscriberFactory,
|
|
54
|
+
RealtimeTranscriber,
|
|
48
55
|
RealtimeServiceFactory,
|
|
49
56
|
RealtimeService,
|
|
50
57
|
TranscriptService,
|
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseServiceParams,
|
|
3
3
|
RealtimeTokenParams,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
CreateRealtimeTranscriberParams,
|
|
5
|
+
RealtimeTranscriberParams,
|
|
6
6
|
RealtimeTemporaryTokenResponse,
|
|
7
|
+
CreateRealtimeServiceParams,
|
|
7
8
|
} from "../..";
|
|
8
|
-
import { RealtimeService } from "./service";
|
|
9
|
+
import { RealtimeService, RealtimeTranscriber } from "./service";
|
|
9
10
|
import { BaseService } from "../base";
|
|
10
11
|
|
|
11
|
-
export class
|
|
12
|
+
export class RealtimeTranscriberFactory extends BaseService {
|
|
12
13
|
private rtFactoryParams: BaseServiceParams;
|
|
13
14
|
constructor(params: BaseServiceParams) {
|
|
14
15
|
super(params);
|
|
15
16
|
this.rtFactoryParams = params;
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Use transcriber(...) instead
|
|
21
|
+
*/
|
|
18
22
|
createService(params?: CreateRealtimeServiceParams): RealtimeService {
|
|
23
|
+
return this.transcriber(params);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
transcriber(params?: CreateRealtimeTranscriberParams): RealtimeTranscriber {
|
|
19
27
|
const serviceParams = { ...params } as Record<string, unknown>;
|
|
20
28
|
if (!serviceParams.token && !serviceParams.apiKey) {
|
|
21
29
|
serviceParams.apiKey = this.rtFactoryParams.apiKey;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
|
-
return new
|
|
32
|
+
return new RealtimeTranscriber(serviceParams as RealtimeTranscriberParams);
|
|
25
33
|
}
|
|
26
34
|
|
|
27
35
|
async createTemporaryToken(params: RealtimeTokenParams) {
|
|
@@ -35,3 +43,8 @@ export class RealtimeServiceFactory extends BaseService {
|
|
|
35
43
|
return data.token;
|
|
36
44
|
}
|
|
37
45
|
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated Use RealtimeTranscriberFactory instead
|
|
49
|
+
*/
|
|
50
|
+
export class RealtimeServiceFactory extends RealtimeTranscriberFactory {}
|
|
@@ -4,13 +4,14 @@ import { ErrorEvent, MessageEvent, CloseEvent } from "ws";
|
|
|
4
4
|
import {
|
|
5
5
|
RealtimeEvents,
|
|
6
6
|
RealtimeListeners,
|
|
7
|
-
|
|
7
|
+
RealtimeTranscriberParams,
|
|
8
8
|
RealtimeMessage,
|
|
9
9
|
RealtimeTranscript,
|
|
10
10
|
PartialTranscript,
|
|
11
11
|
FinalTranscript,
|
|
12
12
|
SessionBeginsEventData,
|
|
13
13
|
AudioEncoding,
|
|
14
|
+
AudioData,
|
|
14
15
|
} from "../..";
|
|
15
16
|
import {
|
|
16
17
|
RealtimeError,
|
|
@@ -20,7 +21,7 @@ import {
|
|
|
20
21
|
|
|
21
22
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
22
23
|
|
|
23
|
-
export class
|
|
24
|
+
export class RealtimeTranscriber {
|
|
24
25
|
private realtimeUrl: string;
|
|
25
26
|
private sampleRate: number;
|
|
26
27
|
private wordBoost?: string[];
|
|
@@ -31,7 +32,7 @@ export class RealtimeService {
|
|
|
31
32
|
private listeners: RealtimeListeners = {};
|
|
32
33
|
private sessionTerminatedResolve?: () => void;
|
|
33
34
|
|
|
34
|
-
constructor(params:
|
|
35
|
+
constructor(params: RealtimeTranscriberParams) {
|
|
35
36
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
36
37
|
this.sampleRate = params.sampleRate ?? 16_000;
|
|
37
38
|
this.wordBoost = params.wordBoost;
|
|
@@ -157,16 +158,16 @@ export class RealtimeService {
|
|
|
157
158
|
});
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
sendAudio(audio:
|
|
161
|
+
sendAudio(audio: AudioData) {
|
|
161
162
|
if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
|
|
162
163
|
throw new Error("Socket is not open for communication");
|
|
163
164
|
}
|
|
164
165
|
this.socket.send(audio);
|
|
165
166
|
}
|
|
166
167
|
|
|
167
|
-
stream(): WritableStream<
|
|
168
|
-
return new WritableStream<
|
|
169
|
-
write: (chunk:
|
|
168
|
+
stream(): WritableStream<AudioData> {
|
|
169
|
+
return new WritableStream<AudioData>({
|
|
170
|
+
write: (chunk: AudioData) => {
|
|
170
171
|
this.sendAudio(chunk);
|
|
171
172
|
},
|
|
172
173
|
});
|
|
@@ -194,3 +195,8 @@ export class RealtimeService {
|
|
|
194
195
|
this.socket = undefined;
|
|
195
196
|
}
|
|
196
197
|
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @deprecated Use RealtimeTranscriber instead
|
|
201
|
+
*/
|
|
202
|
+
export class RealtimeService extends RealtimeTranscriber {}
|
|
@@ -15,10 +15,11 @@ type OneOf<T extends any[]> = T extends [infer Only]
|
|
|
15
15
|
? OneOf<[XOR<A, B>, ...Rest]>
|
|
16
16
|
: never;
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Format: binary
|
|
20
|
+
* @description Binary audio data
|
|
21
|
+
*/
|
|
22
|
+
export type AudioData = ArrayBufferLike;
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* @description The encoding of the audio data
|
|
@@ -475,12 +475,21 @@ export type Error = {
|
|
|
475
475
|
* "64nygnr62k-405c-4ae8-8a6b-d90b40ff3cce"
|
|
476
476
|
* ],
|
|
477
477
|
* "context": "This is an interview about wildfires.",
|
|
478
|
+
* "answer_format": "Bullet Points",
|
|
478
479
|
* "final_model": "default",
|
|
479
480
|
* "temperature": 0,
|
|
480
481
|
* "max_output_size": 3000
|
|
481
482
|
* }
|
|
482
483
|
*/
|
|
483
|
-
export type LemurActionItemsParams = LemurBaseParams
|
|
484
|
+
export type LemurActionItemsParams = LemurBaseParams & {
|
|
485
|
+
/**
|
|
486
|
+
* @description How you want the action items to be returned. This can be any text.
|
|
487
|
+
* Defaults to "Bullet Points".
|
|
488
|
+
*
|
|
489
|
+
* @default Bullet Points
|
|
490
|
+
*/
|
|
491
|
+
answer_format?: string;
|
|
492
|
+
};
|
|
484
493
|
|
|
485
494
|
/**
|
|
486
495
|
* @example {
|
|
@@ -931,6 +940,14 @@ export type RedactedAudioResponse = {
|
|
|
931
940
|
*/
|
|
932
941
|
export type RedactedAudioStatus = "redacted_audio_ready";
|
|
933
942
|
|
|
943
|
+
/**
|
|
944
|
+
* @description Controls the filetype of the audio created by redact_pii_audio. Currently supports mp3 (default) and wav. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
|
|
945
|
+
* @default mp3
|
|
946
|
+
* @example mp3
|
|
947
|
+
* @enum {string}
|
|
948
|
+
*/
|
|
949
|
+
export type RedactPiiAudioQuality = "mp3" | "wav";
|
|
950
|
+
|
|
934
951
|
/**
|
|
935
952
|
* @example {
|
|
936
953
|
* "sentences": [
|
|
@@ -2076,7 +2093,7 @@ export type Transcript = {
|
|
|
2076
2093
|
* @description The audio quality of the PII-redacted audio file, if redact_pii_audio is enabled.
|
|
2077
2094
|
* See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more information.
|
|
2078
2095
|
*/
|
|
2079
|
-
redact_pii_audio_quality?:
|
|
2096
|
+
redact_pii_audio_quality?: RedactPiiAudioQuality | null;
|
|
2080
2097
|
/**
|
|
2081
2098
|
* @description The list of PII Redaction policies that were enabled, if PII Redaction is enabled.
|
|
2082
2099
|
* See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more information.
|
|
@@ -2244,7 +2261,7 @@ export type TranscriptList = {
|
|
|
2244
2261
|
*/
|
|
2245
2262
|
export type TranscriptListItem = {
|
|
2246
2263
|
audio_url: string;
|
|
2247
|
-
completed
|
|
2264
|
+
completed: Date | null;
|
|
2248
2265
|
created: Date;
|
|
2249
2266
|
/** Format: uuid */
|
|
2250
2267
|
id: string;
|
|
@@ -2346,7 +2363,7 @@ export type TranscriptOptionalParams = {
|
|
|
2346
2363
|
* @description Controls the filetype of the audio created by redact_pii_audio. Currently supports mp3 (default) and wav. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
|
|
2347
2364
|
* @default mp3
|
|
2348
2365
|
*/
|
|
2349
|
-
redact_pii_audio_quality?:
|
|
2366
|
+
redact_pii_audio_quality?: RedactPiiAudioQuality;
|
|
2350
2367
|
/** @description The list of PII Redaction policies to enable. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details. */
|
|
2351
2368
|
redact_pii_policies?: PiiPolicy[];
|
|
2352
2369
|
/** @description The replacement logic for detected PII, can be "entity_type" or "hash". See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details. */
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
RealtimeTranscriptType,
|
|
7
7
|
} from "../asyncapi.generated";
|
|
8
8
|
|
|
9
|
-
type
|
|
9
|
+
type CreateRealtimeTranscriberParams = {
|
|
10
10
|
realtimeUrl?: string;
|
|
11
11
|
sampleRate?: number;
|
|
12
12
|
wordBoost?: string[];
|
|
@@ -20,7 +20,12 @@ type CreateRealtimeServiceParams = {
|
|
|
20
20
|
}
|
|
21
21
|
);
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated Use CreateRealtimeTranscriberParams instead
|
|
25
|
+
*/
|
|
26
|
+
type CreateRealtimeServiceParams = CreateRealtimeTranscriberParams;
|
|
27
|
+
|
|
28
|
+
type RealtimeTranscriberParams = {
|
|
24
29
|
realtimeUrl?: string;
|
|
25
30
|
sampleRate?: number;
|
|
26
31
|
wordBoost?: string[];
|
|
@@ -34,6 +39,11 @@ type RealtimeServiceParams = {
|
|
|
34
39
|
}
|
|
35
40
|
);
|
|
36
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated Use RealtimeTranscriberParams instead
|
|
44
|
+
*/
|
|
45
|
+
type RealtimeServiceParams = RealtimeTranscriberParams;
|
|
46
|
+
|
|
37
47
|
type RealtimeEvents =
|
|
38
48
|
| "open"
|
|
39
49
|
| "close"
|
|
@@ -61,6 +71,8 @@ type RealtimeTokenParams = {
|
|
|
61
71
|
};
|
|
62
72
|
|
|
63
73
|
export type {
|
|
74
|
+
CreateRealtimeTranscriberParams,
|
|
75
|
+
RealtimeTranscriberParams,
|
|
64
76
|
CreateRealtimeServiceParams,
|
|
65
77
|
RealtimeServiceParams,
|
|
66
78
|
RealtimeEvents,
|