assemblyai 4.3.0 → 4.3.2

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.
@@ -19,7 +19,7 @@ type CreateRealtimeTranscriberParams = {
19
19
  /**
20
20
  * The duration of the end utterance silence threshold in milliseconds
21
21
  */
22
- end_utterance_silence_threshold?: number;
22
+ endUtteranceSilenceThreshold?: number;
23
23
  } & ({
24
24
  /**
25
25
  * The API key used to authenticate the RealtimeTranscriber
@@ -56,7 +56,7 @@ type RealtimeTranscriberParams = {
56
56
  /**
57
57
  * The duration of the end utterance silence threshold in milliseconds
58
58
  */
59
- end_utterance_silence_threshold?: number;
59
+ endUtteranceSilenceThreshold?: number;
60
60
  } & ({
61
61
  /**
62
62
  * The API key used to authenticate the RealtimeTranscriber.
@@ -2,5 +2,4 @@ type BaseServiceParams = {
2
2
  apiKey: string;
3
3
  baseUrl?: string;
4
4
  };
5
- export * from "./abstractions";
6
5
  export type { BaseServiceParams };
@@ -1,21 +1,27 @@
1
1
  import { FileUploadParams } from "../files";
2
2
  import { TranscriptParams } from "../openapi.generated";
3
+ /**
4
+ * Options for polling.
5
+ */
3
6
  export type PollingOptions = {
4
7
  /**
5
8
  * The amount of time to wait between polling requests.
6
- * @default 3000 or every 3 seconds
9
+ * @defaultValue 3000 or every 3 seconds
7
10
  */
8
11
  pollingInterval?: number;
9
12
  /**
10
13
  * The maximum amount of time to wait for the transcript to be ready.
11
- * @default -1 which means wait forever
14
+ * @defaultValue -1 which means wait forever
12
15
  */
13
16
  pollingTimeout?: number;
14
17
  };
18
+ /**
19
+ * @deprecated Use `TranscriptService.transcribe` with `TranscribeOptions`.
20
+ */
15
21
  export type CreateTranscriptOptions = {
16
22
  /**
17
23
  * Whether to poll the transcript until it is ready.
18
- * @default true
24
+ * @defaultValue true
19
25
  */
20
26
  poll?: boolean;
21
27
  } & PollingOptions;
@@ -26,9 +32,12 @@ export type AudioToTranscribe = FileUploadParams;
26
32
  /**
27
33
  * The parameters to transcribe an audio file.
28
34
  */
29
- export type TranscribeParams = {
35
+ export type TranscribeParams = ({
36
+ /**
37
+ * The audio to transcribe. This can be a public URL, a local file path, a readable file stream, or a file buffer.
38
+ */
30
39
  audio: AudioToTranscribe;
31
- } & Omit<TranscriptParams, "audio_url">;
40
+ } & Omit<TranscriptParams, "audio_url">) | TranscriptParams;
32
41
  /**
33
42
  * The parameters to start the transcription of an audio file.
34
43
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assemblyai",
3
- "version": "4.3.0",
3
+ "version": "4.3.2",
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"
@@ -110,6 +110,7 @@
110
110
  "@typescript-eslint/eslint-plugin": "^6.7.5",
111
111
  "dotenv": "^16.3.1",
112
112
  "eslint": "^8.48.0",
113
+ "eslint-plugin-tsdoc": "^0.2.17",
113
114
  "jest": "^29.5.0",
114
115
  "jest-cli": "^29.5.0",
115
116
  "jest-fetch-mock": "^3.0.3",
@@ -7,7 +7,7 @@ import { Error as JsonError } from "..";
7
7
  export abstract class BaseService {
8
8
  /**
9
9
  * Create a new service.
10
- * @param params The parameters to use for the service.
10
+ * @param params - The parameters to use for the service.
11
11
  */
12
12
  constructor(private params: BaseServiceParams) {}
13
13
  protected async fetch(
@@ -5,8 +5,8 @@ import { UploadedFile, FileUploadParams, FileUploadData } from "../..";
5
5
  export class FileService extends BaseService {
6
6
  /**
7
7
  * Upload a local file to AssemblyAI.
8
- * @param input The local file path to upload, or a stream or buffer of the file to upload.
9
- * @return A promise that resolves to the uploaded file URL.
8
+ * @param input - The local file path to upload, or a stream or buffer of the file to upload.
9
+ * @returns A promise that resolves to the uploaded file URL.
10
10
  */
11
11
  async upload(input: FileUploadParams): Promise<string> {
12
12
  let fileData: FileUploadData;
@@ -34,7 +34,7 @@ class AssemblyAI {
34
34
 
35
35
  /**
36
36
  * Create a new AssemblyAI client.
37
- * @param params The parameters for the service, including the API key and base URL, if any.
37
+ * @param params - The parameters for the service, including the API key and base URL, if any.
38
38
  */
39
39
  constructor(params: BaseServiceParams) {
40
40
  params.baseUrl = params.baseUrl || defaultBaseUrl;
@@ -52,7 +52,7 @@ export class LemurService extends BaseService {
52
52
 
53
53
  /**
54
54
  * Delete the data for a previously submitted LeMUR request.
55
- * @param id ID of the LeMUR request
55
+ * @param id - ID of the LeMUR request
56
56
  */
57
57
  purgeRequestData(id: string): Promise<PurgeLemurRequestDataResponse> {
58
58
  return this.fetchJson<PurgeLemurRequestDataResponse>(`/lemur/v3/${id}`, {
@@ -48,7 +48,7 @@ export class RealtimeTranscriber {
48
48
  private encoding?: AudioEncoding;
49
49
  private apiKey?: string;
50
50
  private token?: string;
51
- private end_utterance_silence_threshold?: number;
51
+ private endUtteranceSilenceThreshold?: number;
52
52
  private socket?: WebSocket;
53
53
  private listeners: RealtimeListeners = {};
54
54
  private sessionTerminatedResolve?: () => void;
@@ -58,8 +58,7 @@ export class RealtimeTranscriber {
58
58
  this.sampleRate = params.sampleRate ?? 16_000;
59
59
  this.wordBoost = params.wordBoost;
60
60
  this.encoding = params.encoding;
61
- this.end_utterance_silence_threshold =
62
- params.end_utterance_silence_threshold;
61
+ this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
63
62
  if ("token" in params && params.token) this.token = params.token;
64
63
  if ("apiKey" in params && params.apiKey) this.apiKey = params.apiKey;
65
64
 
@@ -130,13 +129,13 @@ export class RealtimeTranscriber {
130
129
 
131
130
  this.socket.onopen = () => {
132
131
  if (
133
- this.end_utterance_silence_threshold === undefined ||
134
- this.end_utterance_silence_threshold === null
132
+ this.endUtteranceSilenceThreshold === undefined ||
133
+ this.endUtteranceSilenceThreshold === null
135
134
  ) {
136
135
  return;
137
136
  }
138
137
  this.configureEndUtteranceSilenceThreshold(
139
- this.end_utterance_silence_threshold
138
+ this.endUtteranceSilenceThreshold
140
139
  );
141
140
  };
142
141
 
@@ -214,8 +213,8 @@ export class RealtimeTranscriber {
214
213
 
215
214
  /**
216
215
  * Configure the threshold for how long to wait before ending an utterance. Default is 700ms.
217
- * @param threshold The duration of the end utterance silence threshold in milliseconds
218
- * @format integer
216
+ * @param threshold - The duration of the end utterance silence threshold in milliseconds.
217
+ * This value must be an integer between 0 and 20_000.
219
218
  */
220
219
  configureEndUtteranceSilenceThreshold(threshold: number) {
221
220
  this.send(`{"end_utterance_silence_threshold":${threshold}}`);
@@ -6,10 +6,6 @@ import {
6
6
  TranscriptList,
7
7
  TranscriptParams,
8
8
  CreateTranscriptOptions,
9
- Createable,
10
- Deletable,
11
- Listable,
12
- Retrieveable,
13
9
  SubtitleFormat,
14
10
  RedactedAudioResponse,
15
11
  ListTranscriptParams,
@@ -23,22 +19,15 @@ import {
23
19
  import { FileService } from "../files";
24
20
  import { getPath } from "../../utils/path";
25
21
 
26
- export class TranscriptService
27
- extends BaseService
28
- implements
29
- Createable<Transcript, TranscriptParams, CreateTranscriptOptions>,
30
- Retrieveable<Transcript>,
31
- Deletable<Transcript>,
32
- Listable<TranscriptList>
33
- {
22
+ export class TranscriptService extends BaseService {
34
23
  constructor(params: BaseServiceParams, private files: FileService) {
35
24
  super(params);
36
25
  }
37
26
 
38
27
  /**
39
28
  * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
40
- * @param params The parameters to transcribe an audio file.
41
- * @param options The options to transcribe an audio file.
29
+ * @param params - The parameters to transcribe an audio file.
30
+ * @param options - The options to transcribe an audio file.
42
31
  * @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
43
32
  */
44
33
  async transcribe(
@@ -51,37 +40,43 @@ export class TranscriptService
51
40
 
52
41
  /**
53
42
  * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
54
- * @param params The parameters to start the transcription of an audio file.
43
+ * @param params - The parameters to start the transcription of an audio file.
55
44
  * @returns A promise that resolves to the queued transcript.
56
45
  */
57
46
  async submit(params: SubmitParams): Promise<Transcript> {
58
- const { audio, ...createParams } = params;
59
47
  let audioUrl;
60
- if (typeof audio === "string") {
61
- const path = getPath(audio);
62
- if (path !== null) {
63
- // audio is local path, upload local file
64
- audioUrl = await this.files.upload(path);
48
+ let transcriptParams: TranscriptParams | undefined = undefined;
49
+ if ("audio" in params) {
50
+ const { audio, ...audioTranscriptParams } = params;
51
+ if (typeof audio === "string") {
52
+ const path = getPath(audio);
53
+ if (path !== null) {
54
+ // audio is local path, upload local file
55
+ audioUrl = await this.files.upload(path);
56
+ } else {
57
+ // audio is not a local path, assume it's a URL
58
+ audioUrl = audio;
59
+ }
65
60
  } else {
66
- // audio is not a local path, assume it's a URL
67
- audioUrl = audio;
61
+ // audio is of uploadable type
62
+ audioUrl = await this.files.upload(audio);
68
63
  }
64
+ transcriptParams = { ...audioTranscriptParams, audio_url: audioUrl };
69
65
  } else {
70
- // audio is of uploadable type
71
- audioUrl = await this.files.upload(audio);
66
+ transcriptParams = params;
72
67
  }
73
68
 
74
69
  const data = await this.fetchJson<Transcript>("/v2/transcript", {
75
70
  method: "POST",
76
- body: JSON.stringify({ ...createParams, audio_url: audioUrl }),
71
+ body: JSON.stringify(transcriptParams),
77
72
  });
78
73
  return data;
79
74
  }
80
75
 
81
76
  /**
82
77
  * Create a transcript.
83
- * @param params The parameters to create a transcript.
84
- * @param options The options used for creating the new transcript.
78
+ * @param params - The parameters to create a transcript.
79
+ * @param options - The options used for creating the new transcript.
85
80
  * @returns A promise that resolves to the transcript.
86
81
  * @deprecated Use `transcribe` instead to transcribe a audio file that includes polling, or `submit` to transcribe a audio file without polling.
87
82
  */
@@ -109,8 +104,8 @@ export class TranscriptService
109
104
 
110
105
  /**
111
106
  * Wait until the transcript ready, either the status is "completed" or "error".
112
- * @param transcriptId The ID of the transcript.
113
- * @param options The options to wait until the transcript is ready.
107
+ * @param transcriptId - The ID of the transcript.
108
+ * @param options - The options to wait until the transcript is ready.
114
109
  * @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
115
110
  */
116
111
  async waitUntilReady(
@@ -138,7 +133,7 @@ export class TranscriptService
138
133
 
139
134
  /**
140
135
  * Retrieve a transcript.
141
- * @param id The identifier of the transcript.
136
+ * @param id - The identifier of the transcript.
142
137
  * @returns A promise that resolves to the transcript.
143
138
  */
144
139
  get(id: string): Promise<Transcript> {
@@ -147,19 +142,17 @@ export class TranscriptService
147
142
 
148
143
  /**
149
144
  * Retrieves a page of transcript listings.
150
- * @param parameters The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
145
+ * @param params - The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
151
146
  */
152
- async list(
153
- parameters?: ListTranscriptParams | string
154
- ): Promise<TranscriptList> {
147
+ async list(params?: ListTranscriptParams | string): Promise<TranscriptList> {
155
148
  let url = "/v2/transcript";
156
- if (typeof parameters === "string") {
157
- url = parameters;
158
- } else if (parameters) {
149
+ if (typeof params === "string") {
150
+ url = params;
151
+ } else if (params) {
159
152
  url = `${url}?${new URLSearchParams(
160
- Object.keys(parameters).map((key) => [
153
+ Object.keys(params).map((key) => [
161
154
  key,
162
- parameters[key as keyof ListTranscriptParams]?.toString() || "",
155
+ params[key as keyof ListTranscriptParams]?.toString() || "",
163
156
  ])
164
157
  )}`;
165
158
  }
@@ -176,7 +169,7 @@ export class TranscriptService
176
169
 
177
170
  /**
178
171
  * Delete a transcript
179
- * @param id The identifier of the transcript.
172
+ * @param id - The identifier of the transcript.
180
173
  * @returns A promise that resolves to the transcript.
181
174
  */
182
175
  delete(id: string): Promise<Transcript> {
@@ -186,9 +179,9 @@ export class TranscriptService
186
179
  /**
187
180
  * Search through the transcript for a specific set of keywords.
188
181
  * You can search for individual words, numbers, or phrases containing up to five words or numbers.
189
- * @param id The identifier of the transcript.
190
- * @param words Keywords to search for.
191
- * @return A promise that resolves to the sentences.
182
+ * @param id - The identifier of the transcript.
183
+ * @param words - Keywords to search for.
184
+ * @returns A promise that resolves to the sentences.
192
185
  */
193
186
  wordSearch(id: string, words: string[]): Promise<WordSearchResponse> {
194
187
  const params = new URLSearchParams({ words: words.join(",") });
@@ -199,8 +192,8 @@ export class TranscriptService
199
192
 
200
193
  /**
201
194
  * Retrieve all sentences of a transcript.
202
- * @param id The identifier of the transcript.
203
- * @return A promise that resolves to the sentences.
195
+ * @param id - The identifier of the transcript.
196
+ * @returns A promise that resolves to the sentences.
204
197
  */
205
198
  sentences(id: string): Promise<SentencesResponse> {
206
199
  return this.fetchJson<SentencesResponse>(`/v2/transcript/${id}/sentences`);
@@ -208,8 +201,8 @@ export class TranscriptService
208
201
 
209
202
  /**
210
203
  * Retrieve all paragraphs of a transcript.
211
- * @param id The identifier of the transcript.
212
- * @return A promise that resolves to the paragraphs.
204
+ * @param id - The identifier of the transcript.
205
+ * @returns A promise that resolves to the paragraphs.
213
206
  */
214
207
  paragraphs(id: string): Promise<ParagraphsResponse> {
215
208
  return this.fetchJson<ParagraphsResponse>(
@@ -219,10 +212,10 @@ export class TranscriptService
219
212
 
220
213
  /**
221
214
  * Retrieve subtitles of a transcript.
222
- * @param id The identifier of the transcript.
223
- * @param format The format of the subtitles.
224
- * @param chars_per_caption The maximum number of characters per caption.
225
- * @return A promise that resolves to the subtitles text.
215
+ * @param id - The identifier of the transcript.
216
+ * @param format - The format of the subtitles.
217
+ * @param chars_per_caption - The maximum number of characters per caption.
218
+ * @returns A promise that resolves to the subtitles text.
226
219
  */
227
220
  async subtitles(
228
221
  id: string,
@@ -241,8 +234,8 @@ export class TranscriptService
241
234
 
242
235
  /**
243
236
  * Retrieve redactions of a transcript.
244
- * @param id The identifier of the transcript.
245
- * @return A promise that resolves to the subtitles text.
237
+ * @param id - The identifier of the transcript.
238
+ * @returns A promise that resolves to the subtitles text.
246
239
  */
247
240
  redactions(id: string): Promise<RedactedAudioResponse> {
248
241
  return this.fetchJson<RedactedAudioResponse>(
@@ -1,7 +1,6 @@
1
1
  // this file is generated by typescript/scripts/generate-types.ts
2
2
  /* tslint:disable */
3
3
  /* eslint-disable */
4
-
5
4
  import { LiteralUnion } from "./helpers";
6
5
 
7
6
  /** OneOf type helpers */
@@ -15,44 +14,54 @@ type OneOf<T extends any[]> = T extends [infer Only]
15
14
  ? OneOf<[XOR<A, B>, ...Rest]>
16
15
  : never;
17
16
 
17
+ /* eslint-enable */
18
+
18
19
  /**
19
- * Format: binary
20
- * @description Binary audio data
20
+ * Binary audio data
21
21
  */
22
22
  export type AudioData = ArrayBufferLike;
23
23
 
24
24
  /**
25
- * @description The encoding of the audio data
26
- * @default pcm_s16le
27
- * @enum {string}
25
+ * The encoding of the audio data
26
+ * @defaultValue "pcm_s16"le
28
27
  */
29
28
  export type AudioEncoding = "pcm_s16le" | "pcm_mulaw";
30
29
 
31
- /** @description Configure the threshold for how long to wait before ending an utterance. Default is 700ms. */
30
+ /**
31
+ * Configure the threshold for how long to wait before ending an utterance. Default is 700ms.
32
+ */
32
33
  export type ConfigureEndUtteranceSilenceThreshold = {
33
- /** @description The duration threshold in milliseconds */
34
+ /**
35
+ * The duration threshold in milliseconds
36
+ */
34
37
  end_utterance_silence_threshold: number;
35
38
  };
36
39
 
37
40
  export type FinalTranscript = RealtimeBaseTranscript & {
38
41
  /**
39
- * @description Describes the type of message
40
- * @constant
42
+ * Describes the type of message
41
43
  */
42
44
  message_type: "FinalTranscript";
43
- /** @description Whether the text is punctuated and cased */
45
+ /**
46
+ * Whether the text is punctuated and cased
47
+ */
44
48
  punctuated: boolean;
45
- /** @description Whether the text is formatted, for example Dollar -> $ */
49
+ /**
50
+ * Whether the text is formatted, for example Dollar -&gt; $
51
+ */
46
52
  text_formatted: boolean;
47
53
  };
48
54
 
49
- /** @description Manually end an utterance */
55
+ /**
56
+ * Manually end an utterance
57
+ */
50
58
  export type ForceEndUtterance = {
51
- /** @description A boolean value to communicate that you wish to force the end of the utterance */
59
+ /**
60
+ * A boolean value to communicate that you wish to force the end of the utterance
61
+ */
52
62
  force_end_utterance: boolean;
53
63
  };
54
64
 
55
- /** @enum {string} */
56
65
  export type MessageType =
57
66
  | "SessionBegins"
58
67
  | "PartialTranscript"
@@ -61,33 +70,41 @@ export type MessageType =
61
70
 
62
71
  export type PartialTranscript = RealtimeBaseTranscript & {
63
72
  /**
64
- * @description Describes the type of message
65
- * @constant
73
+ * Describes the type of message
66
74
  */
67
75
  message_type: "PartialTranscript";
68
76
  };
69
77
 
70
78
  export type RealtimeBaseMessage = {
71
- /** @description Describes the type of the message */
79
+ /**
80
+ * Describes the type of the message
81
+ */
72
82
  message_type: MessageType;
73
83
  };
74
84
 
75
85
  export type RealtimeBaseTranscript = {
76
- /** @description End time of audio sample relative to session start, in milliseconds */
86
+ /**
87
+ * End time of audio sample relative to session start, in milliseconds
88
+ */
77
89
  audio_end: number;
78
- /** @description Start time of audio sample relative to session start, in milliseconds */
90
+ /**
91
+ * Start time of audio sample relative to session start, in milliseconds
92
+ */
79
93
  audio_start: number;
80
94
  /**
81
- * Format: double
82
- * @description The confidence score of the entire transcription, between 0 and 1
95
+ * The confidence score of the entire transcription, between 0 and 1
83
96
  */
84
97
  confidence: number;
85
- /** @description The timestamp for the partial transcript */
98
+ /**
99
+ * The timestamp for the partial transcript
100
+ */
86
101
  created: Date;
87
- /** @description The partial transcript for your audio */
102
+ /**
103
+ * The partial transcript for your audio
104
+ */
88
105
  text: string;
89
106
  /**
90
- * @description An array of objects, with the information for each word in the transcription text.
107
+ * An array of objects, with the information for each word in the transcription text.
91
108
  * Includes the start and end time of the word in milliseconds, the confidence score of the word, and the text, which is the word itself.
92
109
  */
93
110
  words: Word[];
@@ -106,47 +123,52 @@ export type RealtimeMessage =
106
123
 
107
124
  export type RealtimeTranscript = PartialTranscript | FinalTranscript;
108
125
 
109
- /** @enum {string} */
110
126
  export type RealtimeTranscriptType = "PartialTranscript" | "FinalTranscript";
111
127
 
112
128
  export type SessionBegins = RealtimeBaseMessage & {
113
- /** @description Timestamp when this session will expire */
129
+ /**
130
+ * Timestamp when this session will expire
131
+ */
114
132
  expires_at: Date;
115
133
  /**
116
- * @description Describes the type of the message
117
- * @constant
134
+ * Describes the type of the message
118
135
  */
119
136
  message_type: "SessionBegins";
120
137
  /**
121
- * Format: uuid
122
- * @description Unique identifier for the established session
138
+ * Unique identifier for the established session
123
139
  */
124
140
  session_id: string;
125
141
  };
126
142
 
127
143
  export type SessionTerminated = RealtimeBaseMessage & {
128
144
  /**
129
- * @description Describes the type of the message
130
- * @constant
145
+ * Describes the type of the message
131
146
  */
132
147
  message_type: "SessionTerminated";
133
148
  };
134
149
 
135
- export type TerminateSession = RealtimeBaseMessage & {
136
- /** @description Set to true to end your real-time session forever */
150
+ export type TerminateSession = {
151
+ /**
152
+ * Set to true to end your real-time session forever
153
+ */
137
154
  terminate_session: boolean;
138
155
  };
139
156
 
140
157
  export type Word = {
141
158
  /**
142
- * Format: double
143
- * @description Confidence score of the word
159
+ * Confidence score of the word
144
160
  */
145
161
  confidence: number;
146
- /** @description End time of the word in milliseconds */
162
+ /**
163
+ * End time of the word in milliseconds
164
+ */
147
165
  end: number;
148
- /** @description Start time of the word in milliseconds */
166
+ /**
167
+ * Start time of the word in milliseconds
168
+ */
149
169
  start: number;
150
- /** @description The word itself */
170
+ /**
171
+ * The word itself
172
+ */
151
173
  text: string;
152
174
  };