assemblyai 3.0.0 → 3.0.1

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/index.js CHANGED
@@ -1,26 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var axios = require('axios');
4
3
  var WebSocket = require('ws');
5
- var stream = require('stream');
4
+ var Stream = require('stream');
6
5
  var fs = require('fs');
7
6
 
8
- function createAxiosClient(params) {
9
- const client = axios.create({
10
- baseURL: params.baseUrl,
11
- headers: { Authorization: params.apiKey },
12
- });
13
- client.interceptors.response.use(undefined, throwApiError);
14
- return client;
15
- }
16
- function throwApiError(error) {
17
- var _a, _b;
18
- if (axios.isAxiosError(error) && ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)) {
19
- return Promise.reject(new Error(error.response.data.error));
20
- }
21
- return Promise.reject(error);
22
- }
23
-
24
7
  /******************************************************************************
25
8
  Copyright (c) Microsoft Corporation.
26
9
 
@@ -59,36 +42,70 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
59
42
  class BaseService {
60
43
  /**
61
44
  * Create a new service.
62
- * @param params The AxiosInstance to send HTTP requests to the API.
45
+ * @param params The parameters to use for the service.
63
46
  */
64
- constructor(client) {
65
- this.client = client;
47
+ constructor(params) {
48
+ this.params = params;
49
+ }
50
+ fetch(input, init) {
51
+ var _a;
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ init = init !== null && init !== void 0 ? init : {};
54
+ init.headers = (_a = init.headers) !== null && _a !== void 0 ? _a : {};
55
+ init.headers = Object.assign({ Authorization: this.params.apiKey, "Content-Type": "application/json" }, init.headers);
56
+ if (!input.startsWith("http"))
57
+ input = this.params.baseUrl + input;
58
+ const response = yield fetch(input, init);
59
+ if (response.status >= 400) {
60
+ let json;
61
+ const text = yield response.text();
62
+ if (text) {
63
+ try {
64
+ json = JSON.parse(text);
65
+ }
66
+ catch (_b) {
67
+ /* empty */
68
+ }
69
+ if (json === null || json === void 0 ? void 0 : json.error)
70
+ throw new Error(json.error);
71
+ throw new Error(text);
72
+ }
73
+ throw new Error(`HTTP Error: ${response.status} ${response.statusText}`);
74
+ }
75
+ return response;
76
+ });
77
+ }
78
+ fetchJson(input, init) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ const response = yield this.fetch(input, init);
81
+ return response.json();
82
+ });
66
83
  }
67
84
  }
68
85
 
