assemblyai 2.0.2 → 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.
@@ -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?: {
@@ -620,6 +621,27 @@ export type TranscriptListItem = {
620
621
  resource_url: string;
621
622
  status: TranscriptStatus;
622
623
  };
624
+ export type TranscriptListParameters = {
625
+ /** @description Get transcripts that were created after this transcript ID */
626
+ after_id?: string;
627
+ /** @description Get transcripts that were created before this transcript ID */
628
+ before_id?: string;
629
+ /**
630
+ * Format: date
631
+ * @description Only get transcripts created on this date
632
+ */
633
+ created_on?: string;
634
+ /**
635
+ * Format: int64
636
+ * @description Maximum amount of transcripts to retrieve
637
+ * @default 10
638
+ */
639
+ limit?: number;
640
+ /** @description Filter by transcript status */
641
+ status?: TranscriptStatus;
642
+ /** @description Only get throttled transcripts, overrides the status filter */
643
+ throttled_only?: boolean;
644
+ };
623
645
  export type TranscriptParagraph = {
624
646
  /** Format: double */
625
647
  confidence: number;
@@ -642,12 +664,20 @@ export type TranscriptSentence = {
642
664
  */
643
665
  export type TranscriptStatus = "queued" | "processing" | "completed" | "error";
644
666
  export type TranscriptUtterance = {
645
- channel: string;
646
- /** Format: double */
667
+ /**
668
+ * Format: double
669
+ * @description The confidence score for the transcript of this utterance
670
+ */
647
671
  confidence: number;
672
+ /** @description The ending time, in milliseconds, of the utterance in the audio file */
648
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 */
649
677
  start: number;
678
+ /** @description The text for this utterance */
650
679
  text: string;
680
+ /** @description The words in the utterance. */
651
681
  words: TranscriptWord[];
652
682
  };
653
683
  export type TranscriptWord = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assemblyai",
3
- "version": "2.0.2",
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
  }
package/src/index.ts CHANGED
@@ -1,7 +1,2 @@
1
- import * as services from "./services";
2
- import { AssemblyAI } from "./services";
3
- export * from "./services";
4
1
  export type * from "./types";
5
- export default AssemblyAI;
6
- class AssemblyAIExports extends AssemblyAI {}
7
- module.exports = Object.assign(AssemblyAIExports, services);
2
+ export * from "./services";
@@ -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
  }
@@ -1,22 +1,28 @@
1
- import { readFile } from "fs/promises";
2
- import { BaseService } from "@/services/base";
3
- import { UploadedFile } from "@/types";
1
+ // import the fs module instead if specific named exports
2
+ // to keep the assemblyai module more compatible. Some fs polyfills don't include `createReadStream`.
3
+ import fs from "fs";
4
+ import { BaseService } from "../base";
5
+ import { UploadedFile, FileUploadParameters, FileUploadData } from "../..";
4
6
 
5
7
  export class FileService extends BaseService {
6
8
  /**
7
9
  * Upload a local file to AssemblyAI.
8
- * @param path The local file to upload.
10
+ * @param input The local file path to upload, or a stream or buffer of the file to upload.
9
11
  * @return A promise that resolves to the uploaded file URL.
10
12
  */
11
- async upload(path: string): Promise<string> {
12
- const file = await readFile(path);
13
+ async upload(input: FileUploadParameters): Promise<string> {
14
+ let fileData: FileUploadData;
15
+ if (typeof input === "string") fileData = fs.createReadStream(input);
16
+ else fileData = input;
13
17
 
14
- const { data } = await this.client.post<UploadedFile>("/v2/upload", file, {
18
+ const data = await this.fetchJson<UploadedFile>("/v2/upload", {
19
+ method: "POST",
20
+ body: fileData as BodyInit,
15
21
  headers: {
16
22
  "Content-Type": "application/octet-stream",
17
23
  },
18
- });
19
-
24
+ duplex: "half",
25
+ } as RequestInit);
20
26
  return data.upload_url;
21
27
  }
22
28
  }
@@ -1,10 +1,11 @@
1
- import { createAxiosClient } from "@/utils/axios";
2
- import { BaseServiceParams } from "@/types";
1
+ import { BaseServiceParams } from "..";
3
2
  import { LemurService } from "./lemur";
4
3
  import { RealtimeService, RealtimeServiceFactory } from "./realtime";
5
4
  import { TranscriptService } from "./transcripts";
6
5
  import { FileService } from "./files";
7
6
 
7
+ const defaultBaseUrl = "https://api.assemblyai.com";
8
+
8
9
  class AssemblyAI {
9
10
  /**
10
11
  * The files service.
@@ -31,12 +32,13 @@ class AssemblyAI {
31
32
  * @param params The parameters for the service, including the API key and base URL, if any.
32
33
  */
33
34
  constructor(params: BaseServiceParams) {
34
- params.baseUrl = params.baseUrl || "https://api.assemblyai.com";
35
- const client = createAxiosClient(params);
36
- this.files = new FileService(client);
37
- this.transcripts = new TranscriptService(client, this.files);
38
- this.lemur = new LemurService(client);
39
- this.realtime = new RealtimeServiceFactory(client, params);
35
+ params.baseUrl = params.baseUrl || defaultBaseUrl;
36
+ if (params.baseUrl && params.baseUrl.endsWith("/"))
37
+ params.baseUrl = params.baseUrl.slice(0, -1);
38
+ this.files = new FileService(params);
39
+ this.transcripts = new TranscriptService(params, this.files);
40
+ this.lemur = new LemurService(params);
41
+ this.realtime = new RealtimeServiceFactory(params);
40
42
  }
41
43
  }
42
44
 
@@ -8,54 +8,55 @@ import {
8
8
  LemurActionItemsResponse,
9
9
  LemurTaskResponse,
10
10
  PurgeLemurRequestDataResponse,
11
- } from "@/types";
12
- import { BaseService } from "@/services/base";
11
+ } from "../..";
12
+ import { BaseService } from "../base";
13
13
 
14
14
  export class LemurService extends BaseService {
15
- async summary(params: LemurSummaryParameters): Promise<LemurSummaryResponse> {
16
- const { data } = await this.client.post<LemurSummaryResponse>(
17
- "/lemur/v3/generate/summary",
18
- params
19
- );
20
- return data;
15
+ summary(params: LemurSummaryParameters): Promise<LemurSummaryResponse> {
16
+ return this.fetchJson<LemurSummaryResponse>("/lemur/v3/generate/summary", {
17
+ method: "POST",
18
+ body: JSON.stringify(params),
19
+ });
21
20
  }
22
21
 
23
- async questionAnswer(
22
+ questionAnswer(
24
23
  params: LemurQuestionAnswerParameters
25
24
  ): Promise<LemurQuestionAnswerResponse> {
26
- const { data } = await this.client.post<LemurQuestionAnswerResponse>(
25
+ return this.fetchJson<LemurQuestionAnswerResponse>(
27
26
  "/lemur/v3/generate/question-answer",
28
- params
27
+ {
28
+ method: "POST",
29
+ body: JSON.stringify(params),
30
+ }
29
31
  );
30
- return data;
31
32
  }
32
33
 
33
- async actionItems(
34
+ actionItems(
34
35
  params: LemurActionItemsParameters
35
36
  ): Promise<LemurActionItemsResponse> {
36
- const { data } = await this.client.post<LemurActionItemsResponse>(
37
+ return this.fetchJson<LemurActionItemsResponse>(
37
38
  "/lemur/v3/generate/action-items",
38
- params
39
+ {
40
+ method: "POST",
41
+ body: JSON.stringify(params),
42
+ }
39
43
  );
40
- return data;
41
44
  }
42
45
 
43
- async task(params: LemurTaskParameters): Promise<LemurTaskResponse> {
44
- const { data } = await this.client.post<LemurTaskResponse>(
45
- "/lemur/v3/generate/task",
46
- params
47
- );
48
- return data;
46
+ task(params: LemurTaskParameters): Promise<LemurTaskResponse> {
47
+ return this.fetchJson<LemurTaskResponse>("/lemur/v3/generate/task", {
48
+ method: "POST",
49
+ body: JSON.stringify(params),
50
+ });
49
51
  }
50
52
 
51
53
  /**
52
54
  * Delete the data for a previously submitted LeMUR request.
53
55
  * @param id ID of the LeMUR request
54
56
  */
55
- async purgeRequestData(id: string): Promise<PurgeLemurRequestDataResponse> {
56
- const { data } = await this.client.delete<PurgeLemurRequestDataResponse>(
57
- `/lemur/v3/${id}`
58
- );
59
- return data;
57
+ purgeRequestData(id: string): Promise<PurgeLemurRequestDataResponse> {
58
+ return this.fetchJson<PurgeLemurRequestDataResponse>(`/lemur/v3/${id}`, {
59
+ method: "DELETE",
60
+ });
60
61
  }
61
62
  }
@@ -3,30 +3,35 @@ import {
3
3
  RealtimeTokenParams,
4
4
  CreateRealtimeServiceParams,
5
5
  RealtimeServiceParams,
6
- } from "@/types";
7
- import { AxiosInstance } from "axios";
6
+ RealtimeTemporaryTokenResponse,
7
+ } from "../..";
8
8
  import { RealtimeService } from "./service";
9
+ import { BaseService } from "../base";
9
10
 
10
- export class RealtimeServiceFactory {
11
- constructor(
12
- private client: AxiosInstance,
13
- private params: BaseServiceParams
14
- ) {}
11
+ export class RealtimeServiceFactory extends BaseService {
12
+ private rtFactoryParams: BaseServiceParams;
13
+ constructor(params: BaseServiceParams) {
14
+ super(params);
15
+ this.rtFactoryParams = params;
16
+ }
15
17
 
16
18
  createService(params?: CreateRealtimeServiceParams): RealtimeService {
17
- if (!params) params = { apiKey: this.params.apiKey };
19
+ if (!params) params = { apiKey: this.rtFactoryParams.apiKey };
18
20
  else if (!("token" in params) && !params.apiKey) {
19
- params.apiKey = this.params.apiKey;
21
+ params.apiKey = this.rtFactoryParams.apiKey;
20
22
  }
21
23
 
22
24
  return new RealtimeService(params as RealtimeServiceParams);
23
25
  }
24
26
 
25
27
  async createTemporaryToken(params: RealtimeTokenParams) {
26
- const response = await this.client.post<{ token: string }>(
28
+ const data = await this.fetchJson<RealtimeTemporaryTokenResponse>(
27
29
  "/v2/realtime/token",
28
- params
30
+ {
31
+ method: "POST",
32
+ body: JSON.stringify(params),
33
+ }
29
34
  );
30
- return response.data.token;
35
+ return data.token;
31
36
  }
32
37
  }
@@ -1,2 +1,2 @@
1
- export * from "@/services/realtime/factory";
2
- export * from "@/services/realtime/service";
1
+ export * from "./factory";
2
+ export * from "./service";
@@ -8,13 +8,13 @@ import {
8
8
  PartialTranscript,
9
9
  FinalTranscript,
10
10
  SessionBeginsEventData,
11
- } from "@/types";
11
+ } from "../..";
12
12
  import {
13
13
  RealtimeError,
14
14
  RealtimeErrorMessages,
15
15
  RealtimeErrorType,
16
- } from "@/utils/errors";
17
- import { Writable } from "stream";
16
+ } from "../../utils/errors";
17
+ import Stream from "stream";
18
18
 
19
19
  const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
20
20
 
@@ -32,7 +32,6 @@ export class RealtimeService {
32
32
  this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
33
33
  this.sampleRate = params.sampleRate ?? 16_000;
34
34
  this.wordBoost = params.wordBoost;
35
- this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
36
35
  if ("apiKey" in params) this.apiKey = params.apiKey;
37
36
  if ("token" in params) this.token = params.token;
38
37
 
@@ -162,8 +161,8 @@ export class RealtimeService {
162
161
  this.socket.send(JSON.stringify(payload));
163
162
  }
164
163
 
165
- stream(): Writable {
166
- const stream = new Writable({
164
+ stream(): NodeJS.WritableStream {
165
+ const stream = new Stream.Writable({
167
166
  write: (chunk: Buffer, encoding, next) => {
168
167
  this.sendAudio(chunk);
169
168
  next();
@@ -1,4 +1,4 @@
1
- import { BaseService } from "@/services/base";
1
+ import { BaseService } from "../base";
2
2
  import {
3
3
  ParagraphsResponse,
4
4
  SentencesResponse,
@@ -12,9 +12,10 @@ import {
12
12
  Retrieveable,
13
13
  SubtitleFormat,
14
14
  RedactedAudioResponse,
15
+ TranscriptListParameters,
15
16
  WordSearchResponse,
16
- } from "@/types";
17
- import { AxiosInstance } from "axios";
17
+ BaseServiceParams,
18
+ } from "../..";
18
19
  import { FileService } from "../files";
19
20
 
20
21
  export class TranscriptService
@@ -25,8 +26,8 @@ export class TranscriptService
25
26
  Deletable<Transcript>,
26
27
  Listable<TranscriptList>
27
28
  {
28
- constructor(client: AxiosInstance, private files: FileService) {
29
- super(client);
29
+ constructor(params: BaseServiceParams, private files: FileService) {
30
+ super(params);
30
31
  }
31
32
 
32
33
  /**
@@ -45,13 +46,16 @@ export class TranscriptService
45
46
  params.audio_url = uploadUrl;
46
47
  }
47
48
 
48
- const res = await this.client.post<Transcript>("/v2/transcript", params);
49
+ const data = await this.fetchJson<Transcript>("/v2/transcript", {
50
+ method: "POST",
51
+ body: JSON.stringify(params),
52
+ });
49
53
 
50
54
  if (options?.poll ?? true) {
51
- return await this.poll(res.data.id, options);
55
+ return await this.poll(data.id, options);
52
56
  }
53
57
 
54
- return res.data;
58
+ return data;
55
59
  }
56
60
 
57
61
  private async poll(
@@ -82,21 +86,29 @@ export class TranscriptService
82
86
  * @param id The identifier of the transcript.
83
87
  * @returns A promise that resolves to the transcript.
84
88
  */
85
- async get(id: string): Promise<Transcript> {
86
- const res = await this.client.get<Transcript>(`/v2/transcript/${id}`);
87
- return res.data;
89
+ get(id: string): Promise<Transcript> {
90
+ return this.fetchJson<Transcript>(`/v2/transcript/${id}`);
88
91
  }
89
92
 
90
- // TODO: add options overload to support list querystring parameters
91
93
  /**
92
- * Retrieves a paged list of transcript listings.
93
- * @param nextUrl The URL to retrieve the transcript list from. If not provided, the first page will be retrieved.
94
- * @returns
94
+ * Retrieves a page of transcript listings.
95
+ * @param parameters The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
95
96
  */
96
- async list(nextUrl?: string | null): Promise<TranscriptList> {
97
- const { data } = await this.client.get<TranscriptList>(
98
- nextUrl ?? "/v2/transcript"
99
- );
97
+ async list(
98
+ parameters?: TranscriptListParameters | string
99
+ ): Promise<TranscriptList> {
100
+ let url = "/v2/transcript";
101
+ if (typeof parameters === "string") {
102
+ url = parameters;
103
+ } else if (parameters) {
104
+ url = `${url}?${new URLSearchParams(
105
+ Object.keys(parameters).map((key) => [
106
+ key,
107
+ parameters[key as keyof TranscriptListParameters]?.toString() || "",
108
+ ])
109
+ )}`;
110
+ }
111
+ const data = await this.fetchJson<TranscriptList>(url);
100
112
  for (const transcriptListItem of data.transcripts) {
101
113
  transcriptListItem.created = new Date(transcriptListItem.created);
102
114
  if (transcriptListItem.completed) {
@@ -104,7 +116,7 @@ export class TranscriptService
104
116
  }
105
117
  }
106
118
 
107
- return data as unknown as TranscriptList;
119
+ return data;
108
120
  }
109
121
 
110
122
  /**
@@ -112,28 +124,21 @@ export class TranscriptService
112
124
  * @param id The identifier of the transcript.
113
125
  * @returns A promise that resolves to the transcript.
114
126
  */
115
- async delete(id: string): Promise<Transcript> {
116
- const res = await this.client.delete<Transcript>(`/v2/transcript/${id}`);
117
- return res.data;
127
+ delete(id: string): Promise<Transcript> {
128
+ return this.fetchJson(`/v2/transcript/${id}`, { method: "DELETE" });
118
129
  }
119
130
 
120
131
  /**
121
132
  * Search through the transcript for a specific set of keywords.
122
133
  * You can search for individual words, numbers, or phrases containing up to five words or numbers.
123
134
  * @param id The identifier of the transcript.
124
- * @param id Keywords to search for.
135
+ * @param words Keywords to search for.
125
136
  * @return A promise that resolves to the sentences.
126
137
  */
127
- async wordSearch(id: string, words: string[]): Promise<WordSearchResponse> {
128
- const { data } = await this.client.get<WordSearchResponse>(
129
- `/v2/transcript/${id}/word-search`,
130
- {
131
- params: {
132
- words: JSON.stringify(words),
133
- },
134
- }
138
+ wordSearch(id: string, words: string[]): Promise<WordSearchResponse> {
139
+ return this.fetchJson<WordSearchResponse>(
140
+ `/v2/transcript/${id}/word-search?words=${JSON.stringify(words)}`
135
141
  );
136
- return data;
137
142
  }
138
143
 
139
144
  /**
@@ -141,11 +146,8 @@ export class TranscriptService
141
146
  * @param id The identifier of the transcript.
142
147
  * @return A promise that resolves to the sentences.
143
148
  */
144
- async sentences(id: string): Promise<SentencesResponse> {
145
- const { data } = await this.client.get<SentencesResponse>(
146
- `/v2/transcript/${id}/sentences`
147
- );
148
- return data;
149
+ sentences(id: string): Promise<SentencesResponse> {
150
+ return this.fetchJson<SentencesResponse>(`/v2/transcript/${id}/sentences`);
149
151
  }
150
152
 
151
153
  /**
@@ -153,11 +155,10 @@ export class TranscriptService
153
155
  * @param id The identifier of the transcript.
154
156
  * @return A promise that resolves to the paragraphs.
155
157
  */
156
- async paragraphs(id: string): Promise<ParagraphsResponse> {
157
- const { data } = await this.client.get<ParagraphsResponse>(
158
+ paragraphs(id: string): Promise<ParagraphsResponse> {
159
+ return this.fetchJson<ParagraphsResponse>(
158
160
  `/v2/transcript/${id}/paragraphs`
159
161
  );
160
- return data;
161
162
  }
162
163
 
163
164
  /**
@@ -167,11 +168,8 @@ export class TranscriptService
167
168
  * @return A promise that resolves to the subtitles text.
168
169
  */
169
170
  async subtitles(id: string, format: SubtitleFormat = "srt"): Promise<string> {
170
- const { data } = await this.client.get<string>(
171
- `/v2/transcript/${id}/${format}`
172
- );
173
-
174
- return data;
171
+ const response = await this.fetch(`/v2/transcript/${id}/${format}`);
172
+ return await response.text();
175
173
  }
176
174
 
177
175
  /**
@@ -179,11 +177,10 @@ export class TranscriptService
179
177
  * @param id The identifier of the transcript.
180
178
  * @return A promise that resolves to the subtitles text.
181
179
  */
182
- async redactions(id: string): Promise<RedactedAudioResponse> {
183
- const { data } = await this.client.get<RedactedAudioResponse>(
180
+ redactions(id: string): Promise<RedactedAudioResponse> {
181
+ return this.fetchJson<RedactedAudioResponse>(
184
182
  `/v2/transcript/${id}/redacted-audio`
185
183
  );
186
- return data;
187
184
  }
188
185
  }
189
186
 
@@ -0,0 +1,11 @@
1
+ type FileUploadParameters = string | FileUploadData;
2
+ type FileUploadData =
3
+ | NodeJS.ReadableStream
4
+ | ReadableStream
5
+ | Blob
6
+ | BufferSource
7
+ | ArrayBufferView
8
+ | ArrayBufferLike
9
+ | Uint8Array;
10
+
11
+ export type { FileUploadParameters, FileUploadData };
@@ -1,3 +1,4 @@
1
+ export type * from "./files";
1
2
  export type * from "./transcripts";
2
3
  export type * from "./realtime";
3
4
  export type * from "./services";