assemblyai 4.12.2 → 4.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.cjs CHANGED
@@ -22,7 +22,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
22
22
  defaultUserAgentString += navigator.userAgent;
23
23
  }
24
24
  const defaultUserAgent = {
25
- sdk: { name: "JavaScript", version: "4.12.2" },
25
+ sdk: { name: "JavaScript", version: "4.13.0" },
26
26
  };
27
27
  if (typeof process !== "undefined") {
28
28
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -198,9 +198,48 @@ const RealtimeErrorMessages = {
198
198
  class RealtimeError extends Error {
199
199
  }
200
200
 
201
+ const StreamingErrorType = {
202
+ BadSampleRate: 4000,
203
+ AuthFailed: 4001,
204
+ InsufficientFunds: 4002,
205
+ FreeTierUser: 4003,
206
+ NonexistentSessionId: 4004,
207
+ SessionExpired: 4008,
208
+ ClosedSession: 4010,
209
+ RateLimited: 4029,
210
+ UniqueSessionViolation: 4030,
211
+ SessionTimeout: 4031,
212
+ AudioTooShort: 4032,
213
+ AudioTooLong: 4033,
214
+ AudioTooSmallToTranscode: 4034,
215
+ BadSchema: 4101,
216
+ TooManyStreams: 4102,
217
+ Reconnected: 4103,
218
+ };
219
+ const StreamingErrorMessages = {
220
+ [StreamingErrorType.BadSampleRate]: "Sample rate must be a positive integer",
221
+ [StreamingErrorType.AuthFailed]: "Not Authorized",
222
+ [StreamingErrorType.InsufficientFunds]: "Insufficient funds",
223
+ [StreamingErrorType.FreeTierUser]: "This feature is paid-only and requires you to add a credit card. Please visit https://app.assemblyai.com/ to add a credit card to your account.",
224
+ [StreamingErrorType.NonexistentSessionId]: "Session ID does not exist",
225
+ [StreamingErrorType.SessionExpired]: "Session has expired",
226
+ [StreamingErrorType.ClosedSession]: "Session is closed",
227
+ [StreamingErrorType.RateLimited]: "Rate limited",
228
+ [StreamingErrorType.UniqueSessionViolation]: "Unique session violation",
229
+ [StreamingErrorType.SessionTimeout]: "Session Timeout",
230
+ [StreamingErrorType.AudioTooShort]: "Audio too short",
231
+ [StreamingErrorType.AudioTooLong]: "Audio too long",
232
+ [StreamingErrorType.AudioTooSmallToTranscode]: "Audio too small to transcode",
233
+ [StreamingErrorType.BadSchema]: "Bad schema",
234
+ [StreamingErrorType.TooManyStreams]: "Too many streams",
235
+ [StreamingErrorType.Reconnected]: "This session has been reconnected. This WebSocket is no longer valid.",
236
+ };
237
+ class StreamingError extends Error {
238
+ }
239
+
201
240
  const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
202
241
  const forceEndOfUtteranceMessage = `{"force_end_utterance":true}`;
203
- const terminateSessionMessage = `{"terminate_session":true}`;
242
+ const terminateSessionMessage$1 = `{"terminate_session":true}`;
204
243
  /**
205
244
  * RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
206
245
  */
@@ -389,11 +428,11 @@ class RealtimeTranscriber {
389
428
  const sessionTerminatedPromise = new Promise((resolve) => {
390
429
  this.sessionTerminatedResolve = resolve;
391
430
  });
392
- this.socket.send(terminateSessionMessage);
431
+ this.socket.send(terminateSessionMessage$1);
393
432
  await sessionTerminatedPromise;
394
433
  }
395
434
  else {
396
- this.socket.send(terminateSessionMessage);
435
+ this.socket.send(terminateSessionMessage$1);
397
436
  }
398
437
  }
399
438
  if (this.socket?.removeAllListeners)
@@ -726,7 +765,168 @@ function dataUrlToBlob(dataUrl) {
726
765
  return new Blob([u8arr], { type: mime });
727
766
  }
728
767
 
768
+ const defaultStreamingUrl$1 = "wss://streaming.assemblyai.com/v3/ws";
769
+ const terminateSessionMessage = `{"type":"Terminate"}`;
770
+ class StreamingTranscriber {
771
+ constructor(params) {
772
+ this.listeners = {};
773
+ this.params = {
774
+ ...params,
775
+ websocketBaseUrl: params.websocketBaseUrl || defaultStreamingUrl$1,
776
+ };
777
+ if ("token" in params && params.token)
778
+ this.token = params.token;
779
+ if ("apiKey" in params && params.apiKey)
780
+ this.apiKey = params.apiKey;
781
+ if (!(this.token || this.apiKey)) {
782
+ throw new Error("API key or temporary token is required.");
783
+ }
784
+ }
785
+ connectionUrl() {
786
+ const url = new URL(this.params.websocketBaseUrl ?? "");
787
+ if (url.protocol !== "wss:") {
788
+ throw new Error("Invalid protocol, must be wss");
789
+ }
790
+ const searchParams = new URLSearchParams();
791
+ searchParams.set("sample_rate", this.params.sampleRate.toString());
792
+ if (this.params.endOfTurnConfidenceThreshold) {
793
+ searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
794
+ }
795
+ if (this.params.minEndOfTurnSilenceWhenConfident) {
796
+ searchParams.set("min_end_of_turn_silence_when_confident", this.params.minEndOfTurnSilenceWhenConfident.toString());
797
+ }
798
+ if (this.params.maxTurnSilence) {
799
+ searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
800
+ }
801
+ if (this.params.formatTurns) {
802
+ searchParams.set("format_turns", this.params.formatTurns.toString());
803
+ }
804
+ url.search = searchParams.toString();
805
+ return url;
806
+ }
807
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
808
+ on(event, listener) {
809
+ this.listeners[event] = listener;
810
+ }
811
+ connect() {
812
+ return new Promise((resolve) => {
813
+ if (this.socket) {
814
+ throw new Error("Already connected");
815
+ }
816
+ const url = this.connectionUrl();
817
+ this.socket = factory(url.toString(), {
818
+ headers: { Authorization: this.token || this.apiKey },
819
+ });
820
+ this.socket.binaryType = "arraybuffer";
821
+ this.socket.onopen = () => { };
822
+ this.socket.onclose = ({ code, reason }) => {
823
+ if (!reason) {
824
+ if (code in StreamingErrorMessages) {
825
+ reason = StreamingErrorMessages[code];
826
+ }
827
+ }
828
+ this.listeners.close?.(code, reason);
829
+ };
830
+ this.socket.onerror = (event) => {
831
+ if (event.error)
832
+ this.listeners.error?.(event.error);
833
+ else
834
+ this.listeners.error?.(new Error(event.message));
835
+ };
836
+ this.socket.onmessage = ({ data }) => {
837
+ const message = JSON.parse(data.toString());
838
+ if ("error" in message) {
839
+ this.listeners.error?.(new StreamingError(message.error));
840
+ return;
841
+ }
842
+ switch (message.type) {
843
+ case "Begin": {
844
+ resolve(message);
845
+ this.listeners.open?.(message);
846
+ break;
847
+ }
848
+ case "Turn": {
849
+ this.listeners.turn?.(message);
850
+ break;
851
+ }
852
+ case "Termination": {
853
+ this.sessionTerminatedResolve?.();
854
+ break;
855
+ }
856
+ }
857
+ };
858
+ });
859
+ }
860
+ stream() {
861
+ return new web.WritableStream({
862
+ write: (chunk) => {
863
+ this.sendAudio(chunk);
864
+ },
865
+ });
866
+ }
867
+ sendAudio(audio) {
868
+ this.send(audio);
869
+ }
870
+ send(data) {
871
+ if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
872
+ throw new Error("Socket is not open for communication");
873
+ }
874
+ this.socket.send(data);
875
+ }
876
+ async close(waitForSessionTermination = true) {
877
+ if (this.socket) {
878
+ if (this.socket.readyState === this.socket.OPEN) {
879
+ if (waitForSessionTermination) {
880
+ const sessionTerminatedPromise = new Promise((resolve) => {
881
+ this.sessionTerminatedResolve = resolve;
882
+ });
883
+ this.socket.send(terminateSessionMessage);
884
+ await sessionTerminatedPromise;
885
+ }
886
+ else {
887
+ this.socket.send(terminateSessionMessage);
888
+ }
889
+ }
890
+ if (this.socket?.removeAllListeners)
891
+ this.socket.removeAllListeners();
892
+ this.socket.close();
893
+ }
894
+ this.listeners = {};
895
+ this.socket = undefined;
896
+ }
897
+ }
898
+
899
+ class StreamingTranscriberFactory extends BaseService {
900
+ constructor(params) {
901
+ super(params);
902
+ this.baseServiceParams = params;
903
+ }
904
+ transcriber(params) {
905
+ const serviceParams = { ...params };
906
+ if (!serviceParams.token && !serviceParams.apiKey) {
907
+ serviceParams.apiKey = this.baseServiceParams.apiKey;
908
+ }
909
+ return new StreamingTranscriber(serviceParams);
910
+ }
911
+ async createTemporaryToken(params) {
912
+ const searchParams = new URLSearchParams();
913
+ // Add each param to the search params
914
+ Object.entries(params).forEach(([key, value]) => {
915
+ if (value !== undefined && value !== null) {
916
+ searchParams.append(key, String(value));
917
+ }
918
+ });
919
+ const queryString = searchParams.toString();
920
+ const url = queryString ? `/v3/token?${queryString}` : "/v3/token";
921
+ const data = await this.fetchJson(url, {
922
+ method: "GET",
923
+ });
924
+ return data.token;
925
+ }
926
+ }
927
+
729
928
  const defaultBaseUrl = "https://api.assemblyai.com";
