assemblyai 4.2.1 → 4.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/assemblyai.umd.js +12 -13
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/bun.mjs +12 -13
- package/dist/deno.mjs +12 -13
- package/dist/index.cjs +12 -13
- package/dist/index.mjs +12 -13
- package/dist/node.cjs +12 -13
- package/dist/node.mjs +12 -13
- package/dist/types/openapi.generated.d.ts +17 -0
- package/dist/utils/path.d.ts +1 -0
- package/package.json +1 -1
- package/src/services/transcripts/index.ts +1 -11
- package/src/types/openapi.generated.ts +18 -0
- package/src/utils/path.ts +7 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.2.2] - 2024-01-29
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Windows paths passed to `client.transcripts.transcribe` and `client.transcripts.submit` will work as expected.
|
|
8
|
+
|
|
3
9
|
## [4.2.1] - 2024-01-23
|
|
4
10
|
|
|
5
11
|
### Added
|
|
12
|
+
|
|
6
13
|
- Add `answer_format` to `LemurActionItemsParams` type
|
|
7
14
|
|
|
8
15
|
### Changed
|
|
16
|
+
|
|
9
17
|
- Rename `RealtimeService` to `RealtimeTranscriber`, `RealtimeServiceFactory` to `RealtimeTranscriberFactory`, `RealtimeTranscriberFactory.createService()` to `RealtimeTranscriberFactory.transcriber()`. Deprecated aliases are provided for all old types and functions for backwards compatibility.
|
|
10
18
|
- Restrict the type for `redact_pii_audio_quality` from `string` to `RedactPiiAudioQuality` an enum string.
|
|
11
19
|
|
package/dist/assemblyai.umd.js
CHANGED
|
@@ -382,6 +382,18 @@
|
|
|
382
382
|
class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
383
383
|
}
|
|
384
384
|
|
|
385
|
+
function getPath(path) {
|
|
386
|
+
if (path.startsWith("http"))
|
|
387
|
+
return null;
|
|
388
|
+
if (path.startsWith("https"))
|
|
389
|
+
return null;
|
|
390
|
+
if (path.startsWith("file://"))
|
|
391
|
+
return path.substring(7);
|
|
392
|
+
if (path.startsWith("file:"))
|
|
393
|
+
return path.substring(5);
|
|
394
|
+
return path;
|
|
395
|
+
}
|
|
396
|
+
|
|
385
397
|
class TranscriptService extends BaseService {
|
|
386
398
|
constructor(params, files) {
|
|
387
399
|
super(params);
|
|
@@ -583,19 +595,6 @@
|
|
|
583
595
|
return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
|
|
584
596
|
}
|
|
585
597
|
}
|
|
586
|
-
function getPath(path) {
|
|
587
|
-
let url;
|
|
588
|
-
try {
|
|
589
|
-
url = new URL(path);
|
|
590
|
-
if (url.protocol === "file:")
|
|
591
|
-
return url.pathname;
|
|
592
|
-
else
|
|
593
|
-
return null;
|
|
594
|
-
}
|
|
595
|
-
catch (_a) {
|
|
596
|
-
return path;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
598
|
|
|
600
599
|
const readFile = function (
|
|
601
600
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -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){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}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).assemblyai={})}(this,(function(e){"use strict";function t(e,t,s,i){return new(s||(s=Promise))((function(o,n){function r(e){try{c(i.next(e))}catch(e){n(e)}}function a(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,a)}c((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class s{constructor(e){this.params=e}fetch(e,s){var i;return t(this,void 0,void 0,(function*(){(s=null!=s?s:{}).headers=null!==(i=s.headers)&&void 0!==i?i:{},s.headers=Object.assign({Authorization:this.params.apiKey,"Content-Type":"application/json"},s.headers),e.startsWith("http")||(e=this.params.baseUrl+e);const t=yield fetch(e,s);if(t.status>=400){let e;const s=yield t.text();if(s){try{e=JSON.parse(s)}catch(e){}if(null==e?void 0:e.error)throw new Error(e.error);throw new Error(s)}throw new Error(`HTTP Error: ${t.status} ${t.statusText}`)}return t}))}fetchJson(e,s){return t(this,void 0,void 0,(function*(){return(yield this.fetch(e,s)).json()}))}}class i extends s{summary(e){return this.fetchJson("/lemur/v3/generate/summary",{method:"POST",body:JSON.stringify(e)})}questionAnswer(e){return this.fetchJson("/lemur/v3/generate/question-answer",{method:"POST",body:JSON.stringify(e)})}actionItems(e){return this.fetchJson("/lemur/v3/generate/action-items",{method:"POST",body:JSON.stringify(e)})}task(e){return this.fetchJson("/lemur/v3/generate/task",{method:"POST",body:JSON.stringify(e)})}purgeRequestData(e){return this.fetchJson(`/lemur/v3/${e}`,{method:"DELETE"})}}const{WritableStream:o}="undefined"!=typeof window?window:"undefined"!=typeof global?global:globalThis;var n=null;"undefined"!=typeof WebSocket?n=WebSocket:"undefined"!=typeof MozWebSocket?n=MozWebSocket:"undefined"!=typeof global?n=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window?n=window.WebSocket||window.MozWebSocket:"undefined"!=typeof self&&(n=self.WebSocket||self.MozWebSocket);var r,a=n;!function(e){e[e.BadSampleRate=4e3]="BadSampleRate",e[e.AuthFailed=4001]="AuthFailed",e[e.InsufficientFundsOrFreeAccount=4002]="InsufficientFundsOrFreeAccount",e[e.NonexistentSessionId=4004]="NonexistentSessionId",e[e.SessionExpired=4008]="SessionExpired",e[e.ClosedSession=4010]="ClosedSession",e[e.RateLimited=4029]="RateLimited",e[e.UniqueSessionViolation=4030]="UniqueSessionViolation",e[e.SessionTimeout=4031]="SessionTimeout",e[e.AudioTooShort=4032]="AudioTooShort",e[e.AudioTooLong=4033]="AudioTooLong",e[e.BadJson=4100]="BadJson",e[e.BadSchema=4101]="BadSchema",e[e.TooManyStreams=4102]="TooManyStreams",e[e.Reconnected=4103]="Reconnected",e[e.ReconnectAttemptsExhausted=1013]="ReconnectAttemptsExhausted"}(r||(r={}));const c={[r.BadSampleRate]:"Sample rate must be a positive integer",[r.AuthFailed]:"Not Authorized",[r.InsufficientFundsOrFreeAccount]:"Insufficient funds or you are using a free account. This feature is paid-only and requires you to add a credit card. Please visit https://assemblyai.com/dashboard/ to add a credit card to your account.",[r.NonexistentSessionId]:"Session ID does not exist",[r.SessionExpired]:"Session has expired",[r.ClosedSession]:"Session is closed",[r.RateLimited]:"Rate limited",[r.UniqueSessionViolation]:"Unique session violation",[r.SessionTimeout]:"Session Timeout",[r.AudioTooShort]:"Audio too short",[r.AudioTooLong]:"Audio too long",[r.BadJson]:"Bad JSON",[r.BadSchema]:"Bad schema",[r.TooManyStreams]:"Too many streams",[r.Reconnected]:"Reconnected",[r.ReconnectAttemptsExhausted]:"Reconnect attempts exhausted"};class l extends Error{}class d{constructor(e){var t,s;if(this.listeners={},this.realtimeUrl=null!==(t=e.realtimeUrl)&&void 0!==t?t:"wss://api.assemblyai.com/v2/realtime/ws",this.sampleRate=null!==(s=e.sampleRate)&&void 0!==s?s:16e3,this.wordBoost=e.wordBoost,this.encoding=e.encoding,"token"in e&&e.token&&(this.token=e.token),"apiKey"in e&&e.apiKey&&(this.apiKey=e.apiKey),!this.token&&!this.apiKey)throw new Error("API key or temporary token is required.")}connectionUrl(){const e=new URL(this.realtimeUrl);if("wss:"!==e.protocol)throw new Error("Invalid protocol, must be wss");const t=new URLSearchParams;return this.token&&t.set("token",this.token),t.set("sample_rate",this.sampleRate.toString()),this.wordBoost&&this.wordBoost.length>0&&t.set("word_boost",JSON.stringify(this.wordBoost)),this.encoding&&t.set("encoding",this.encoding),e.search=t.toString(),e}on(e,t){this.listeners[e]=t}connect(){return new Promise((e=>{if(this.socket)throw new Error("Already connected");const t=this.connectionUrl();this.token?this.socket=new a(t.toString()):this.socket=new a(t.toString(),{headers:{Authorization:this.apiKey}}),this.socket.binaryType="arraybuffer",this.socket.onclose=({code:e,reason:t})=>{var s,i;t||e in r&&(t=c[e]),null===(i=(s=this.listeners).close)||void 0===i||i.call(s,e,t)},this.socket.onerror=e=>{var t,s,i,o;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(o=(i=this.listeners).error)||void 0===o||o.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,o,n,r,a,c,d,u,h,f,p,m;const y=JSON.parse(t.toString());if("error"in y)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new l(y.error));else switch(y.message_type){case"SessionBegins":{const t={sessionId:y.session_id,expiresAt:new Date(y.expires_at)};e(t),null===(n=(o=this.listeners).open)||void 0===n||n.call(o,t);break}case"PartialTranscript":y.created=new Date(y.created),null===(a=(r=this.listeners).transcript)||void 0===a||a.call(r,y),null===(d=(c=this.listeners)["transcript.partial"])||void 0===d||d.call(c,y);break;case"FinalTranscript":y.created=new Date(y.created),null===(h=(u=this.listeners).transcript)||void 0===h||h.call(u,y),null===(p=(f=this.listeners)["transcript.final"])||void 0===p||p.call(f,y);break;case"SessionTerminated":null===(m=this.sessionTerminatedResolve)||void 0===m||m.call(this)}}}))}sendAudio(e){if(!this.socket||this.socket.readyState!==a.OPEN)throw new Error("Socket is not open for communication");this.socket.send(e)}stream(){return new o({write:e=>{this.sendAudio(e)}})}close(e=!0){return t(this,void 0,void 0,(function*(){if(this.socket){if(this.socket.readyState===a.OPEN){const t='{"terminate_session": true}';if(e){const e=new Promise((e=>{this.sessionTerminatedResolve=e}));this.socket.send(t),yield e}else this.socket.send(t)}"removeAllListeners"in this.socket&&this.socket.removeAllListeners(),this.socket.close()}this.listeners={},this.socket=void 0}))}}class u extends s{constructor(e){super(e),this.rtFactoryParams=e}createService(e){return this.transcriber(e)}transcriber(e){const t=Object.assign({},e);return t.token||t.apiKey||(t.apiKey=this.rtFactoryParams.apiKey),new d(t)}createTemporaryToken(e){return t(this,void 0,void 0,(function*(){return(yield this.fetchJson("/v2/realtime/token",{method:"POST",body:JSON.stringify(e)})).token}))}}function h(e){return e.startsWith("http")||e.startsWith("https")?null:e.startsWith("file://")?e.substring(7):e.startsWith("file:")?e.substring(5):e}class f extends s{constructor(e,t){super(e),this.files=t}transcribe(e,s){return t(this,void 0,void 0,(function*(){const t=yield this.submit(e);return yield this.waitUntilReady(t.id,s)}))}submit(e){return t(this,void 0,void 0,(function*(){const{audio:t}=e,s=function(e,t){var s={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(s[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(s[i[o]]=e[i[o]])}return s}(e,["audio"]);let i;if("string"==typeof t){const e=h(t);i=null!==e?yield this.files.upload(e):t}else i=yield this.files.upload(t);return yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(Object.assign(Object.assign({},s),{audio_url:i}))})}))}create(e,s){var i;return t(this,void 0,void 0,(function*(){const t=h(e.audio_url);if(null!==t){const s=yield this.files.upload(t);e.audio_url=s}const o=yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(e)});return null===(i=null==s?void 0:s.poll)||void 0===i||i?yield this.waitUntilReady(o.id,s):o}))}waitUntilReady(e,s){var i,o;return t(this,void 0,void 0,(function*(){const t=null!==(i=null==s?void 0:s.pollingInterval)&&void 0!==i?i:3e3,n=null!==(o=null==s?void 0:s.pollingTimeout)&&void 0!==o?o:-1,r=Date.now();for(;;){const s=yield this.get(e);if("completed"===s.status||"error"===s.status)return s;if(n>0&&Date.now()-r>n)throw new Error("Polling timeout");yield new Promise((e=>setTimeout(e,t)))}}))}get(e){return this.fetchJson(`/v2/transcript/${e}`)}list(e){return t(this,void 0,void 0,(function*(){let t="/v2/transcript";"string"==typeof e?t=e:e&&(t=`${t}?${new URLSearchParams(Object.keys(e).map((t=>{var s;return[t,(null===(s=e[t])||void 0===s?void 0:s.toString())||""]})))}`);const s=yield this.fetchJson(t);for(const e of s.transcripts)e.created=new Date(e.created),e.completed&&(e.completed=new Date(e.completed));return s}))}delete(e){return this.fetchJson(`/v2/transcript/${e}`,{method:"DELETE"})}wordSearch(e,t){const s=new URLSearchParams({words:t.join(",")});return this.fetchJson(`/v2/transcript/${e}/word-search?${s.toString()}`)}sentences(e){return this.fetchJson(`/v2/transcript/${e}/sentences`)}paragraphs(e){return this.fetchJson(`/v2/transcript/${e}/paragraphs`)}subtitles(e,s="srt",i){return t(this,void 0,void 0,(function*(){let t=`/v2/transcript/${e}/${s}`;if(i){const e=new URLSearchParams;e.set("chars_per_caption",i.toString()),t+=`?${e.toString()}`}const o=yield this.fetch(t);return yield o.text()}))}redactions(e){return this.fetchJson(`/v2/transcript/${e}/redacted-audio`)}}class p extends s{upload(e){return t(this,void 0,void 0,(function*(){let s;s="string"==typeof e?yield function(e){return t(this,void 0,void 0,(function*(){throw new Error("Interacting with the file system is not supported in this environment.")}))}():e;return(yield this.fetchJson("/v2/upload",{method:"POST",body:s,headers:{"Content-Type":"application/octet-stream"},duplex:"half"})).upload_url}))}}e.AssemblyAI=class{constructor(e){e.baseUrl=e.baseUrl||"https://api.assemblyai.com",e.baseUrl&&e.baseUrl.endsWith("/")&&(e.baseUrl=e.baseUrl.slice(0,-1)),this.files=new p(e),this.transcripts=new f(e,this.files),this.lemur=new i(e),this.realtime=new u(e)}},e.FileService=p,e.LemurService=i,e.RealtimeService=class extends d{},e.RealtimeServiceFactory=class extends u{},e.RealtimeTranscriber=d,e.RealtimeTranscriberFactory=u,e.TranscriptService=f}));
|
package/dist/bun.mjs
CHANGED
|
@@ -309,6 +309,18 @@ class RealtimeTranscriberFactory extends BaseService {
|
|
|
309
309
|
class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
+
function getPath(path) {
|
|
313
|
+
if (path.startsWith("http"))
|
|
314
|
+
return null;
|
|
315
|
+
if (path.startsWith("https"))
|
|
316
|
+
return null;
|
|
317
|
+
if (path.startsWith("file://"))
|
|
318
|
+
return path.substring(7);
|
|
319
|
+
if (path.startsWith("file:"))
|
|
320
|
+
return path.substring(5);
|
|
321
|
+
return path;
|
|
322
|
+
}
|
|
323
|
+
|
|
312
324
|
class TranscriptService extends BaseService {
|
|
313
325
|
constructor(params, files) {
|
|
314
326
|
super(params);
|
|
@@ -493,19 +505,6 @@ class TranscriptService extends BaseService {
|
|
|
493
505
|
return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
|
|
494
506
|
}
|
|
495
507
|
}
|
|
496
|
-
function getPath(path) {
|
|
497
|
-
let url;
|
|
498
|
-
try {
|
|
499
|
-
url = new URL(path);
|
|
500
|
-
if (url.protocol === "file:")
|
|
501
|
-
return url.pathname;
|
|
502
|
-
else
|
|
503
|
-
return null;
|
|
504
|
-
}
|
|
505
|
-
catch {
|
|
506
|
-
return path;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
508
|
|
|
510
509
|
const readFile = async (path) => Bun.file(path).stream();
|
|
511
510
|
|
package/dist/deno.mjs
CHANGED
|
@@ -309,6 +309,18 @@ class RealtimeTranscriberFactory extends BaseService {
|
|
|
309
309
|
class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
+
function getPath(path) {
|
|
313
|
+
if (path.startsWith("http"))
|
|
314
|
+
return null;
|
|
315
|
+
if (path.startsWith("https"))
|
|
316
|
+
return null;
|
|
317
|
+
if (path.startsWith("file://"))
|
|
318
|
+
return path.substring(7);
|
|
319
|
+
if (path.startsWith("file:"))
|
|
320
|
+
return path.substring(5);
|
|
321
|
+
return path;
|
|
322
|
+
}
|
|
323
|
+
|
|
312
324
|
class TranscriptService extends BaseService {
|
|
313
325
|
constructor(params, files) {
|
|
314
326
|
super(params);
|
|
@@ -493,19 +505,6 @@ class TranscriptService extends BaseService {
|
|
|
493
505
|
return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
|
|
494
506
|
}
|
|
495
507
|
}
|
|
496
|
-
function getPath(path) {
|
|
497
|
-
let url;
|
|
498
|
-
try {
|
|
499
|
-
url = new URL(path);
|
|
500
|
-
if (url.protocol === "file:")
|
|
501
|
-
return url.pathname;
|
|
502
|
-
else
|
|
503
|
-
return null;
|
|
504
|
-
}
|
|
505
|
-
catch {
|
|
506
|
-
return path;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
508
|
|
|
510
509
|
const readFile = async (path) => (await Deno.open(path)).readable;
|
|
511
510
|
|
package/dist/index.cjs
CHANGED
|
@@ -364,6 +364,18 @@ class RealtimeTranscriberFactory extends BaseService {
|
|
|
364
364
|
class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
+
function getPath(path) {
|
|
368
|
+
if (path.startsWith("http"))
|
|
369
|
+
return null;
|
|
370
|
+
if (path.startsWith("https"))
|
|
371
|
+
return null;
|
|
372
|
+
if (path.startsWith("file://"))
|
|
373
|
+
return path.substring(7);
|
|
374
|
+
if (path.startsWith("file:"))
|
|
375
|
+
return path.substring(5);
|
|
376
|
+
return path;
|
|
377
|
+
}
|
|
378
|
+
|
|
367
379
|
class TranscriptService extends BaseService {
|
|
368
380
|
constructor(params, files) {
|
|
369
381
|
super(params);
|
|
@@ -565,19 +577,6 @@ class TranscriptService extends BaseService {
|
|
|
565
577
|
return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
|
|
566
578
|
}
|
|
567
579
|
}
|
|
568
|
-
function getPath(path) {
|
|
569
|
-
let url;
|
|
570
|
-
try {
|
|
571
|
-
url = new URL(path);
|
|
572
|
-
if (url.protocol === "file:")
|
|
573
|
-
return url.pathname;
|
|
574
|
-
else
|
|
575
|
-
return null;
|
|
576
|
-
}
|
|
577
|
-
catch (_a) {
|
|
578
|
-
return path;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
580
|
|
|
582
581
|
const readFile = function (
|
|
583
582
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
package/dist/index.mjs
CHANGED
|
@@ -362,6 +362,18 @@ class RealtimeTranscriberFactory extends BaseService {
|
|
|
362
362
|
class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
+
function getPath(path) {
|
|
366
|
+
if (path.startsWith("http"))
|
|
367
|
+
return null;
|
|
368
|
+
if (path.startsWith("https"))
|
|
369
|
+
return null;
|
|
370
|
+
if (path.startsWith("file://"))
|
|
371
|
+
return path.substring(7);
|
|
372
|
+
if (path.startsWith("file:"))
|
|
373
|
+
return path.substring(5);
|
|
374
|
+
return path;
|
|
375
|
+
}
|
|
376
|
+
|
|
365
377
|
class TranscriptService extends BaseService {
|
|
366
378
|
constructor(params, files) {
|
|
367
379
|
super(params);
|
|
@@ -563,19 +575,6 @@ class TranscriptService extends BaseService {
|
|
|
563
575
|
return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
|
|
564
576
|
}
|
|
565
577
|
}
|
|
566
|
-
function getPath(path) {
|
|
567
|
-
let url;
|
|
568
|
-
try {
|
|
569
|
-
url = new URL(path);
|
|
570
|
-
if (url.protocol === "file:")
|
|
571
|
-
return url.pathname;
|
|
572
|
-
else
|
|
573
|
-
return null;
|
|
574
|
-
}
|
|
575
|
-
catch (_a) {
|
|
576
|
-
return path;
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
578
|
|
|
580
579
|
const readFile = function (
|
|
581
580
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
package/dist/node.cjs
CHANGED
|
@@ -308,6 +308,18 @@ class RealtimeTranscriberFactory extends BaseService {
|
|
|
308
308
|
class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
+
function getPath(path) {
|
|
312
|
+
if (path.startsWith("http"))
|
|
313
|
+
return null;
|
|
314
|
+
if (path.startsWith("https"))
|
|
315
|
+
return null;
|
|
316
|
+
if (path.startsWith("file://"))
|
|
317
|
+
return path.substring(7);
|
|
318
|
+
if (path.startsWith("file:"))
|
|
319
|
+
return path.substring(5);
|
|
320
|
+
return path;
|
|
321
|
+
}
|
|
322
|
+
|
|
311
323
|
class TranscriptService extends BaseService {
|
|
312
324
|
constructor(params, files) {
|
|
313
325
|
super(params);
|
|
@@ -492,19 +504,6 @@ class TranscriptService extends BaseService {
|
|
|
492
504
|
return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
|
|
493
505
|
}
|
|
494
506
|
}
|
|
495
|
-
function getPath(path) {
|
|
496
|
-
let url;
|
|
497
|
-
try {
|
|
498
|
-
url = new URL(path);
|
|
499
|
-
if (url.protocol === "file:")
|
|
500
|
-
return url.pathname;
|
|
501
|
-
else
|
|
502
|
-
return null;
|
|
503
|
-
}
|
|
504
|
-
catch {
|
|
505
|
-
return path;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
507
|
|
|
509
508
|
const readFile = async (path) => stream.Readable.toWeb(fs.createReadStream(path));
|
|
510
509
|
|
package/dist/node.mjs
CHANGED
|
@@ -306,6 +306,18 @@ class RealtimeTranscriberFactory extends BaseService {
|
|
|
306
306
|
class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
+
function getPath(path) {
|
|
310
|
+
if (path.startsWith("http"))
|
|
311
|
+
return null;
|
|
312
|
+
if (path.startsWith("https"))
|
|
313
|
+
return null;
|
|
314
|
+
if (path.startsWith("file://"))
|
|
315
|
+
return path.substring(7);
|
|
316
|
+
if (path.startsWith("file:"))
|
|
317
|
+
return path.substring(5);
|
|
318
|
+
return path;
|
|
319
|
+
}
|
|
320
|
+
|
|
309
321
|
class TranscriptService extends BaseService {
|
|
310
322
|
constructor(params, files) {
|
|
311
323
|
super(params);
|
|
@@ -490,19 +502,6 @@ class TranscriptService extends BaseService {
|
|
|
490
502
|
return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
|
|
491
503
|
}
|
|
492
504
|
}
|
|
493
|
-
function getPath(path) {
|
|
494
|
-
let url;
|
|
495
|
-
try {
|
|
496
|
-
url = new URL(path);
|
|
497
|
-
if (url.protocol === "file:")
|
|
498
|
-
return url.pathname;
|
|
499
|
-
else
|
|
500
|
-
return null;
|
|
501
|
-
}
|
|
502
|
-
catch {
|
|
503
|
-
return path;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
505
|
|
|
507
506
|
const readFile = async (path) => Readable.toWeb(createReadStream(path));
|
|
508
507
|
|
|
@@ -991,6 +991,11 @@ export type SeverityScoreSummary = {
|
|
|
991
991
|
/** Format: double */
|
|
992
992
|
medium: number;
|
|
993
993
|
};
|
|
994
|
+
/**
|
|
995
|
+
* @description The speech model to use for the transcription.
|
|
996
|
+
* @enum {string}
|
|
997
|
+
*/
|
|
998
|
+
export type SpeechModel = "nano";
|
|
994
999
|
/**
|
|
995
1000
|
* @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.
|
|
996
1001
|
* @enum {string}
|
|
@@ -1187,6 +1192,7 @@ export type TopicDetectionResult = {
|
|
|
1187
1192
|
* @description A transcript object
|
|
1188
1193
|
* @example {
|
|
1189
1194
|
* "id": "9ea68fd3-f953-42c1-9742-976c447fb463",
|
|
1195
|
+
* "speech_model": null,
|
|
1190
1196
|
* "language_model": "assemblyai_default",
|
|
1191
1197
|
* "acoustic_model": "assemblyai_default",
|
|
1192
1198
|
* "language_code": "en_us",
|
|
@@ -1989,6 +1995,11 @@ export type Transcript = {
|
|
|
1989
1995
|
speaker_labels?: boolean | null;
|
|
1990
1996
|
/** @description Tell the speaker label model how many speakers it should attempt to identify, up to 10. See [Speaker diarization](https://www.assemblyai.com/docs/models/speaker-diarization) for more details. */
|
|
1991
1997
|
speakers_expected?: number | null;
|
|
1998
|
+
/**
|
|
1999
|
+
* @description The speech model used for the transcription. When `null`, the default model is used.
|
|
2000
|
+
* @default null
|
|
2001
|
+
*/
|
|
2002
|
+
speech_model: SpeechModel | null;
|
|
1992
2003
|
/**
|
|
1993
2004
|
* Format: float
|
|
1994
2005
|
* @description Defaults to null. Reject audio files that contain less than this fraction of speech.
|
|
@@ -2123,6 +2134,7 @@ export type TranscriptListItem = {
|
|
|
2123
2134
|
/**
|
|
2124
2135
|
* @description The parameters for creating a transcript
|
|
2125
2136
|
* @example {
|
|
2137
|
+
* "speech_model": null,
|
|
2126
2138
|
* "language_code": "en_us",
|
|
2127
2139
|
* "punctuate": true,
|
|
2128
2140
|
* "format_text": true,
|
|
@@ -2228,6 +2240,11 @@ export type TranscriptOptionalParams = {
|
|
|
2228
2240
|
* @default null
|
|
2229
2241
|
*/
|
|
2230
2242
|
speakers_expected?: number | null;
|
|
2243
|
+
/**
|
|
2244
|
+
* @description The speech model to use for the transcription. When `null`, the default model is used.
|
|
2245
|
+
* @default null
|
|
2246
|
+
*/
|
|
2247
|
+
speech_model?: SpeechModel | null;
|
|
2231
2248
|
/**
|
|
2232
2249
|
* Format: float
|
|
2233
2250
|
* @description Reject audio files that contain less than this fraction of speech.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPath(path: string): string | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblyai",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.3",
|
|
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"
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
SubmitParams,
|
|
22
22
|
} from "../..";
|
|
23
23
|
import { FileService } from "../files";
|
|
24
|
+
import { getPath } from "../../utils/path";
|
|
24
25
|
|
|
25
26
|
export class TranscriptService
|
|
26
27
|
extends BaseService
|
|
@@ -249,14 +250,3 @@ export class TranscriptService
|
|
|
249
250
|
);
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
|
-
|
|
253
|
-
function getPath(path: string) {
|
|
254
|
-
let url: URL;
|
|
255
|
-
try {
|
|
256
|
-
url = new URL(path);
|
|
257
|
-
if (url.protocol === "file:") return url.pathname;
|
|
258
|
-
else return null;
|
|
259
|
-
} catch {
|
|
260
|
-
return path;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
@@ -1102,6 +1102,12 @@ export type SeverityScoreSummary = {
|
|
|
1102
1102
|
medium: number;
|
|
1103
1103
|
};
|
|
1104
1104
|
|
|
1105
|
+
/**
|
|
1106
|
+
* @description The speech model to use for the transcription.
|
|
1107
|
+
* @enum {string}
|
|
1108
|
+
*/
|
|
1109
|
+
export type SpeechModel = "nano";
|
|
1110
|
+
|
|
1105
1111
|
/**
|
|
1106
1112
|
* @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.
|
|
1107
1113
|
* @enum {string}
|
|
@@ -1310,6 +1316,7 @@ export type TopicDetectionResult = {
|
|
|
1310
1316
|
* @description A transcript object
|
|
1311
1317
|
* @example {
|
|
1312
1318
|
* "id": "9ea68fd3-f953-42c1-9742-976c447fb463",
|
|
1319
|
+
* "speech_model": null,
|
|
1313
1320
|
* "language_model": "assemblyai_default",
|
|
1314
1321
|
* "acoustic_model": "assemblyai_default",
|
|
1315
1322
|
* "language_code": "en_us",
|
|
@@ -2112,6 +2119,11 @@ export type Transcript = {
|
|
|
2112
2119
|
speaker_labels?: boolean | null;
|
|
2113
2120
|
/** @description Tell the speaker label model how many speakers it should attempt to identify, up to 10. See [Speaker diarization](https://www.assemblyai.com/docs/models/speaker-diarization) for more details. */
|
|
2114
2121
|
speakers_expected?: number | null;
|
|
2122
|
+
/**
|
|
2123
|
+
* @description The speech model used for the transcription. When `null`, the default model is used.
|
|
2124
|
+
* @default null
|
|
2125
|
+
*/
|
|
2126
|
+
speech_model: SpeechModel | null;
|
|
2115
2127
|
/**
|
|
2116
2128
|
* Format: float
|
|
2117
2129
|
* @description Defaults to null. Reject audio files that contain less than this fraction of speech.
|
|
@@ -2272,6 +2284,7 @@ export type TranscriptListItem = {
|
|
|
2272
2284
|
/**
|
|
2273
2285
|
* @description The parameters for creating a transcript
|
|
2274
2286
|
* @example {
|
|
2287
|
+
* "speech_model": null,
|
|
2275
2288
|
* "language_code": "en_us",
|
|
2276
2289
|
* "punctuate": true,
|
|
2277
2290
|
* "format_text": true,
|
|
@@ -2377,6 +2390,11 @@ export type TranscriptOptionalParams = {
|
|
|
2377
2390
|
* @default null
|
|
2378
2391
|
*/
|
|
2379
2392
|
speakers_expected?: number | null;
|
|
2393
|
+
/**
|
|
2394
|
+
* @description The speech model to use for the transcription. When `null`, the default model is used.
|
|
2395
|
+
* @default null
|
|
2396
|
+
*/
|
|
2397
|
+
speech_model?: SpeechModel | null;
|
|
2380
2398
|
/**
|
|
2381
2399
|
* Format: float
|
|
2382
2400
|
* @description Reject audio files that contain less than this fraction of speech.
|