Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

assemblyai

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assemblyai - npm Package Compare versions

Comparing version 4.2.0 to 4.2.1

9

CHANGELOG.md
# Changelog
## [4.2.1] - 2024-01-23
### Added
- Add `answer_format` to `LemurActionItemsParams` type
### Changed
- 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.
- Restrict the type for `redact_pii_audio_quality` from `string` to `RedactPiiAudioQuality` an enum string.
## [4.2.0] - 2024-01-11

@@ -4,0 +13,0 @@

26

dist/assemblyai.umd.js

@@ -198,3 +198,3 @@ (function (global, factory) {

const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
class RealtimeService {
class RealtimeTranscriber {
constructor(params) {

@@ -346,4 +346,9 @@ var _a, _b;

}
/**
* @deprecated Use RealtimeTranscriber instead
*/
class RealtimeService extends RealtimeTranscriber {
}
class RealtimeServiceFactory extends BaseService {
class RealtimeTranscriberFactory extends BaseService {
constructor(params) {

@@ -353,3 +358,9 @@ super(params);

}
/**
* @deprecated Use transcriber(...) instead
*/
createService(params) {
return this.transcriber(params);
}
transcriber(params) {
const serviceParams = Object.assign({}, params);

@@ -359,3 +370,3 @@ if (!serviceParams.token && !serviceParams.apiKey) {

}
return new RealtimeService(serviceParams);
return new RealtimeTranscriber(serviceParams);
}

@@ -372,2 +383,7 @@ createTemporaryToken(params) {

}
/**
* @deprecated Use RealtimeTranscriberFactory instead
*/
class RealtimeServiceFactory extends RealtimeTranscriberFactory {
}

@@ -636,3 +652,3 @@ class TranscriptService extends BaseService {

this.lemur = new LemurService(params);
this.realtime = new RealtimeServiceFactory(params);
this.realtime = new RealtimeTranscriberFactory(params);
}

@@ -646,4 +662,6 @@ }

exports.RealtimeServiceFactory = RealtimeServiceFactory;
exports.RealtimeTranscriber = RealtimeTranscriber;
exports.RealtimeTranscriberFactory = RealtimeTranscriberFactory;
exports.TranscriptService = TranscriptService;
}));

2

dist/assemblyai.umd.min.js

@@ -1,1 +0,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}));
!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}));
import { BaseServiceParams } from "..";
import { LemurService } from "./lemur";
import { RealtimeService, RealtimeServiceFactory } from "./realtime";
import { RealtimeTranscriber, RealtimeTranscriberFactory, RealtimeService, RealtimeServiceFactory } from "./realtime";
import { TranscriptService } from "./transcripts";

@@ -22,3 +22,3 @@ import { FileService } from "./files";

*/
realtime: RealtimeServiceFactory;
realtime: RealtimeTranscriberFactory;
/**

@@ -30,2 +30,2 @@ * Create a new AssemblyAI client.

}
export { AssemblyAI, LemurService, RealtimeServiceFactory, RealtimeService, TranscriptService, FileService, };
export { AssemblyAI, LemurService, RealtimeTranscriberFactory, RealtimeTranscriber, RealtimeServiceFactory, RealtimeService, TranscriptService, FileService, };

@@ -1,9 +0,18 @@

import { BaseServiceParams, RealtimeTokenParams, CreateRealtimeServiceParams } from "../..";
import { RealtimeService } from "./service";
import { BaseServiceParams, RealtimeTokenParams, CreateRealtimeTranscriberParams, CreateRealtimeServiceParams } from "../..";
import { RealtimeService, RealtimeTranscriber } from "./service";
import { BaseService } from "../base";
export declare class RealtimeServiceFactory extends BaseService {
export declare class RealtimeTranscriberFactory extends BaseService {
private rtFactoryParams;
constructor(params: BaseServiceParams);
/**
* @deprecated Use transcriber(...) instead
*/
createService(params?: CreateRealtimeServiceParams): RealtimeService;
transcriber(params?: CreateRealtimeTranscriberParams): RealtimeTranscriber;
createTemporaryToken(params: RealtimeTokenParams): Promise<string>;
}
/**
* @deprecated Use RealtimeTranscriberFactory instead
*/
export declare class RealtimeServiceFactory extends RealtimeTranscriberFactory {
}

@@ -1,3 +0,3 @@

