assemblyai 2.0.0-beta → 2.0.1-beta

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.
Files changed (79) hide show
  1. package/README.md +148 -48
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.esm.js +218 -123
  4. package/dist/index.js +225 -123
  5. package/dist/services/base.d.ts +0 -2
  6. package/dist/services/index.d.ts +7 -9
  7. package/dist/services/lemur/index.d.ts +6 -6
  8. package/dist/services/realtime/factory.d.ts +10 -0
  9. package/dist/services/realtime/index.d.ts +2 -16
  10. package/dist/services/realtime/service.d.ts +22 -0
  11. package/dist/services/transcripts/index.d.ts +37 -20
  12. package/dist/types/asyncapi.generated.d.ts +87 -0
  13. package/dist/types/index.d.ts +3 -4
  14. package/dist/types/openapi.generated.d.ts +685 -0
  15. package/dist/types/realtime/index.d.ts +30 -11
  16. package/dist/types/services/abstractions.d.ts +8 -36
  17. package/dist/types/services/index.d.ts +2 -5
  18. package/dist/types/transcripts/index.d.ts +5 -0
  19. package/dist/utils/axios.d.ts +3 -0
  20. package/dist/utils/errors/realtime.d.ts +1 -4
  21. package/package.json +8 -5
  22. package/src/index.ts +3 -0
  23. package/src/services/base.ts +1 -3
  24. package/src/services/files/index.ts +4 -4
  25. package/src/services/index.ts +18 -35
  26. package/src/services/lemur/index.ts +20 -16
  27. package/src/services/realtime/factory.ts +32 -0
  28. package/src/services/realtime/index.ts +2 -106
  29. package/src/services/realtime/service.ts +184 -0
  30. package/src/services/transcripts/index.ts +85 -63
  31. package/src/types/asyncapi.generated.ts +124 -0
  32. package/src/types/index.ts +3 -4
  33. package/src/types/openapi.generated.ts +834 -0
  34. package/src/types/realtime/index.ts +53 -13
  35. package/src/types/services/abstractions.ts +8 -40
  36. package/src/types/services/index.ts +2 -6
  37. package/src/types/transcripts/index.ts +5 -0
  38. package/src/utils/axios.ts +19 -0
  39. package/src/utils/errors/realtime.ts +5 -18
  40. package/dist/services/transcripts/redactions.d.ts +0 -14
  41. package/dist/services/transcripts/subtitles.d.ts +0 -12
  42. package/dist/types/core/index.d.ts +0 -2
  43. package/dist/types/core/params.d.ts +0 -2
  44. package/dist/types/core/segments.d.ts +0 -28
  45. package/dist/types/core/transcript.d.ts +0 -113
  46. package/dist/types/lemur/index.d.ts +0 -79
  47. package/dist/types/models/auto_chapter.d.ts +0 -8
  48. package/dist/types/models/auto_highlights.d.ts +0 -11
  49. package/dist/types/models/content_safety.d.ts +0 -25
  50. package/dist/types/models/entity_detection.d.ts +0 -7
  51. package/dist/types/models/index.d.ts +0 -8
  52. package/dist/types/models/pii.d.ts +0 -3
  53. package/dist/types/models/sentiment_analysis.d.ts +0 -9
  54. package/dist/types/models/shared.d.ts +0 -3
  55. package/dist/types/models/summarization.d.ts +0 -3
  56. package/dist/types/models/topic_detection.d.ts +0 -17
  57. package/dist/types/shared/index.d.ts +0 -2
  58. package/dist/types/shared/pagination.d.ts +0 -7
  59. package/dist/types/shared/timestamp.d.ts +0 -5
  60. package/src/services/transcripts/redactions.ts +0 -27
  61. package/src/services/transcripts/subtitles.ts +0 -26
  62. package/src/types/core/index.ts +0 -2
  63. package/src/types/core/params.ts +0 -3
  64. package/src/types/core/segments.ts +0 -29
  65. package/src/types/core/transcript.ts +0 -159
  66. package/src/types/lemur/index.ts +0 -97
  67. package/src/types/models/auto_chapter.ts +0 -9
  68. package/src/types/models/auto_highlights.ts +0 -14
  69. package/src/types/models/content_safety.ts +0 -34
  70. package/src/types/models/entity_detection.ts +0 -8
  71. package/src/types/models/index.ts +0 -8
  72. package/src/types/models/pii.ts +0 -32
  73. package/src/types/models/sentiment_analysis.ts +0 -11
  74. package/src/types/models/shared.ts +0 -4
  75. package/src/types/models/summarization.ts +0 -10
  76. package/src/types/models/topic_detection.ts +0 -21
  77. package/src/types/shared/index.ts +0 -2
  78. package/src/types/shared/pagination.ts +0 -8
  79. package/src/types/shared/timestamp.ts +0 -6