929
+ const defaultStreamingUrl = "https://streaming.assemblyai.com";
730
930
  class AssemblyAI {
731
931
  /**
732
932
  * Create a new AssemblyAI client.
@@ -741,6 +941,10 @@ class AssemblyAI {
741
941
  this.transcripts = new TranscriptService(params, this.files);
742
942
  this.lemur = new LemurService(params);
743
943
  this.realtime = new RealtimeTranscriberFactory(params);
944
+ this.streaming = new StreamingTranscriberFactory({
945
+ ...params,
946
+ baseUrl: params.streamingBaseUrl || defaultStreamingUrl,
947
+ });
744
948
  }
745
949
  }
746
950
 
@@ -751,4 +955,5 @@ exports.RealtimeService = RealtimeService;
751
955
  exports.RealtimeServiceFactory = RealtimeServiceFactory;
752
956
  exports.RealtimeTranscriber = RealtimeTranscriber;
753
957
  exports.RealtimeTranscriberFactory = RealtimeTranscriberFactory;
958
+ exports.StreamingTranscriber = StreamingTranscriber;
754
959
  exports.TranscriptService = TranscriptService;
package/dist/node.mjs CHANGED
@@ -20,7 +20,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
20
20
  defaultUserAgentString += navigator.userAgent;
21
21
  }
22
22
  const defaultUserAgent = {
23
- sdk: { name: "JavaScript", version: "4.12.2" },
23
+ sdk: { name: "JavaScript", version: "4.13.0" },
24
24
  };
25
25
  if (typeof process !== "undefined") {
26
26
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -196,9 +196,48 @@ const RealtimeErrorMessages = {
196
196
  class RealtimeError extends Error {
197
197
  }
198
198
 
199
+ const StreamingErrorType = {
200
+ BadSampleRate: 4000,
201
+ AuthFailed: 4001,
202
+ InsufficientFunds: 4002,
203
+ FreeTierUser: 4003,
204
+ NonexistentSessionId: 4004,
205
+ SessionExpired: 4008,
206
+ ClosedSession: 4010,
207
+ RateLimited: 4029,
208
+ UniqueSessionViolation: 4030,
209
+ SessionTimeout: 4031,
210
+ AudioTooShort: 4032,
211
+ AudioTooLong: 4033,
212
+ AudioTooSmallToTranscode: 4034,
213
+ BadSchema: 4101,
214
+ TooManyStreams: 4102,
215
+ Reconnected: 4103,
216
+ };
217
+ const StreamingErrorMessages = {
218
+ [StreamingErrorType.BadSampleRate]: "Sample rate must be a positive integer",
219
+ [StreamingErrorType.AuthFailed]: "Not Authorized",
220
+ [StreamingErrorType.InsufficientFunds]: "Insufficient funds",
221
+ [StreamingErrorType.FreeTierUser]: "This feature is paid-only and requires you to add a credit card. Please visit https://app.assemblyai.com/ to add a credit card to your account.",
222
+ [StreamingErrorType.NonexistentSessionId]: "Session ID does not exist",
223
+ [StreamingErrorType.SessionExpired]: "Session has expired",
224
+ [StreamingErrorType.ClosedSession]: "Session is closed",
225
+ [StreamingErrorType.RateLimited]: "Rate limited",
226
+ [StreamingErrorType.UniqueSessionViolation]: "Unique session violation",
227
+ [StreamingErrorType.SessionTimeout]: "Session Timeout",
228
+ [StreamingErrorType.AudioTooShort]: "Audio too short",
229
+ [StreamingErrorType.AudioTooLong]: "Audio too long",
230
+ [StreamingErrorType.AudioTooSmallToTranscode]: "Audio too small to transcode",
231
+ [StreamingErrorType.BadSchema]: "Bad schema",
232
+ [StreamingErrorType.TooManyStreams]: "Too many streams",
233
+ [StreamingErrorType.Reconnected]: "This session has been reconnected. This WebSocket is no longer valid.",
234
+ };
235
+ class StreamingError extends Error {
236
+ }
237
+
199
238
  const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
200
239
  const forceEndOfUtteranceMessage = `{"force_end_utterance":true}`;
201
- const terminateSessionMessage = `{"terminate_session":true}`;
240
+ const terminateSessionMessage$1 = `{"terminate_session":true}`;
202
241
  /**
203
242
  * RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
204
243
  */
@@ -387,11 +426,11 @@ class RealtimeTranscriber {
387
426
  const sessionTerminatedPromise = new Promise((resolve) => {
388
427
  this.sessionTerminatedResolve = resolve;
389
428
  });
390
- this.socket.send(terminateSessionMessage);
429
+ this.socket.send(terminateSessionMessage$1);
391
430
  await sessionTerminatedPromise;
392
431
  }
393
432
  else {
394
- this.socket.send(terminateSessionMessage);
433
+ this.socket.send(terminateSessionMessage$1);
395
434
  }
396
435
  }