import { RealtimeServiceParams, RealtimeTranscript, PartialTranscript, FinalTranscript, SessionBeginsEventData } from "../..";
export declare class RealtimeService {
import { RealtimeTranscriberParams, RealtimeTranscript, PartialTranscript, FinalTranscript, SessionBeginsEventData, AudioData } from "../..";
export declare class RealtimeTranscriber {
private realtimeUrl;

@@ -12,3 +12,3 @@ private sampleRate;

private sessionTerminatedResolve?;
constructor(params: RealtimeServiceParams);
constructor(params: RealtimeTranscriberParams);
private connectionUrl;

@@ -22,5 +22,10 @@ on(event: "open", listener: (event: SessionBeginsEventData) => void): void;

connect(): Promise<SessionBeginsEventData>;
sendAudio(audio: ArrayBufferLike): void;
stream(): WritableStream<ArrayBufferLike>;
sendAudio(audio: AudioData): void;
stream(): WritableStream<AudioData>;
close(waitForSessionTermination?: boolean): Promise<void>;
}
/**
* @deprecated Use RealtimeTranscriber instead
*/
export declare class RealtimeService extends RealtimeTranscriber {
}

@@ -1,6 +0,7 @@

export type AudioData = {
/** @description Base64 encoded raw audio data */
audio_data: string;
};
/**
* Format: binary
* @description Binary audio data
*/
export type AudioData = ArrayBufferLike;
/**
* @description The encoding of the audio data

@@ -7,0 +8,0 @@ * @default pcm_s16le

import { AudioEncoding, FinalTranscript, PartialTranscript, RealtimeTranscript, RealtimeTranscriptType } from "../asyncapi.generated";
type CreateRealtimeServiceParams = {
type CreateRealtimeTranscriberParams = {
realtimeUrl?: string;

@@ -12,3 +12,7 @@ sampleRate?: number;

});
type RealtimeServiceParams = {
/**
* @deprecated Use CreateRealtimeTranscriberParams instead
*/
type CreateRealtimeServiceParams = CreateRealtimeTranscriberParams;
type RealtimeTranscriberParams = {
realtimeUrl?: string;

@@ -23,2 +27,6 @@ sampleRate?: number;

});
/**
* @deprecated Use RealtimeTranscriberParams instead
*/
type RealtimeServiceParams = RealtimeTranscriberParams;
type RealtimeEvents = "open" | "close" | "transcript" | "transcript.partial" | "transcript.final" | "error";

@@ -40,2 +48,2 @@ type SessionBeginsEventData = {

};
export type { CreateRealtimeServiceParams, RealtimeServiceParams, RealtimeEvents, RealtimeTranscriptType, SessionBeginsEventData, RealtimeListeners, RealtimeTokenParams, };
export type { CreateRealtimeTranscriberParams, RealtimeTranscriberParams, CreateRealtimeServiceParams, RealtimeServiceParams, RealtimeEvents, RealtimeTranscriptType, SessionBeginsEventData, RealtimeListeners, RealtimeTokenParams, };

@@ -16,3 +16,3 @@ # SDK Compatibility

- `RealtimeService` doesn't support the AssemblyAI API key in the browser.
- `RealtimeTranscriber` doesn't support the AssemblyAI API key in the browser.
Instead, you have to generate a temporary auth token using `client.realtime.createTemporaryToken`, and pass in the resulting token to the real-time transcriber.

@@ -35,12 +35,12 @@