@@ -1,17 +1,36 @@
1
- type RealtimeConnectionParams = {
1
+ import { FinalTranscript, PartialTranscript, RealtimeTranscript, RealtimeTranscriptType } from "../asyncapi.generated";
2
+ type CreateRealtimeServiceParams = {
3
+ realtimeUrl?: string;
2
4
  sampleRate?: number;
3
5
  wordBoost?: string[];
4
- };
5
- type RealtimeListener = "data" | "error" | "open" | "close";
6
- type RealtimeTranscriptType = "PartialTranscript" | "FinalTranscript";
7
- type RealtimeTranscript = {
8
- text: string;
9
- message_type: RealtimeTranscriptType;
6
+ } & ({
7
+ apiKey?: string;
8
+ } | {
9
+ token: string;
10
+ });
11
+ type RealtimeServiceParams = {
12
+ realtimeUrl?: string;
13
+ sampleRate?: number;
14
+ wordBoost?: string[];
15
+ } & ({
16
+ apiKey: string;
17
+ } | {
18
+ token: string;
19
+ });
20
+ type RealtimeEvents = "open" | "close" | "transcript" | "transcript.partial" | "transcript.final" | "error";
21
+ type SessionBeginsEventData = {
22
+ sessionId: string;
23
+ expiresAt: Date;
10
24
  };
11
25
  type RealtimeListeners = {
12
- data?: (transcript: RealtimeTranscript) => void;
13
- error?: (error: Error) => void;
14
- open?: () => void;
26
+ open?: (event: SessionBeginsEventData) => void;
15
27
  close?: (code: number, reason: string) => void;
28
+ transcript?: (transcript: RealtimeTranscript) => void;
29
+ "transcript.partial"?: (transcript: PartialTranscript) => void;
30
+ "transcript.final"?: (transcript: FinalTranscript) => void;
31
+ error?: (error: Error) => void;
32
+ };
33
+ type RealtimeTokenParams = {
34
+ expires_in: number;
16
35
  };
17
- export type { RealtimeConnectionParams, RealtimeListener, RealtimeTranscript, RealtimeTranscriptType, RealtimeListeners, };
36
+ export type { CreateRealtimeServiceParams, RealtimeServiceParams, RealtimeEvents, RealtimeTranscriptType, SessionBeginsEventData, RealtimeListeners, RealtimeTokenParams, };
@@ -1,16 +1,16 @@
1
1
  /**
2
2
  * Interface for classes that can create resources.
3
3
  * @template T The type of the resource.
4
- * @template Props The type of the properties required to create the resource.
4
+ * @template Parameters The type of the parameters required to create the resource.
5
5
  */
6
- interface Createable<T, Props, Settings = Record<string, any>> {
6
+ interface Createable<T, Parameters, Options = Record<string, any>> {
7
7
  /**
8
8
  * Create a new resource.
9
- * @param data The properties of the new resource.
10
- * @param settings The settings used for creating the new resource.
9
+ * @param params The parameters of the new resource.
10
+ * @param options The options used for creating the new resource.
11
11
  * @return A promise that resolves to the newly created resource.
12
12
  */
13
- create(params: Props, settings?: Settings | null): Promise<T>;
13
+ create(params: Parameters, options?: Options): Promise<T>;
14
14
  }
15
15
  /**
16
16
  * Interface for classes that can retrieve resources.
@@ -19,11 +19,11 @@ interface Createable<T, Props, Settings = Record<string, any>> {
19
19
  */
20
20
  interface Retrieveable<T, Id = string> {
21
21
  /**
22
- * Retrieve a resource.
22
+ * Get a resource.
23
23
  * @param id The identifier of the resource to retrieve.
24
24
  * @return A promise that resolves to the retrieved resource.
25
25
  */
26
- retrieve(id: Id): Promise<T>;
26
+ get(id: Id): Promise<T>;
27
27
  }
28
28
  /**
29
29
  * Interface for classes that can delete resources.
@@ -49,32 +49,4 @@ interface Listable<T, Page = string> {
49
49
  */
50
50
  list(page?: Page): Promise<T>;
51
51
  }
52
- /**
53
- * Interface for classes that can connect to resources.
54
- * @template T The type of the resource's data.
55
- */
56
- interface Connectable<T, Params> {
57
- /**
58
- * Connect to a resource.
59
- * @param event The event to listen for.
60
- * @param listener The listener for the event.
61
- */
62
- on(event: "data", listener: (data: T) => void): void;
63
- on(event: "error", listener: (error: Error) => void): void;
64
- on(event: "open", listener: () => void): void;
65
- on(event: "close", listener: (code: number, reason: string) => void): void;
66
- /**
67
- * Send data to the resource.
68
- * @param data The data to send.
69
- */
70
- send(data: ArrayBuffer): void;
71
- /**
72
- * Connect to the resource.
73
- */
74
- connect(params: Params): void;
75
- /**
76
- * Disconnect from the resource.
77
- */
78
- disconnect(): void;
79
- }
80
- export type { Createable, Retrieveable, Deletable, Listable, Connectable };
52
+ export type { Createable, Retrieveable, Deletable, Listable };
@@ -1,9 +1,6 @@
1
1
  type BaseServiceParams = {
2
- token: string;
2
+ apiKey: string;
3
3
  baseUrl?: string;
4
4
  };
5
- type Upload = {
6
- upload_url: string;
7
- };
8
5
  export type * from "./abstractions";
9
- export type { BaseServiceParams, Upload };
6
+ export type { BaseServiceParams };
@@ -0,0 +1,5 @@
1
+ export type CreateTranscriptOptions = {
2
+ poll?: boolean;
3
+ pollingInterval?: number;
4
+ pollingTimeout?: number;
5
+ };
@@ -0,0 +1,3 @@
1
+ import { BaseServiceParams } from "../.";
2
+ export declare function createAxiosClient(params: BaseServiceParams): import("axios").AxiosInstance;
3
+ export declare function throwApiError(error: unknown): Promise<never>;
@@ -1,8 +1,7 @@
1
1
  declare enum RealtimeErrorType {
2
2
  BadSampleRate = 4000,
3
3
  AuthFailed = 4001,
4
- InsufficientFunds = 4002,
5
- FreeAccount = 4003,
4
+ InsufficientFundsOrFreeAccount = 4002,
6
5
  NonexistentSessionId = 4004,
7
6
  SessionExpired = 4008,
8
7
  ClosedSession = 4010,
@@ -19,8 +18,6 @@ declare enum RealtimeErrorType {
19
18
  }
20
19
  declare const RealtimeErrorMessages: Record<RealtimeErrorType, string>;
21
20
  declare class RealtimeError extends Error {
22
- code: RealtimeErrorType;
23
- constructor(code: RealtimeErrorType);
24
21
  }
25
22
  export { RealtimeErrorType, RealtimeErrorMessages };
26
23
  export default RealtimeError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assemblyai",
3
- "version": "2.0.0-beta",
3
+ "version": "2.0.1-beta",
4
4
  "description": "The AssemblyAI Node.js 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
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -21,7 +21,8 @@
21
21
  "lint": "tslint -p tsconfig.json",
22
22
  "test": "pnpm lint && pnpm test:unit",
23
23
  "test:unit": "jest --config jest.config.rollup.ts",
24
- "prettier": "prettier --write 'src/**/*.ts'"
24
+ "prettier": "prettier --write 'src/**/*.ts'",
25
+ "generate-types": "tsx ./scripts/generate-types.ts && pnpm prettier"
25
26
  },
26
27
  "keywords": [
27
28
  "AssemblyAI",
@@ -36,17 +37,20 @@
36
37
  "types"
37
38
  ],
38
39
  "devDependencies": {
39
- "@types/jest": "^29.5.2",
40
+ "@types/jest": "^29.5.5",
40
41
  "@types/node": "^20.5.7",
41
42
  "@types/ws": "^8.5.5",
43
+ "dotenv": "^16.3.1",
42
44
  "eslint": "^8.43.0",
43
45
  "i": "^0.3.7",
44
46
  "jest": "^29.5.0",
45
47
  "jest-cli": "^29.5.0",
46
48
  "jest-junit": "^16.0.0",
47
49
  "jest-mock-extended": "^3.0.4",
50
+ "jest-websocket-mock": "^2.4.1",
48
51
  "mock-socket": "^9.2.1",
49
52
  "npm": "^9.7.1",
53
+ "openapi-typescript": "^6.6.1",
50
54
  "prettier": "^2.8.8",
51
55
  "rimraf": "^5.0.1",
52
56
  "rollup": "^3.25.1",
@@ -55,8 +59,7 @@
55
59
  "ts-node": "^10.9.1",
56
60
  "tslib": "^2.5.3",
57
61
  "tslint": "^6.1.3",
58
- "typescript": "^5.1.3",
59
- "jest-websocket-mock": "^2.4.1"
62
+ "typescript": "^5.2.2"
60
63
  },
61
64
  "dependencies": {
62
65
  "axios": "^1.4.0",
package/src/index.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  import AssemblyAI from "./services";
2
+
3
+ export * from "./services";
4
+ export type * from "./types";
2
5
  export default AssemblyAI;
@@ -1,5 +1,4 @@
1
- import axios, { AxiosInstance } from "axios";
2
- import { BaseServiceParams } from "@/types";
1
+ import { AxiosInstance } from "axios";
3
2
 
4
3
  /**
5
4
  * Base class for services that communicate with the API.
@@ -12,5 +11,4 @@ abstract class BaseService {
12
11
  constructor(protected client: AxiosInstance) {}
13
12
  }
14
13
 
15
- export type { BaseServiceParams };
16
14
  export default BaseService;
@@ -1,6 +1,6 @@
1
- import fs from "fs/promises";
1
+ import { readFile } from "fs/promises";
2
2
  import BaseService from "@/services/base";
3
- import { Upload } from "@/types";
3
+ import { UploadedFile } from "@/types";
4
4
 
5
5
  export default class FileService extends BaseService {
6
6
  /**
@@ -9,9 +9,9 @@ export default class FileService extends BaseService {
9
9
  * @return A promise that resolves to the uploaded file URL.
10
10
  */
11
11
  async upload(path: string): Promise<string> {
12
- const file = await fs.readFile(path);
12
+ const file = await readFile(path);
13
13
 
14
- const { data } = await this.client.post<Upload>("/v2/upload", file, {
14
+ const { data } = await this.client.post<UploadedFile>("/v2/upload", file, {
15
15
  headers: {
16
16
  "Content-Type": "application/octet-stream",
17
17
  },
@@ -1,7 +1,7 @@
1
- import axios, { isAxiosError } from "axios";
2
- import { BaseServiceParams } from "./base";
3
- import LeMURService from "./lemur";
4
- import RealtimeService from "./realtime";
1
+ import { createAxiosClient } from "@/utils/axios";
2
+ import { BaseServiceParams } from "@/types";
3
+ import LemurService from "./lemur";
4
+ import { RealtimeService, RealtimeServiceFactory } from "./realtime";
5
5
  import TranscriptService from "./transcripts";
6
6
  import FileService from "./files";
7
7
 
@@ -19,48 +19,31 @@ export default class AssemblyAI {
19
19
  /**
20
20
  * The LeMUR service.
21
21
  */
22
- public lemur: LeMURService;
22
+ public lemur: LemurService;
23
23
 
24
24
  /**
25
25
  * The realtime service.
26
26
  */
27
- public realtime: (params?: { baseUrl: string }) => RealtimeService;
27
+ public realtime: RealtimeServiceFactory;
28
28
 
29
29
  /**
30
30
  * Create a new AssemblyAI client.
31
- * @param params The parameters for the service, including the API token and base URL, if any.
31
+ * @param params The parameters for the service, including the API key and base URL, if any.
32
32
  */
33
33
  constructor(params: BaseServiceParams) {
34
34
  params.baseUrl = params.baseUrl || "https://api.assemblyai.com";
35
- const client = this.createClient(params);
35
+ const client = createAxiosClient(params);
36
36
  this.files = new FileService(client);
37
37
  this.transcripts = new TranscriptService(client, this.files);
38
- this.lemur = new LeMURService(client);
39
- this.realtime = ({ baseUrl } = { baseUrl: "" }) => {
40
- if (!baseUrl) {
41
- const url = new URL(params.baseUrl as string);
42
- url.protocol = "wss:";
43
- baseUrl = url.toString();
44
- }
45
- return new RealtimeService({
46
- token: params.token,
47
- baseUrl,
48
- });
49
- };
50
- }
51
-
52
- private createClient(params: BaseServiceParams) {
53
- const client = axios.create({
54
- baseURL: params.baseUrl,
55
- headers: { Authorization: params.token },
56
- });
57
-
58
- client.interceptors.response.use(null, (error) => {
59
- if (isAxiosError(error) && error.response?.data?.error) {
60
- return Promise.reject(new Error(error.response.data.error));
61
- }
62
- return Promise.reject(error);
63
- });
64
- return client;
38
+ this.lemur = new LemurService(client);
39
+ this.realtime = new RealtimeServiceFactory(client, params);
65
40
  }
66
41
  }
42
+
43
+ export {
44
+ LemurService,
45
+ RealtimeServiceFactory,
46
+ RealtimeService,
47
+ TranscriptService,
48
+ FileService,
49
+ };
@@ -1,16 +1,18 @@
1
1
  import {
2
- LeMURResponse,
3
- SummaryParams,
4
- QuestionAnswerParams,
5
- ActionItemsParams,
6
- TaskParams,
7
- LeMURQuestionAnswerResponse,
2
+ LemurSummaryParameters,
3
+ LemurActionItemsParameters,
4
+ LemurQuestionAnswerParameters,
5
+ LemurTaskParameters,
6
+ LemurSummaryResponse,
7
+ LemurQuestionAnswerResponse,
8
+ LemurActionItemsResponse,
9
+ LemurTaskResponse,
8
10
  } from "@/types";
9
11
  import BaseService from "@/services/base";
10
12
 
11
- export default class LeMURService extends BaseService {
12
- async summary(params: SummaryParams): Promise<LeMURResponse> {
13
- const { data } = await this.client.post<LeMURResponse>(
13
+ export default class LemurService extends BaseService {
14
+ async summary(params: LemurSummaryParameters): Promise<LemurSummaryResponse> {
15
+ const { data } = await this.client.post<LemurSummaryResponse>(
14
16
  "/lemur/v3/generate/summary",
15
17
  params
16
18
  );
@@ -18,25 +20,27 @@ export default class LeMURService extends BaseService {
18
20
  }
19
21
 
20
22
  async questionAnswer(
21
- params: QuestionAnswerParams
22
- ): Promise<LeMURQuestionAnswerResponse> {
23
- const { data } = await this.client.post<LeMURQuestionAnswerResponse>(
23
+ params: LemurQuestionAnswerParameters
24
+ ): Promise<LemurQuestionAnswerResponse> {
25
+ const { data } = await this.client.post<LemurQuestionAnswerResponse>(
24
26
  "/lemur/v3/generate/question-answer",
25
27
  params
26
28
  );
27
29
  return data;
28
30
  }
29
31
 
30
- async actionItems(params: ActionItemsParams): Promise<LeMURResponse> {
31
- const { data } = await this.client.post<LeMURResponse>(
32
+ async actionItems(
33
+ params: LemurActionItemsParameters
34
+ ): Promise<LemurActionItemsResponse> {
35
+ const { data } = await this.client.post<LemurActionItemsResponse>(
32
36
  "/lemur/v3/generate/action-items",
33
37
  params
34
38
  );
35
39
  return data;
36
40
  }
37
41
 
38
- async task(params: TaskParams): Promise<LeMURResponse> {
39
- const { data } = await this.client.post<LeMURResponse>(
42
+ async task(params: LemurTaskParameters): Promise<LemurTaskResponse> {
43
+ const { data } = await this.client.post<LemurTaskResponse>(
40
44
  "/lemur/v3/generate/task",
41
45
  params
42
46
  );
@@ -0,0 +1,32 @@
1
+ import {
2
+ BaseServiceParams,
3
+ RealtimeTokenParams,
4
+ CreateRealtimeServiceParams,
5
+ RealtimeServiceParams,
6
+ } from "@/types";
7
+ import { AxiosInstance } from "axios";
8
+ import { RealtimeService } from "./service";
9
+
10
+ export class RealtimeServiceFactory {
11
+ constructor(
12
+ private client: AxiosInstance,
13
+ private params: BaseServiceParams
14
+ ) {}
15
+
16
+ createService(params?: CreateRealtimeServiceParams): RealtimeService {
17
+ if (!params) params = { apiKey: this.params.apiKey };
18
+ else if (!("token" in params) && !params.apiKey) {
19
+ params.apiKey = this.params.apiKey;
20
+ }
21
+
22
+ return new RealtimeService(params as RealtimeServiceParams);
23
+ }
24
+
25
+ async createTemporaryToken(params: RealtimeTokenParams) {
26
+ const response = await this.client.post<{ token: string }>(
27
+ "/v2/realtime/token",
28
+ params
29
+ );
30
+ return response.data.token;
31
+ }
32
+ }
@@ -1,106 +1,2 @@
1
- import { BaseServiceParams } from "@/services/base";
2
- import {
3
- Connectable,
4
- RealtimeConnectionParams,
5
- RealtimeListener,
6
- RealtimeListeners,
7
- RealtimeTranscript,
8
- } from "@/types";
9
- import { RealtimeError, RealtimeErrorType } from "@/utils/errors";
10
- import WebSocket, { type CloseEvent, type MessageEvent } from "ws";
11
-
12
- export default class RealtimeService
13
- implements Connectable<RealtimeTranscript, RealtimeConnectionParams>
14
- {
15
- private params: BaseServiceParams;
16
- private socket?: WebSocket;
17
- private listeners: RealtimeListeners = {};
18
-
19
- constructor(params: BaseServiceParams) {
20
- this.params = params;
21
- }
22
-
23
- private connectionUrl(
24
- connectionParams: Required<RealtimeConnectionParams>
25
- ): URL {
26
- if (!this.params.baseUrl) {
27
- throw new Error("Missing base URL");
28
- }
29
-
30
- const url = new URL(this.params.baseUrl);
31
-
32
- if (url.protocol !== "wss:") {
33
- throw new Error("Invalid protocol, must be wss");
34
- }
35
-
36
- const searchParams = new URLSearchParams();
37
- searchParams.set("sample_rate", connectionParams.sampleRate.toString());
38
- searchParams.set("word_boost", connectionParams.wordBoost.join(","));
39
- url.search = searchParams.toString();
40
-
41
- return url;
42
- }
43
-
44
- on(event: "data", listener: (transcript: RealtimeTranscript) => void): void;
45
- on(event: "error", listener: (error: Error) => void): void;
46
- on(event: "open", listener: () => void): void;
47
- on(event: "close", listener: (code: number, reason: string) => void): void;
48
- on(event: RealtimeListener, listener: (...args: any[]) => void) {
49
- this.listeners[event] = listener;
50
- }
51
-
52
- connect(connectionParams: RealtimeConnectionParams) {
53
- if (this.socket) {
54
- throw new Error("Already connected");
55
- }
56
-
57
- const url = this.connectionUrl({
58
- ...connectionParams,
59
- sampleRate: connectionParams.sampleRate || 16000,
60
- wordBoost: connectionParams.wordBoost || [],
61
- });
62
-
63
- this.socket = new WebSocket(url.toString(), {
64
- headers: {
65
- Authorization: this.params.token,
66
- },
67
- });
68
-
69
- this.socket.onopen = () => this.listeners.open?.();
70
- this.socket.onclose = ({ code, reason }: CloseEvent) =>
71
- this.listeners.close?.(code, reason);
72
-
73
- this.socket.onerror = (error) => {
74
- const code = error.message as unknown as RealtimeErrorType;
75
- const realtimeError = new RealtimeError(code);
76
- this.listeners.error?.(realtimeError);
77
- };
78
-
79
- this.socket.onmessage = ({ data }: MessageEvent) => {
80
- const message = JSON.parse(data.toString()) as RealtimeTranscript;
81
- this.listeners.data?.(message);
82
- };
83
- }
84
-
85
- send(data: ArrayBuffer) {
86
- if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
87
- throw new Error("Socket is not open for communication");
88
- }
89
-
90
- const payload = {
91
- audio_data: Buffer.from(data).toString("base64"),
92
- };
93
-
94
- this.socket.send(JSON.stringify(payload));
95
- }
96
-
97
- disconnect() {
98
- if (this.socket) {
99
- this.socket.removeAllListeners();
100
- this.socket.close();
101
- }
102
-
103
- this.listeners = {};
104
- this.socket = undefined;
105
- }
106
- }
1
+ export * from "@/services/realtime/factory";
2
+ export * from "@/services/realtime/service";