397
436
  if (this.socket?.removeAllListeners)
@@ -724,7 +763,168 @@ function dataUrlToBlob(dataUrl) {
724
763
  return new Blob([u8arr], { type: mime });
725
764
  }
726
765
 
766
+ const defaultStreamingUrl$1 = "wss://streaming.assemblyai.com/v3/ws";
767
+ const terminateSessionMessage = `{"type":"Terminate"}`;
768
+ class StreamingTranscriber {
769
+ constructor(params) {
770
+ this.listeners = {};
771
+ this.params = {
772
+ ...params,
773
+ websocketBaseUrl: params.websocketBaseUrl || defaultStreamingUrl$1,
774
+ };
775
+ if ("token" in params && params.token)
776
+ this.token = params.token;
777
+ if ("apiKey" in params && params.apiKey)
778
+ this.apiKey = params.apiKey;
779
+ if (!(this.token || this.apiKey)) {
780
+ throw new Error("API key or temporary token is required.");
781
+ }
782
+ }
783
+ connectionUrl() {
784
+ const url = new URL(this.params.websocketBaseUrl ?? "");
785
+ if (url.protocol !== "wss:") {
786
+ throw new Error("Invalid protocol, must be wss");
787
+ }
788
+ const searchParams = new URLSearchParams();
789
+ searchParams.set("sample_rate", this.params.sampleRate.toString());
790
+ if (this.params.endOfTurnConfidenceThreshold) {
791
+ searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
792
+ }
793
+ if (this.params.minEndOfTurnSilenceWhenConfident) {
794
+ searchParams.set("min_end_of_turn_silence_when_confident", this.params.minEndOfTurnSilenceWhenConfident.toString());
795
+ }
796
+ if (this.params.maxTurnSilence) {
797
+ searchParams.set("max_turn_silence", this.params.maxTurnSilence.toString());
798
+ }
799
+ if (this.params.formatTurns) {
800
+ searchParams.set("format_turns", this.params.formatTurns.toString());
801
+ }
802
+ url.search = searchParams.toString();
803
+ return url;
804
+ }
805
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
806
+ on(event, listener) {
807
+ this.listeners[event] = listener;
808
+ }
809
+ connect() {
810
+ return new Promise((resolve) => {
811
+ if (this.socket) {
812
+ throw new Error("Already connected");
813
+ }
814
+ const url = this.connectionUrl();
815
+ this.socket = factory(url.toString(), {
816
+ headers: { Authorization: this.token || this.apiKey },
817
+ });
818
+ this.socket.binaryType = "arraybuffer";
819
+ this.socket.onopen = () => { };
820
+ this.socket.onclose = ({ code, reason }) => {
821
+ if (!reason) {
822
+ if (code in StreamingErrorMessages) {
823
+ reason = StreamingErrorMessages[code];
824
+ }
825
+ }
826
+ this.listeners.close?.(code, reason);
827
+ };
828
+ this.socket.onerror = (event) => {
829
+ if (event.error)
830
+ this.listeners.error?.(event.error);
831
+ else
832
+ this.listeners.error?.(new Error(event.message));
833
+ };
834
+ this.socket.onmessage = ({ data }) => {
835
+ const message = JSON.parse(data.toString());
836
+ if ("error" in message) {
837
+ this.listeners.error?.(new StreamingError(message.error));
838
+ return;
839
+ }
840
+ switch (message.type) {
841
+ case "Begin": {
842
+ resolve(message);
843
+ this.listeners.open?.(message);
844
+ break;
845
+ }
846
+ case "Turn": {
847
+ this.listeners.turn?.(message);
848
+ break;
849
+ }
850
+ case "Termination": {
851
+ this.sessionTerminatedResolve?.();
852
+ break;
853
+ }
854
+ }
855
+ };
856
+ });
857
+ }
858
+ stream() {
859
+ return new WritableStream({
860
+ write: (chunk) => {
861
+ this.sendAudio(chunk);
862
+ },
863
+ });
864
+ }
865
+ sendAudio(audio) {
866
+ this.send(audio);
867
+ }
868
+ send(data) {
869
+ if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
870
+ throw new Error("Socket is not open for communication");
871
+ }
872
+ this.socket.send(data);
873
+ }
874
+ async close(waitForSessionTermination = true) {
875
+ if (this.socket) {
876
+ if (this.socket.readyState === this.socket.OPEN) {
877
+ if (waitForSessionTermination) {
878
+ const sessionTerminatedPromise = new Promise((resolve) => {
879
+ this.sessionTerminatedResolve = resolve;
880
+ });
881
+ this.socket.send(terminateSessionMessage);
882
+ await sessionTerminatedPromise;
883
+ }
884
+ else {
885
+ this.socket.send(terminateSessionMessage);
886
+ }
887
+ }
888
+ if (this.socket?.removeAllListeners)
889
+ this.socket.removeAllListeners();
890
+ this.socket.close();
891
+ }
892
+ this.listeners = {};
893
+ this.socket = undefined;
894
+ }
895
+ }
896
+
897
+ class StreamingTranscriberFactory extends BaseService {
898
+ constructor(params) {
899
+ super(params);
900
+ this.baseServiceParams = params;
901
+ }
902
+ transcriber(params) {
903
+ const serviceParams = { ...params };
904
+ if (!serviceParams.token && !serviceParams.apiKey) {
905
+ serviceParams.apiKey = this.baseServiceParams.apiKey;
906
+ }
907
+ return new StreamingTranscriber(serviceParams);
908
+ }
909
+ async createTemporaryToken(params) {
910
+ const searchParams = new URLSearchParams();
911
+ // Add each param to the search params
912
+ Object.entries(params).forEach(([key, value]) => {
913
+ if (value !== undefined && value !== null) {
914
+ searchParams.append(key, String(value));
915
+ }
916
+ });
917
+ const queryString = searchParams.toString();
918
+ const url = queryString ? `/v3/token?${queryString}` : "/v3/token";
919
+ const data = await this.fetchJson(url, {
920
+ method: "GET",
921
+ });
922
+ return data.token;
923
+ }
924
+ }
925
+
727
926
  const defaultBaseUrl = "https://api.assemblyai.com";