Then pass the token via an API to the client.
On the client, create an instance of `RealtimeService` using the token.
On the client, create an instance of `RealtimeTranscriber` using the token.
```js
import { RealtimeService } from "assemblyai";
import { RealtimeTranscriber } from "assemblyai";
// or the following if you're using UMD
// const { RealtimeService } = assemblyai;
// const { RealtimeTranscriber } = assemblyai;
const token = getToken(); // getToken is a function for you to implement
const rt = new RealtimeService({
const rt = new RealtimeTranscriber({
token: token,

@@ -47,0 +47,0 @@ });

{
"name": "assemblyai",
"version": "4.2.0",
"version": "4.2.1",
"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,0 +5,0 @@ "engines": {

@@ -187,8 +187,8 @@ <img src="https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/assemblyai.png?raw=true" width="500"/>

## Transcribe in real time
## Transcribe in real-time
Create the real-time service.
Create the real-time transcriber.
```typescript
const rt = client.realtime.createService();
const rt = client.realtime.transcriber();
```

@@ -199,3 +199,3 @@

```typescript
const rt = client.realtime.createService({
const rt = client.realtime.transcriber({
realtimeUrl: 'wss://localhost/override',

@@ -212,3 +212,3 @@ apiKey: process.env.ASSEMBLYAI_API_KEY // The API key passed to `AssemblyAI` will be used by default,

const token = await client.realtime.createTemporaryToken({ expires_in = 60 });
const rt = client.realtime.createService({
const rt = client.realtime.transcriber({
token: token,

@@ -215,0 +215,0 @@ });

import { BaseServiceParams } from "..";
import { LemurService } from "./lemur";
import { RealtimeService, RealtimeServiceFactory } from "./realtime";
import {
RealtimeTranscriber,
RealtimeTranscriberFactory,
RealtimeService,
RealtimeServiceFactory,
} from "./realtime";
import { TranscriptService } from "./transcripts";

@@ -28,3 +33,3 @@ import { FileService } from "./files";

*/
public realtime: RealtimeServiceFactory;
public realtime: RealtimeTranscriberFactory;

@@ -42,3 +47,3 @@ /**

this.lemur = new LemurService(params);
this.realtime = new RealtimeServiceFactory(params);
this.realtime = new RealtimeTranscriberFactory(params);
}

@@ -50,2 +55,4 @@ }

LemurService,
RealtimeTranscriberFactory,
RealtimeTranscriber,
RealtimeServiceFactory,

@@ -52,0 +59,0 @@ RealtimeService,

import {
BaseServiceParams,
RealtimeTokenParams,
CreateRealtimeTranscriberParams,
RealtimeTranscriberParams,
RealtimeTemporaryTokenResponse,
CreateRealtimeServiceParams,
RealtimeServiceParams,
RealtimeTemporaryTokenResponse,
} from "../..";
import { RealtimeService } from "./service";
import { RealtimeService, RealtimeTranscriber } from "./service";
import { BaseService } from "../base";
export class RealtimeServiceFactory extends BaseService {
export class RealtimeTranscriberFactory extends BaseService {
private rtFactoryParams: BaseServiceParams;

@@ -18,3 +19,10 @@ constructor(params: BaseServiceParams) {

/**
* @deprecated Use transcriber(...) instead
*/
createService(params?: CreateRealtimeServiceParams): RealtimeService {
return this.transcriber(params);
}
transcriber(params?: CreateRealtimeTranscriberParams): RealtimeTranscriber {
const serviceParams = { ...params } as Record<string, unknown>;

@@ -25,3 +33,3 @@ if (!serviceParams.token && !serviceParams.apiKey) {

return new RealtimeService(serviceParams as RealtimeServiceParams);
return new RealtimeTranscriber(serviceParams as RealtimeTranscriberParams);
}

@@ -40,1 +48,6 @@

}
/**
* @deprecated Use RealtimeTranscriberFactory instead
*/
export class RealtimeServiceFactory extends RealtimeTranscriberFactory {}

@@ -7,3 +7,3 @@ import { WritableStream } from "#streams";

RealtimeListeners,
RealtimeServiceParams,
RealtimeTranscriberParams,
RealtimeMessage,

@@ -15,2 +15,3 @@ RealtimeTranscript,

AudioEncoding,
AudioData,
} from "../..";

@@ -25,3 +26,3 @@ import {

export class RealtimeService {
export class RealtimeTranscriber {
private realtimeUrl: string;

@@ -37,3 +38,3 @@ private sampleRate: number;

constructor(params: RealtimeServiceParams) {
constructor(params: RealtimeTranscriberParams) {
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;

@@ -164,3 +165,3 @@ this.sampleRate = params.sampleRate ?? 16_000;

sendAudio(audio: ArrayBufferLike) {
sendAudio(audio: AudioData) {
if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {

@@ -172,5 +173,5 @@ throw new Error("Socket is not open for communication");

stream(): WritableStream<ArrayBufferLike> {
return new WritableStream<ArrayBufferLike>({
write: (chunk: ArrayBufferLike) => {
stream(): WritableStream<AudioData> {
return new WritableStream<AudioData>({
write: (chunk: AudioData) => {
this.sendAudio(chunk);

@@ -203,1 +204,6 @@ },

}
/**
* @deprecated Use RealtimeTranscriber instead
*/
export class RealtimeService extends RealtimeTranscriber {}

@@ -18,6 +18,7 @@ // this file is generated by typescript/scripts/generate-types.ts

export type AudioData = {
/** @description Base64 encoded raw audio data */
audio_data: string;
};
/**
* Format: binary
* @description Binary audio data
*/
export type AudioData = ArrayBufferLike;

@@ -24,0 +25,0 @@ /**

@@ -9,3 +9,3 @@ import {

type CreateRealtimeServiceParams = {
type CreateRealtimeTranscriberParams = {
realtimeUrl?: string;

@@ -24,3 +24,8 @@ sampleRate?: number;

type RealtimeServiceParams = {
/**
* @deprecated Use CreateRealtimeTranscriberParams instead
*/
type CreateRealtimeServiceParams = CreateRealtimeTranscriberParams;
type RealtimeTranscriberParams = {
realtimeUrl?: string;

@@ -39,2 +44,7 @@ sampleRate?: number;

/**
* @deprecated Use RealtimeTranscriberParams instead
*/
type RealtimeServiceParams = RealtimeTranscriberParams;
type RealtimeEvents =

@@ -67,2 +77,4 @@ | "open"

export type {
CreateRealtimeTranscriberParams,
RealtimeTranscriberParams,
CreateRealtimeServiceParams,

@@ -69,0 +81,0 @@ RealtimeServiceParams,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc