assemblyai 3.0.1 → 3.1.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/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  [![AssemblyAI Twitter](https://img.shields.io/twitter/follow/AssemblyAI?label=%40AssemblyAI&style=social)](https://twitter.com/AssemblyAI)
9
9
  [![AssemblyAI YouTube](https://img.shields.io/youtube/channel/subscribers/UCtatfZMf-8EkIwASXM4ts0A)](https://www.youtube.com/@AssemblyAI)
10
10
  [![Discord](https://img.shields.io/discord/875120158014853141?logo=discord&label=Discord&link=https%3A%2F%2Fdiscord.com%2Fchannels%2F875120158014853141&style=social)
11
- ](https://discord.gg/5aQNZyq3)
11
+ ](https://assemblyai.com/discord)
12
12
 
13
13
  # AssemblyAI Node.js SDK
14
14
 
@@ -79,7 +79,7 @@ const transcript = await client.transcripts.create({
79
79
  poll: true,
80
80
  // How frequently the transcript is polled in ms. Defaults to 3000.
81
81
  pollingInterval: 1000,
82
- // How long to wait in ms until the "Polling timeout" error is thrown. Defaults to 180000.
82
+ // How long to wait in ms until the "Polling timeout" error is thrown. Defaults to infinite (-1).
83
83
  pollingTimeout: 5000,
84
84
  })
85
85
  ```
@@ -92,9 +92,21 @@ This will return the transcript object in its current state. If the transcript i
92
92
  const transcript = await client.transcripts.get(transcript.id)
93
93
  ```
94
94
 
95
+ If you disabled polling during transcript creation, you can still poll until the transcript `status` is `completed` or `error` using `waitUntilReady`:
96
+
97
+ ```javascript
98
+ const transcript = await client.transcripts.waitUntilReady(transcript.id,
99
+ {
100
+ // How frequently the transcript is polled in ms. Defaults to 3000.
101
+ pollingInterval: 1000,
102
+ // How long to wait in ms until the "Polling timeout" error is thrown. Defaults to infinite (-1).
103
+ pollingTimeout: 5000,
104
+ })
105
+ ```
106
+
95
107
  ## List transcripts
96
108
 
97
- This will return a page of transcripts that you have transcript.
109
+ This will return a page of transcripts you created.
98
110
 
99
111
  ```javascript
100
112
  const page = await client.transcripts.list()
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export type * from "./types";
1
+ export * from "./types";
2
2
  export * from "./services";
package/dist/index.esm.js CHANGED
@@ -354,14 +354,16 @@ class TranscriptService extends BaseService {
354
354
  body: JSON.stringify(params),
355
355
  });
356
356
  if ((_a = options === null || options === void 0 ? void 0 : options.poll) !== null && _a !== void 0 ? _a : true) {
357
- return yield this.poll(data.id, options);
357
+ return yield this.waitUntilReady(data.id, options);
358
358
  }
359
359
  return data;
360
360
  });
361
361
  }
362
- poll(transcriptId, options) {
363
- var _a;
362
+ waitUntilReady(transcriptId, options) {
363
+ var _a, _b;
364
364
  return __awaiter(this, void 0, void 0, function* () {
365
+ const pollingInterval = (_a = options === null || options === void 0 ? void 0 : options.pollingInterval) !== null && _a !== void 0 ? _a : 3000;
366
+ const pollingTimeout = (_b = options === null || options === void 0 ? void 0 : options.pollingTimeout) !== null && _b !== void 0 ? _b : -1;
365
367
  const startTime = Date.now();
366
368
  // eslint-disable-next-line no-constant-condition
367
369
  while (true) {
@@ -369,12 +371,12 @@ class TranscriptService extends BaseService {
369
371
  if (transcript.status === "completed" || transcript.status === "error") {
370
372
  return transcript;
371
373
  }
372
- else if (Date.now() - startTime <
373
- ((_a = options === null || options === void 0 ? void 0 : options.pollingTimeout) !== null && _a !== void 0 ? _a : 180000)) {
374
- yield new Promise((resolve) => { var _a; return setTimeout(resolve, (_a = options === null || options === void 0 ? void 0 : options.pollingInterval) !== null && _a !== void 0 ? _a : 3000); });
374
+ else if (pollingTimeout > 0 &&
375
+ Date.now() - startTime > pollingTimeout) {
376
+ throw new Error("Polling timeout");
375
377
  }
376
378
  else {
377
- throw new Error("Polling timeout");
379
+ yield new Promise((resolve) => setTimeout(resolve, pollingInterval));
378
380
  }
379
381
  }
380
382
  });
@@ -432,7 +434,8 @@ class TranscriptService extends BaseService {
432
434
  * @return A promise that resolves to the sentences.
433
435
  */
434
436
  wordSearch(id, words) {
435
- return this.fetchJson(`/v2/transcript/${id}/word-search?words=${JSON.stringify(words)}`);
437
+ const params = new URLSearchParams({ words: words.join(",") });
438
+ return this.fetchJson(`/v2/transcript/${id}/word-search?${params.toString()}`);
436
439
  }
437
440
  /**
438
441
  * Retrieve all sentences of a transcript.
@@ -454,11 +457,18 @@ class TranscriptService extends BaseService {
454
457
  * Retrieve subtitles of a transcript.
455
458
  * @param id The identifier of the transcript.
456
459
  * @param format The format of the subtitles.
460
+ * @param chars_per_caption The maximum number of characters per caption.
457
461
  * @return A promise that resolves to the subtitles text.
458
462
  */
459
- subtitles(id, format = "srt") {
463
+ subtitles(id, format = "srt", chars_per_caption) {
460
464
  return __awaiter(this, void 0, void 0, function* () {
461
- const response = yield this.fetch(`/v2/transcript/${id}/${format}`);
465
+ let url = `/v2/transcript/${id}/${format}`;
466
+ if (chars_per_caption) {
467
+ const params = new URLSearchParams();
468
+ params.set("chars_per_caption", chars_per_caption.toString());
469
+ url += `?${params.toString()}`;
470
+ }
471
+ const response = yield this.fetch(url);
462
472
  return yield response.text();
463
473
  });
464
474
  }
package/dist/index.js CHANGED
@@ -356,14 +356,16 @@ class TranscriptService extends BaseService {
356
356
  body: JSON.stringify(params),
357
357
  });
358
358
  if ((_a = options === null || options === void 0 ? void 0 : options.poll) !== null && _a !== void 0 ? _a : true) {
359
- return yield this.poll(data.id, options);
359
+ return yield this.waitUntilReady(data.id, options);
360
360
  }
361
361
  return data;
362
362
  });
363
363
  }
364
- poll(transcriptId, options) {
365
- var _a;
364
+ waitUntilReady(transcriptId, options) {
365
+ var _a, _b;
366
366
  return __awaiter(this, void 0, void 0, function* () {
367
+ const pollingInterval = (_a = options === null || options === void 0 ? void 0 : options.pollingInterval) !== null && _a !== void 0 ? _a : 3000;
368
+ const pollingTimeout = (_b = options === null || options === void 0 ? void 0 : options.pollingTimeout) !== null && _b !== void 0 ? _b : -1;
367
369
  const startTime = Date.now();
368
370
  // eslint-disable-next-line no-constant-condition
369
371
  while (true) {
@@ -371,12 +373,12 @@ class TranscriptService extends BaseService {
371
373
  if (transcript.status === "completed" || transcript.status === "error") {
372
374
  return transcript;
373
375
  }
374
- else if (Date.now() - startTime <
375
- ((_a = options === null || options === void 0 ? void 0 : options.pollingTimeout) !== null && _a !== void 0 ? _a : 180000)) {
376
- yield new Promise((resolve) => { var _a; return setTimeout(resolve, (_a = options === null || options === void 0 ? void 0 : options.pollingInterval) !== null && _a !== void 0 ? _a : 3000); });
376
+ else if (pollingTimeout > 0 &&
377
+ Date.now() - startTime > pollingTimeout) {
378
+ throw new Error("Polling timeout");
377
379
  }
378
380
  else {
379
- throw new Error("Polling timeout");
381
+ yield new Promise((resolve) => setTimeout(resolve, pollingInterval));
380
382
  }
381
383
  }
382
384
  });
@@ -434,7 +436,8 @@ class TranscriptService extends BaseService {
434
436
  * @return A promise that resolves to the sentences.
435
437
  */
436
438
  wordSearch(id, words) {
437
- return this.fetchJson(`/v2/transcript/${id}/word-search?words=${JSON.stringify(words)}`);
439
+ const params = new URLSearchParams({ words: words.join(",") });
440
+ return this.fetchJson(`/v2/transcript/${id}/word-search?${params.toString()}`);
438
441
  }
439
442
  /**
440
443
  * Retrieve all sentences of a transcript.
@@ -456,11 +459,18 @@ class TranscriptService extends BaseService {
456
459
  * Retrieve subtitles of a transcript.
457
460
  * @param id The identifier of the transcript.
458
461
  * @param format The format of the subtitles.
462
+ * @param chars_per_caption The maximum number of characters per caption.
459
463
  * @return A promise that resolves to the subtitles text.
460
464
  */
461
- subtitles(id, format = "srt") {
465
+ subtitles(id, format = "srt", chars_per_caption) {
462
466
  return __awaiter(this, void 0, void 0, function* () {
463
- const response = yield this.fetch(`/v2/transcript/${id}/${format}`);
467
+ let url = `/v2/transcript/${id}/${format}`;
468
+ if (chars_per_caption) {
469
+ const params = new URLSearchParams();
470
+ params.set("chars_per_caption", chars_per_caption.toString());
471
+ url += `?${params.toString()}`;
472
+ }
473
+ const response = yield this.fetch(url);
464
474
  return yield response.text();
465
475
  });
466
476
  }
@@ -1,5 +1,5 @@
1
1
  import { BaseService } from "../base";
2
- import { ParagraphsResponse, SentencesResponse, Transcript, TranscriptList, CreateTranscriptParameters, CreateTranscriptOptions, Createable, Deletable, Listable, Retrieveable, SubtitleFormat, RedactedAudioResponse, TranscriptListParameters, WordSearchResponse, BaseServiceParams } from "../..";
2
+ import { ParagraphsResponse, SentencesResponse, Transcript, TranscriptList, CreateTranscriptParameters, CreateTranscriptOptions, Createable, Deletable, Listable, Retrieveable, SubtitleFormat, RedactedAudioResponse, TranscriptListParameters, WordSearchResponse, BaseServiceParams, PollingOptions } from "../..";
3
3
  import { FileService } from "../files";
4
4
  export declare class TranscriptService extends BaseService implements Createable<Transcript, CreateTranscriptParameters, CreateTranscriptOptions>, Retrieveable<Transcript>, Deletable<Transcript>, Listable<TranscriptList> {
5
5
  private files;
@@ -11,7 +11,7 @@ export declare class TranscriptService extends BaseService implements Createable
11
11
  * @returns A promise that resolves to the newly created transcript.
12
12
  */
13
13
  create(params: CreateTranscriptParameters, options?: CreateTranscriptOptions): Promise<Transcript>;
14
- private poll;
14
+ waitUntilReady(transcriptId: string, options?: PollingOptions): Promise<Transcript>;
15
15
  /**
16
16
  * Retrieve a transcript.
17
17
  * @param id The identifier of the transcript.
@@ -53,9 +53,10 @@ export declare class TranscriptService extends BaseService implements Createable
53
53
  * Retrieve subtitles of a transcript.
54
54
  * @param id The identifier of the transcript.
55
55
  * @param format The format of the subtitles.
56
+ * @param chars_per_caption The maximum number of characters per caption.
56
57
  * @return A promise that resolves to the subtitles text.
57
58
  */
58
- subtitles(id: string, format?: SubtitleFormat): Promise<string>;
59
+ subtitles(id: string, format?: SubtitleFormat, chars_per_caption?: number): Promise<string>;
59
60
  /**
60
61
  * Retrieve redactions of a transcript.
61
62
  * @param id The identifier of the transcript.
@@ -1,46 +1,49 @@
1
1
  export type AudioData = {
2
- /** @description Raw audio data, base64 encoded. This can be the raw data recorded directly from a microphone or read from an audio file. */
2
+ /** @description Base64 encoded raw audio data */
3
3
  audio_data: string;
4
4
  };
5
5
  export type FinalTranscript = RealtimeBaseTranscript & {
6
6
  /**
7
- * @description Describes the type of message.
7
+ * @description Describes the type of message
8
8
  * @constant
9
9
  */
10
10
  message_type: "FinalTranscript";
11
- /** @description Whether the text has been punctuated and cased. */
11
+ /** @description Whether the text is punctuated and cased */
12
12
  punctuated: boolean;
13
- /** @description Whether the text has been formatted (e.g. Dollar -> $) */
13
+ /** @description Whether the text is formatted, for example Dollar -> $ */
14
14
  text_formatted: boolean;
15
15
  };
16
16
  /** @enum {string} */
17
17
  export type MessageType = "SessionBegins" | "PartialTranscript" | "FinalTranscript" | "SessionTerminated";
18
18
  export type PartialTranscript = RealtimeBaseTranscript & {
19
19
  /**
20
- * @description Describes the type of message.
20
+ * @description Describes the type of message
21
21
  * @constant
22
22
  */
23
23
  message_type: "PartialTranscript";
24
24
  };
25
25
  export type RealtimeBaseMessage = {
26
- /** @description Describes the type of the message. */
26
+ /** @description Describes the type of the message */
27
27
  message_type: MessageType;
28
28
  };
29
29
  export type RealtimeBaseTranscript = {
30
- /** @description End time of audio sample relative to session start, in milliseconds. */
30
+ /** @description End time of audio sample relative to session start, in milliseconds */
31
31
  audio_end: number;
32
- /** @description Start time of audio sample relative to session start, in milliseconds. */
32
+ /** @description Start time of audio sample relative to session start, in milliseconds */
33
33
  audio_start: number;
34
34
  /**
35
35
  * Format: double
36
- * @description The confidence score of the entire transcription, between 0 and 1.
36
+ * @description The confidence score of the entire transcription, between 0 and 1
37
37
  */
38
38
  confidence: number;
39
- /** @description The timestamp for the partial transcript. */
39
+ /** @description The timestamp for the partial transcript */
40
40
  created: Date;
41
- /** @description The partial transcript for your audio. */
41
+ /** @description The partial transcript for your audio */
42
42
  text: string;
43
- /** @description An array of objects, with the information for each word in the transcription text. Includes the start/end time (in milliseconds) of the word, the confidence score of the word, and the text (i.e. the word itself). */
43
+ /**
44
+ * @description An array of objects, with the information for each word in the transcription text.
45
+ * 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.
46
+ */
44
47
  words: Word[];
45
48
  };
46
49
  export type RealtimeError = {
@@ -51,25 +54,25 @@ export type RealtimeTranscript = PartialTranscript | FinalTranscript;
51
54
  /** @enum {string} */
52
55
  export type RealtimeTranscriptType = "PartialTranscript" | "FinalTranscript";
53
56
  export type SessionBegins = RealtimeBaseMessage & {
54
- /** @description Timestamp when this session will expire. */
57
+ /** @description Timestamp when this session will expire */
55
58
  expires_at: Date;
56
59
  /**
57
- * @description Describes the type of the message.
60
+ * @description Describes the type of the message
58
61
  * @constant
59
62
  */
60
63
  message_type: "SessionBegins";
61
- /** @description Unique identifier for the established session. */
64
+ /** @description Unique identifier for the established session */
62
65
  session_id: string;
63
66
  };
64
67
  export type SessionTerminated = RealtimeBaseMessage & {
65
68
  /**
66
- * @description Describes the type of the message.
69
+ * @description Describes the type of the message
67
70
  * @constant
68
71
  */
69
72
  message_type: "SessionTerminated";
70
73
  };
71
74
  export type TerminateSession = RealtimeBaseMessage & {
72
- /** @description A boolean value to communicate that you wish to end your real-time session forever. */
75
+ /** @description Set to true to end your real-time session forever */
73
76
  terminate_session: boolean;
74
77
  };
75
78
  export type Word = {
@@ -1,6 +1,6 @@
1
- export type * from "./files";
2
- export type * from "./transcripts";
3
- export type * from "./realtime";
4
- export type * from "./services";
5
- export type * from "./asyncapi.generated";
6
- export type * from "./openapi.generated";
1
+ export * from "./files";
2
+ export * from "./transcripts";
3
+ export * from "./realtime";
4
+ export * from "./services";
5
+ export * from "./asyncapi.generated";
6
+ export * from "./openapi.generated";