927
+ const defaultStreamingUrl = "https://streaming.assemblyai.com";
728
928
  class AssemblyAI {
729
929
  /**
730
930
  * Create a new AssemblyAI client.
@@ -739,7 +939,11 @@ class AssemblyAI {
739
939
  this.transcripts = new TranscriptService(params, this.files);
740
940
  this.lemur = new LemurService(params);
741
941
  this.realtime = new RealtimeTranscriberFactory(params);
942
+ this.streaming = new StreamingTranscriberFactory({
943
+ ...params,
944
+ baseUrl: params.streamingBaseUrl || defaultStreamingUrl,
945
+ });
742
946
  }
743
947
  }
744
948
 
745
- export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, RealtimeTranscriber, RealtimeTranscriberFactory, TranscriptService };
949
+ export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, RealtimeTranscriber, RealtimeTranscriberFactory, StreamingTranscriber, TranscriptService };
@@ -3,6 +3,7 @@ import { LemurService } from "./lemur";
3
3
  import { RealtimeTranscriber, RealtimeTranscriberFactory, RealtimeService, RealtimeServiceFactory } from "./realtime";
4
4
  import { TranscriptService } from "./transcripts";
5
5
  import { FileService } from "./files";
6
+ import { StreamingTranscriber, StreamingTranscriberFactory } from "./streaming";
6
7
  declare class AssemblyAI {
7
8
  /**
8
9
  * The files service.
@@ -20,10 +21,14 @@ declare class AssemblyAI {
20
21
  * The realtime service.
21
22
  */
22
23
  realtime: RealtimeTranscriberFactory;
24
+ /**
25
+ * The streaming service.
26
+ */
27
+ streaming: StreamingTranscriberFactory;
23
28
  /**
24
29
  * Create a new AssemblyAI client.
25
30
  * @param params - The parameters for the service, including the API key and base URL, if any.
26
31
  */
27
32
  constructor(params: BaseServiceParams);
28
33
  }