69
86
  class LemurService extends BaseService {
70
87
  summary(params) {
71
- return __awaiter(this, void 0, void 0, function* () {
72
- const { data } = yield this.client.post("/lemur/v3/generate/summary", params);
73
- return data;
88
+ return this.fetchJson("/lemur/v3/generate/summary", {
89
+ method: "POST",
90
+ body: JSON.stringify(params),
74
91
  });
75
92
  }
76
93
  questionAnswer(params) {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- const { data } = yield this.client.post("/lemur/v3/generate/question-answer", params);
79
- return data;
94
+ return this.fetchJson("/lemur/v3/generate/question-answer", {
95
+ method: "POST",
96
+ body: JSON.stringify(params),
80
97
  });
81
98
  }
82
99
  actionItems(params) {
83
- return __awaiter(this, void 0, void 0, function* () {
84
- const { data } = yield this.client.post("/lemur/v3/generate/action-items", params);
85
- return data;
100
+ return this.fetchJson("/lemur/v3/generate/action-items", {
101
+ method: "POST",
102
+ body: JSON.stringify(params),
86
103
  });
87
104
  }
88
105
  task(params) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- const { data } = yield this.client.post("/lemur/v3/generate/task", params);
91
- return data;
106
+ return this.fetchJson("/lemur/v3/generate/task", {
107
+ method: "POST",
108
+ body: JSON.stringify(params),
92
109
  });
93
110
  }
94
111
  /**
@@ -96,9 +113,8 @@ class LemurService extends BaseService {
96
113
  * @param id ID of the LeMUR request
97
114
  */
98
115
  purgeRequestData(id) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- const { data } = yield this.client.delete(`/lemur/v3/${id}`);
101
- return data;
116
+ return this.fetchJson(`/lemur/v3/${id}`, {
117
+ method: "DELETE",
102
118
  });
103
119
  }
104
120
  }
@@ -147,12 +163,11 @@ class RealtimeError extends Error {
147
163
  const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
148
164
  class RealtimeService {
149
165
  constructor(params) {
150
- var _a, _b, _c;
166
+ var _a, _b;
151
167
  this.listeners = {};
152
168
  this.realtimeUrl = (_a = params.realtimeUrl) !== null && _a !== void 0 ? _a : defaultRealtimeUrl;
153
169
  this.sampleRate = (_b = params.sampleRate) !== null && _b !== void 0 ? _b : 16000;
154
170
  this.wordBoost = params.wordBoost;
155
- this.realtimeUrl = (_c = params.realtimeUrl) !== null && _c !== void 0 ? _c : defaultRealtimeUrl;
156
171
  if ("apiKey" in params)
157
172
  this.apiKey = params.apiKey;
158
173
  if ("token" in params)
@@ -260,13 +275,13 @@ class RealtimeService {
260
275
  this.socket.send(JSON.stringify(payload));
261
276
  }
262
277
  stream() {
263
- const stream$1 = new stream.Writable({
278
+ const stream = new Stream.Writable({
264
279
  write: (chunk, encoding, next) => {
265
280
  this.sendAudio(chunk);
266
281
  next();
267
282
  },
268
283
  });
269
- return stream$1;
284
+ return stream;
270
285
  }
271
286
  close(waitForSessionTermination = true) {
272
287
  return __awaiter(this, void 0, void 0, function* () {
@@ -293,30 +308,33 @@ class RealtimeService {
293
308
  }
294
309
  }
295
310
 
296
- class RealtimeServiceFactory {
297
- constructor(client, params) {
298
- this.client = client;
299
- this.params = params;
311
+ class RealtimeServiceFactory extends BaseService {
312
+ constructor(params) {
313
+ super(params);
314
+ this.rtFactoryParams = params;
300
315
  }
301
316
  createService(params) {
302
317
  if (!params)
303
- params = { apiKey: this.params.apiKey };
318
+ params = { apiKey: this.rtFactoryParams.apiKey };
304
319
  else if (!("token" in params) && !params.apiKey) {
305
- params.apiKey = this.params.apiKey;
320
+ params.apiKey = this.rtFactoryParams.apiKey;
306
321
  }
307
322
  return new RealtimeService(params);
308
323
  }
309
324
  createTemporaryToken(params) {
310
325
  return __awaiter(this, void 0, void 0, function* () {
311
- const response = yield this.client.post("/v2/realtime/token", params);
312
- return response.data.token;
326
+ const data = yield this.fetchJson("/v2/realtime/token", {
327
+ method: "POST",
328
+ body: JSON.stringify(params),
329
+ });
330
+ return data.token;
313
331
  });
314
332
  }
315
333
  }
316
334
 
317
335
  class TranscriptService extends BaseService {
318
- constructor(client, files) {
319
- super(client);
336
+ constructor(params, files) {
337
+ super(params);
320
338
  this.files = files;
321
339
  }
322
340
  /**
@@ -333,11 +351,14 @@ class TranscriptService extends BaseService {
333
351
  const uploadUrl = yield this.files.upload(path);
334
352
  params.audio_url = uploadUrl;
335
353
  }
336
- const res = yield this.client.post("/v2/transcript", params);
354
+ const data = yield this.fetchJson("/v2/transcript", {
355
+ method: "POST",
356
+ body: JSON.stringify(params),
357
+ });
337
358
  if ((_a = options === null || options === void 0 ? void 0 : options.poll) !== null && _a !== void 0 ? _a : true) {
338
- return yield this.poll(res.data.id, options);
359
+ return yield this.poll(data.id, options);
339
360
  }
340
- return res.data;
361
+ return data;
341
362
  });
342
363
  }
343
364
  poll(transcriptId, options) {
@@ -366,10 +387,7 @@ class TranscriptService extends BaseService {
366
387
  * @returns A promise that resolves to the transcript.
367
388
  */
368
389
  get(id) {
369
- return __awaiter(this, void 0, void 0, function* () {
370
- const res = yield this.client.get(`/v2/transcript/${id}`);
371
- return res.data;
372
- });
390
+ return this.fetchJson(`/v2/transcript/${id}`);
373
391
  }
374
392
  /**
375
393
  * Retrieves a page of transcript listings.
@@ -378,16 +396,19 @@ class TranscriptService extends BaseService {
378
396
  list(parameters) {
379
397
  return __awaiter(this, void 0, void 0, function* () {
380
398
  let url = "/v2/transcript";
381
- let query;
382
399
  if (typeof parameters === "string") {
383
400
  url = parameters;
384
401
  }
385
402
  else if (parameters) {
386
- query = parameters;
403
+ url = `${url}?${new URLSearchParams(Object.keys(parameters).map((key) => {
404
+ var _a;
405
+ return [
406
+ key,
407
+ ((_a = parameters[key]) === null || _a === void 0 ? void 0 : _a.toString()) || "",
408
+ ];
409
+ }))}`;
387
410
  }
388
- const { data } = yield this.client.get(url, {
389
- params: query,
390
- });
411
+ const data = yield this.fetchJson(url);
391
412
  for (const transcriptListItem of data.transcripts) {
392
413
  transcriptListItem.created = new Date(transcriptListItem.created);
393
414
  if (transcriptListItem.completed) {
@@ -403,27 +424,17 @@ class TranscriptService extends BaseService {
403
424
  * @returns A promise that resolves to the transcript.
404
425
  */
405
426
  delete(id) {
406
- return __awaiter(this, void 0, void 0, function* () {
407
- const res = yield this.client.delete(`/v2/transcript/${id}`);
408
- return res.data;
409
- });
427
+ return this.fetchJson(`/v2/transcript/${id}`, { method: "DELETE" });
410
428
  }
411
429
  /**
412
430
  * Search through the transcript for a specific set of keywords.
413
431
  * You can search for individual words, numbers, or phrases containing up to five words or numbers.
414
432
  * @param id The identifier of the transcript.
415
- * @param id Keywords to search for.
433
+ * @param words Keywords to search for.
416
434
  * @return A promise that resolves to the sentences.
417
435
  */
418
436
  wordSearch(id, words) {
419
- return __awaiter(this, void 0, void 0, function* () {
420
- const { data } = yield this.client.get(`/v2/transcript/${id}/word-search`, {
421
- params: {
422
- words: JSON.stringify(words),
423
- },
424
- });
425
- return data;
426
- });
437
+ return this.fetchJson(`/v2/transcript/${id}/word-search?words=${JSON.stringify(words)}`);
427
438
  }
428
439
  /**
429
440
  * Retrieve all sentences of a transcript.
@@ -431,10 +442,7 @@ class TranscriptService extends BaseService {
431
442
  * @return A promise that resolves to the sentences.
432
443
  */
433
444
  sentences(id) {
434
- return __awaiter(this, void 0, void 0, function* () {
435
- const { data } = yield this.client.get(`/v2/transcript/${id}/sentences`);
436
- return data;
437
- });
445
+ return this.fetchJson(`/v2/transcript/${id}/sentences`);
438
446
  }
439
447
  /**
440
448
  * Retrieve all paragraphs of a transcript.
@@ -442,10 +450,7 @@ class TranscriptService extends BaseService {
442
450
  * @return A promise that resolves to the paragraphs.
443
451
  */
444
452
  paragraphs(id) {
445
- return __awaiter(this, void 0, void 0, function* () {
446
- const { data } = yield this.client.get(`/v2/transcript/${id}/paragraphs`);
447
- return data;
448
- });
453
+ return this.fetchJson(`/v2/transcript/${id}/paragraphs`);
449
454
  }
450
455
  /**
451
456
  * Retrieve subtitles of a transcript.
@@ -455,8 +460,8 @@ class TranscriptService extends BaseService {
455
460
  */
456
461
  subtitles(id, format = "srt") {
457
462
  return __awaiter(this, void 0, void 0, function* () {
458
- const { data } = yield this.client.get(`/v2/transcript/${id}/${format}`);
459
- return data;
463
+ const response = yield this.fetch(`/v2/transcript/${id}/${format}`);
464
+ return yield response.text();
460
465
  });
461
466
  }
462
467
  /**
@@ -465,10 +470,7 @@ class TranscriptService extends BaseService {
465
470
  * @return A promise that resolves to the subtitles text.
466
471
  */
467
472
  redactions(id) {
468
- return __awaiter(this, void 0, void 0, function* () {
469
- const { data } = yield this.client.get(`/v2/transcript/${id}/redacted-audio`);
470
- return data;
471
- });
473
+ return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
472
474
  }
473
475
  }
474
476
  function getPath(path) {
@@ -498,28 +500,33 @@ class FileService extends BaseService {
498
500
  fileData = fs.createReadStream(input);
499
501
  else
500
502
  fileData = input;
501
- const { data } = yield this.client.post("/v2/upload", fileData, {
503
+ const data = yield this.fetchJson("/v2/upload", {
504
+ method: "POST",
505
+ body: fileData,
502
506
  headers: {
503
507
  "Content-Type": "application/octet-stream",
504
508
  },
509
+ duplex: "half",
505
510
  });
506
511
  return data.upload_url;
507
512
  });
508
513
  }
509
514
  }
510
515
 
516
+ const defaultBaseUrl = "https://api.assemblyai.com";
511
517
  class AssemblyAI {
512
518
  /**
513
519
  * Create a new AssemblyAI client.
514
520
  * @param params The parameters for the service, including the API key and base URL, if any.
515
521
  */
516
522
  constructor(params) {
517
- params.baseUrl = params.baseUrl || "https://api.assemblyai.com";
518
- const client = createAxiosClient(params);
519
- this.files = new FileService(client);
520
- this.transcripts = new TranscriptService(client, this.files);
521
- this.lemur = new LemurService(client);
522
- this.realtime = new RealtimeServiceFactory(client, params);
523
+ params.baseUrl = params.baseUrl || defaultBaseUrl;
524
+ if (params.baseUrl && params.baseUrl.endsWith("/"))
525
+ params.baseUrl = params.baseUrl.slice(0, -1);
526
+ this.files = new FileService(params);
527
+ this.transcripts = new TranscriptService(params, this.files);
528
+ this.lemur = new LemurService(params);
529
+ this.realtime = new RealtimeServiceFactory(params);
523
530
  }
524
531
  }
525
532
 
@@ -1,12 +1,14 @@
1
- import { AxiosInstance } from "axios";
1
+ import { BaseServiceParams } from "..";
2
2
  /**
3
3
  * Base class for services that communicate with the API.
4
4
  */
5
5
  export declare abstract class BaseService {
6
- protected client: AxiosInstance;
6
+ private params;
7
7
  /**
8
8
  * Create a new service.
9
- * @param params The AxiosInstance to send HTTP requests to the API.
9
+ * @param params The parameters to use for the service.
10
10
  */
11
- constructor(client: AxiosInstance);
11
+ constructor(params: BaseServiceParams);
12
+ protected fetch(input: string, init?: RequestInit | undefined): Promise<Response>;
13
+ protected fetchJson<T>(input: string, init?: RequestInit | undefined): Promise<T>;
12
14
  }
@@ -1,5 +1,5 @@
1
- import { BaseService } from "@/services/base";
2
- import { FileUploadParameters } from "@/types";
1
+ import { BaseService } from "../base";
2
+ import { FileUploadParameters } from "../..";
3
3
  export declare class FileService extends BaseService {
4
4
  /**
5
5
  * Upload a local file to AssemblyAI.
@@ -1,4 +1,4 @@
1
- import { BaseServiceParams } from "@/types";
1
+ import { BaseServiceParams } from "..";
2
2
  import { LemurService } from "./lemur";
3
3
  import { RealtimeService, RealtimeServiceFactory } from "./realtime";
4
4
  import { TranscriptService } from "./transcripts";
@@ -1,5 +1,5 @@
1
- import { LemurSummaryParameters, LemurActionItemsParameters, LemurQuestionAnswerParameters, LemurTaskParameters, LemurSummaryResponse, LemurQuestionAnswerResponse, LemurActionItemsResponse, LemurTaskResponse, PurgeLemurRequestDataResponse } from "@/types";
2
- import { BaseService } from "@/services/base";
1
+ import { LemurSummaryParameters, LemurActionItemsParameters, LemurQuestionAnswerParameters, LemurTaskParameters, LemurSummaryResponse, LemurQuestionAnswerResponse, LemurActionItemsResponse, LemurTaskResponse, PurgeLemurRequestDataResponse } from "../..";
2
+ import { BaseService } from "../base";
3
3
  export declare class LemurService extends BaseService {
4
4
  summary(params: LemurSummaryParameters): Promise<LemurSummaryResponse>;
5
5
  questionAnswer(params: LemurQuestionAnswerParameters): Promise<LemurQuestionAnswerResponse>;
@@ -1,10 +1,9 @@
1
- import { BaseServiceParams, RealtimeTokenParams, CreateRealtimeServiceParams } from "@/types";
2
- import { AxiosInstance } from "axios";
1
+ import { BaseServiceParams, RealtimeTokenParams, CreateRealtimeServiceParams } from "../..";
3
2
  import { RealtimeService } from "./service";
4
- export declare class RealtimeServiceFactory {
5
- private client;
6
- private params;
7
- constructor(client: AxiosInstance, params: BaseServiceParams);
3
+ import { BaseService } from "../base";
4
+ export declare class RealtimeServiceFactory extends BaseService {
5
+ private rtFactoryParams;
6
+ constructor(params: BaseServiceParams);
8
7
  createService(params?: CreateRealtimeServiceParams): RealtimeService;
9
8
  createTemporaryToken(params: RealtimeTokenParams): Promise<string>;
10
9
  }
@@ -1,2 +1,2 @@
1
- export * from "@/services/realtime/factory";
2
- export * from "@/services/realtime/service";
1
+ export * from "./factory";
2
+ export * from "./service";
@@ -1,6 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { RealtimeServiceParams, RealtimeTranscript, PartialTranscript, FinalTranscript, SessionBeginsEventData } from "@/types";
3
- import { Writable } from "stream";
2
+ import { RealtimeServiceParams, RealtimeTranscript, PartialTranscript, FinalTranscript, SessionBeginsEventData } from "../..";
4
3
  export declare class RealtimeService {
5
4
  private realtimeUrl;
6
5
  private sampleRate;
@@ -20,6 +19,6 @@ export declare class RealtimeService {
20
19
  on(event: "close", listener: (code: number, reason: string) => void): void;
21
20
  connect(): Promise<SessionBeginsEventData>;
22
21
  sendAudio(audio: ArrayBuffer): void;
23
- stream(): Writable;
22
+ stream(): NodeJS.WritableStream;
24
23
  close(waitForSessionTermination?: boolean): Promise<void>;
25
24
  }
@@ -1,10 +1,9 @@
1
- import { BaseService } from "@/services/base";
2
- import { ParagraphsResponse, SentencesResponse, Transcript, TranscriptList, CreateTranscriptParameters, CreateTranscriptOptions, Createable, Deletable, Listable, Retrieveable, SubtitleFormat, RedactedAudioResponse, TranscriptListParameters, WordSearchResponse } from "@/types";
3
- import { AxiosInstance } from "axios";
1
+ import { BaseService } from "../base";
2
+ import { ParagraphsResponse, SentencesResponse, Transcript, TranscriptList, CreateTranscriptParameters, CreateTranscriptOptions, Createable, Deletable, Listable, Retrieveable, SubtitleFormat, RedactedAudioResponse, TranscriptListParameters, WordSearchResponse, BaseServiceParams } from "../..";
4
3
  import { FileService } from "../files";
5
4
  export declare class TranscriptService extends BaseService implements Createable<Transcript, CreateTranscriptParameters, CreateTranscriptOptions>, Retrieveable<Transcript>, Deletable<Transcript>, Listable<TranscriptList> {
6
5
  private files;
7
- constructor(client: AxiosInstance, files: FileService);
6
+ constructor(params: BaseServiceParams, files: FileService);
8
7
  /**
9
8
  * Create a transcript.
10
9
  * @param params The parameters to create a transcript.
@@ -34,7 +33,7 @@ export declare class TranscriptService extends BaseService implements Createable
34
33
  * Search through the transcript for a specific set of keywords.
35
34
  * You can search for individual words, numbers, or phrases containing up to five words or numbers.
36
35
  * @param id The identifier of the transcript.
37
- * @param id Keywords to search for.
36
+ * @param words Keywords to search for.
38
37
  * @return A promise that resolves to the sentences.
39
38
  */
40
39
  wordSearch(id: string, words: string[]): Promise<WordSearchResponse>;
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
2
  type FileUploadParameters = string | FileUploadData;
4
- type FileUploadData = NodeJS.ReadableStream | ReadableStream | Buffer | ArrayBufferView | ArrayBufferLike | Uint8Array;
3
+ type FileUploadData = NodeJS.ReadableStream | ReadableStream | Blob | BufferSource | ArrayBufferView | ArrayBufferLike | Uint8Array;
5
4
  export type { FileUploadParameters, FileUploadData };
@@ -64,19 +64,24 @@ export type ContentSafetyLabelResult = {
64
64
  sentences_idx_end: number;
65
65
  /** @description The sentence index at which the section begins */
66
66
  sentences_idx_start: number;
67
+ /** @description The transcript of the section flagged by the Content Moderation model */
68
+ text: string;
69
+ /** @description Timestamp information for the section */
70
+ timestamp: Timestamp;
71
+ };
72
+ export type ContentSafetyLabelsResult = {
73
+ results: ContentSafetyLabelResult[];
67
74
  /** @description A summary of the Content Moderation severity results for the entire audio file */
68
75
  severity_score_summary: {
69
76
  [key: string]: SeverityScoreSummary;
70
77
  };
78
+ /** @description Will be either success, or unavailable in the rare case that the Content Moderation model failed. */
79
+ status: AudioIntelligenceModelStatus;
71
80
  /** @description A summary of the Content Moderation confidence results for the entire audio file */
72
81
  summary: {
73
82
  [key: string]: number;
74
83
  };
75
- /** @description The transcript of the section flagged by the Content Moderation model */
76
- text: string;
77
- /** @description Timestamp information for the section */
78
- timestamp: Timestamp;
79
- };
84
+ } | null;
80
85
  export type CreateRealtimeTemporaryTokenParameters = {
81
86
  /** @description The amount of time until the token expires in seconds. */
82
87
  expires_in: number;
@@ -347,7 +352,7 @@ export type SentimentAnalysisResult = {
347
352
  end: number;
348
353
  /** @description The detected sentiment for the sentence, one of POSITIVE, NEUTRAL, NEGATIVE */
349
354
  sentiment: Sentiment;
350
- /** @description The speaker of the sentence if Speaker Diarization is enabled, else null */
355
+ /** @description The speaker of the sentence if [Speaker Diarization](https://www.assemblyai.com/docs/models/speaker-diarization) is enabled, else null */
351
356
  speaker?: string | null;
352
357
  /** @description The starting time, in milliseconds, of the sentence */
353
358
  start: number;
@@ -391,7 +396,7 @@ export type Timestamp = {
391
396
  /** @description The start time in milliseconds */
392
397
  start: number;
393
398
  };
394
- /** @description THe result of the topic detection model. */
399
+ /** @description The result of the topic detection model. */
395
400
  export type TopicDetectionResult = {
396
401
  labels?: {
397
402
  /** @description The IAB taxonomical label for the label of the detected topic, where > denotes supertopic/subtopic relationship */
@@ -448,11 +453,7 @@ export type Transcript = {
448
453
  * @description An array of results for the Content Moderation model, if it was enabled during the transcription request.
449
454
  * See [Content moderation](https://www.assemblyai.com/docs/Models/content_moderation) for more information.
450
455
  */
451
- content_safety_labels?: {
452
- results: ContentSafetyLabelResult[];
453
- /** @description Will be either success, or unavailable in the rare case that the Content Safety Labels model failed. */
454
- status: AudioIntelligenceModelStatus;
455
- } | null;
456
+ content_safety_labels?: ContentSafetyLabelsResult;
456
457
  /** @description Customize how words are spelled and formatted using to and from values */
457
458
  custom_spelling?: TranscriptCustomSpelling[] | null;
458
459
  /** @description Whether custom topics was enabled in the transcription request, either true or false */
@@ -477,7 +478,7 @@ export type Transcript = {
477
478
  /** @description Enable [Topic Detection](https://www.assemblyai.com/docs/Models/iab_classification), can be true or false */
478
479
  iab_categories?: boolean | null;
479
480
  /**
480
- * @description An array of results for the Topic Detection model, if it was enabled during the transcription request.
481
+ * @description The result of the Topic Detection model, if it was enabled during the transcription request.
481
482
  * See [Topic Detection](https://www.assemblyai.com/docs/Models/iab_classification) for more information.
482
483
  */
483
484
  iab_categories_result?: {
@@ -663,12 +664,20 @@ export type TranscriptSentence = {
663
664
  */
664
665
  export type TranscriptStatus = "queued" | "processing" | "completed" | "error";
665
666
  export type TranscriptUtterance = {
666
- channel: string;
667
- /** Format: double */
667
+ /**
668
+ * Format: double
669
+ * @description The confidence score for the transcript of this utterance
670
+ */
668
671
  confidence: number;
672
+ /** @description The ending time, in milliseconds, of the utterance in the audio file */
669
673
  end: number;
674
+ /** @description The speaker of this utterance, where each speaker is assigned a sequential capital letter - e.g. "A" for Speaker A, "B" for Speaker B, etc. */
675
+ speaker: string;
676
+ /** @description The starting time, in milliseconds, of the utterance in the audio file */
670
677
  start: number;
678
+ /** @description The text for this utterance */
671
679
  text: string;
680
+ /** @description The words in the utterance. */
672
681
  words: TranscriptWord[];
673
682
  };
674
683
  export type TranscriptWord = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assemblyai",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
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",
@@ -51,6 +51,7 @@
51
51
  "i": "^0.3.7",
52
52
  "jest": "^29.5.0",
53
53
  "jest-cli": "^29.5.0",
54
+ "jest-fetch-mock": "^3.0.3",
54
55
  "jest-junit": "^16.0.0",
55
56
  "jest-mock-extended": "^3.0.4",
56
57
  "jest-websocket-mock": "^2.4.1",
@@ -67,7 +68,6 @@
67
68
  "typescript": "^5.2.2"
68
69
  },
69
70
  "dependencies": {
70
- "axios": "^1.4.0",
71
71
  "ws": "^8.13.0"
72
72
  }
73
73
  }
@@ -1,4 +1,5 @@
1
- import { AxiosInstance } from "axios";
1
+ import { BaseServiceParams } from "..";
2
+ import { Error as JsonError } from "..";
2
3
 
3
4
  /**
4
5
  * Base class for services that communicate with the API.
@@ -6,7 +7,47 @@ import { AxiosInstance } from "axios";
6
7
  export abstract class BaseService {
7
8
  /**
8
9
  * Create a new service.
9
- * @param params The AxiosInstance to send HTTP requests to the API.
10
+ * @param params The parameters to use for the service.
10
11
  */
11
- constructor(protected client: AxiosInstance) {}
12
+ constructor(private params: BaseServiceParams) {}
13
+ protected async fetch(
14
+ input: string,
15
+ init?: RequestInit | undefined
16
+ ): Promise<Response> {
17
+ init = init ?? {};
18
+ init.headers = init.headers ?? {};
19
+ init.headers = {
20
+ Authorization: this.params.apiKey,
21
+ "Content-Type": "application/json",
22
+ ...init.headers,
23
+ };
24
+ if (!input.startsWith("http")) input = this.params.baseUrl + input;
25
+
26
+ const response = await fetch(input, init);
27
+
28
+ if (response.status >= 400) {
29
+ let json: JsonError | undefined;
30
+ const text = await response.text();
31
+ if (text) {
32
+ try {
33
+ json = JSON.parse(text);
34
+ } catch {
35
+ /* empty */
36
+ }
37
+ if (json?.error) throw new Error(json.error);
38
+ throw new Error(text);
39
+ }
40
+ throw new Error(`HTTP Error: ${response.status} ${response.statusText}`);
41
+ }
42
+
43
+ return response;
44
+ }
45
+
46
+ protected async fetchJson<T>(
47
+ input: string,
48
+ init?: RequestInit | undefined
49
+ ): Promise<T> {
50
+ const response = await this.fetch(input, init);
51
+ return response.json() as Promise<T>;
52
+ }
12
53
  }