29
- export { AssemblyAI, LemurService, RealtimeTranscriberFactory, RealtimeTranscriber, RealtimeServiceFactory, RealtimeService, TranscriptService, FileService, };
34
+ export { AssemblyAI, LemurService, RealtimeTranscriberFactory, RealtimeTranscriber, RealtimeServiceFactory, RealtimeService, TranscriptService, FileService, StreamingTranscriber, };
@@ -0,0 +1,11 @@
1
+ import { BaseServiceParams, StreamingTokenParams, StreamingTranscriberParams } from "../..";
2
+ import { StreamingTranscriber } from "./service";
3
+ import { BaseService } from "../base";
4
+ export declare class StreamingTranscriberFactory extends BaseService {
5
+ private baseServiceParams;
6
+ constructor(params: BaseServiceParams);
7
+ transcriber(params: StreamingTranscriberParams): StreamingTranscriber;
8
+ createTemporaryToken(params: StreamingTokenParams): Promise<string>;
9
+ }
10
+ export declare class StreamingServiceFactory extends StreamingTranscriberFactory {
11
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./factory";
2
+ export * from "./service";
@@ -0,0 +1,20 @@
1
+ import { StreamingTranscriberParams, AudioData, BeginEvent, TurnEvent } from "../..";
2
+ export declare class StreamingTranscriber {
3
+ private apiKey?;
4
+ private token?;
5
+ private params;
6
+ private socket?;
7
+ private listeners;
8
+ private sessionTerminatedResolve?;
9
+ constructor(params: StreamingTranscriberParams);
10
+ private connectionUrl;
11
+ on(event: "open", listener: (event: BeginEvent) => void): void;
12
+ on(event: "turn", listener: (event: TurnEvent) => void): void;
13
+ on(event: "error", listener: (error: Error) => void): void;
14
+ on(event: "close", listener: (code: number, reason: string) => void): void;
15
+ connect(): Promise<BeginEvent>;
16
+ stream(): WritableStream<AudioData>;
17
+ sendAudio(audio: AudioData): void;
18
+ private send;
19
+ close(waitForSessionTermination?: boolean): Promise<void>;
20
+ }
@@ -1,8 +1,9 @@
1
1
  export * from "./files";
2
2
  export * from "./transcripts";
3
3
  export * from "./realtime";
4
- export * from "./services";
5
4
  export * from "./asyncapi.generated";
5
+ export * from "./streaming";
6
+ export * from "./services";
6
7
  export * from "./openapi.generated";
7
8
  export * from "./deprecated";
8
9
  export type UserAgentItem = {
@@ -2,6 +2,7 @@ import { UserAgent } from "..";
2
2
  type BaseServiceParams = {
3
3
  apiKey: string;
4
4
  baseUrl?: string;
5
+ streamingBaseUrl?: string;
5
6
  /**
6
7
  * The AssemblyAI user agent to use for requests.
7
8
  * The provided components will be merged into the default AssemblyAI user agent.
@@ -0,0 +1,69 @@
1
+ export type StreamingTranscriberParams = {
2
+ websocketBaseUrl?: string;
3
+ apiKey?: string;
4
+ token?: string;
5
+ sampleRate: number;
6
+ endOfTurnConfidenceThreshold?: number;
7
+ minEndOfTurnSilenceWhenConfident?: number;
8
+ maxTurnSilence?: number;
9
+ formatTurns?: boolean;
10
+ };
11
+ export type StreamingEvents = "open" | "close" | "turn" | "error";
12
+ export type StreamingListeners = {
13
+ open?: (event: BeginEvent) => void;
14
+ close?: (code: number, reason: string) => void;
15
+ turn?: (event: TurnEvent) => void;
16
+ error?: (error: Error) => void;
17
+ };
18
+ export type StreamingTokenParams = {
19
+ expires_in_seconds: number;
20
+ max_session_duration_seconds: number;
21
+ };
22
+ export type StreamingTemporaryTokenResponse = {
23
+ token: string;
24
+ };
25
+ export type StreamingAudioData = ArrayBufferLike;
26
+ export type BeginEvent = {
27
+ type: "Begin";
28
+ id: string;
29
+ expires_at: number;
30
+ };
31
+ export type TurnEvent = {
32
+ type: "Turn";
33
+ turn_order: number;
34
+ turn_is_formatted: boolean;
35
+ end_of_turn: boolean;
36
+ transcript: string;
37
+ end_of_turn_confidence: number;
38
+ words: StreamingWord[];
39
+ };
40
+ export type StreamingWord = {
41
+ start: number;
42
+ end: number;
43
+ confidence: number;
44
+ text: string;
45
+ word_is_final: boolean;
46
+ };
47
+ export type TerminationEvent = {
48
+ type: "Termination";
49
+ audio_duration_seconds: number;
50
+ session_duration_seconds: number;
51
+ };
52
+ export type StreamingTerminateSession = {
53
+ type: "Terminate";
54
+ };
55
+ export type StreamingUpdateConfiguration = {
56
+ type: "UpdateConfiguration";
57
+ end_of_turn_confidence_threshold?: number;
58
+ min_end_of_turn_silence_when_confident?: number;
59
+ max_turn_silence?: number;
60
+ format_turns?: boolean;
61
+ };
62
+ export type StreamingForceEndpoint = {
63
+ type: "ForceEndpoint";
64
+ };
65
+ export type ErrorEvent = {
66
+ error: string;
67
+ };
68
+ export type StreamingEventMessage = BeginEvent | TurnEvent | TerminationEvent | ErrorEvent;
69
+ export type StreamingOperationMessage = StreamingUpdateConfiguration | StreamingForceEndpoint | StreamingTerminateSession;
@@ -1 +1,2 @@
1
1
  export { RealtimeError, RealtimeErrorType, RealtimeErrorMessages, } from "./realtime";
2
+ export { StreamingError, StreamingErrorType, StreamingErrorMessages, } from "./streaming";