assemblyai 4.3.1 → 4.3.3
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/CHANGELOG.md +27 -0
- package/README.md +165 -89
- package/dist/assemblyai.umd.js +62 -56
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/bun.mjs +57 -51
- package/dist/deno.mjs +57 -51
- package/dist/index.cjs +62 -56
- package/dist/index.mjs +62 -56
- package/dist/node.cjs +57 -51
- package/dist/node.mjs +57 -51
- package/dist/services/base.d.ts +1 -1
- package/dist/services/files/index.d.ts +2 -2
- package/dist/services/index.d.ts +1 -1
- package/dist/services/lemur/index.d.ts +1 -1
- package/dist/services/realtime/service.d.ts +2 -2
- package/dist/services/transcripts/index.d.ts +26 -26
- package/dist/types/asyncapi.generated.d.ts +60 -39
- package/dist/types/openapi.generated.d.ts +740 -347
- package/dist/types/services/index.d.ts +0 -1
- package/dist/types/transcripts/index.d.ts +14 -5
- package/package.json +26 -25
- package/src/polyfills/fs/index.ts +2 -2
- package/src/polyfills/fs/node.ts +1 -1
- package/src/polyfills/streams/index.ts +2 -2
- package/src/services/base.ts +3 -3
- package/src/services/files/index.ts +2 -2
- package/src/services/index.ts +1 -1
- package/src/services/lemur/index.ts +5 -5
- package/src/services/realtime/factory.ts +1 -1
- package/src/services/realtime/service.ts +7 -8
- package/src/services/transcripts/index.ts +59 -63
- package/src/types/asyncapi.generated.ts +64 -42
- package/src/types/openapi.generated.ts +748 -352
- package/src/types/services/index.ts +0 -1
- package/src/types/transcripts/index.ts +17 -7
- package/dist/types/services/abstractions.d.ts +0 -52
- package/src/types/services/abstractions.ts +0 -56
|
@@ -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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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.
|
|
3
|
+
"version": "4.3.3",
|
|
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"
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"build": "pnpm clean && pnpm rollup -c",
|
|
70
|
-
"clean": "rimraf dist/*",
|
|
71
|
-
"lint": "eslint -c .eslintrc.json '{src,tests}/**/*.{js,ts}' && publint",
|
|
70
|
+
"clean": "rimraf dist/* && rimraf temp/* && rimraf temp-docs/*",
|
|
71
|
+
"lint": "eslint -c .eslintrc.json '{src,tests}/**/*.{js,ts}' && publint && tsc --noEmit -p tsconfig.json",
|
|
72
72
|
"test": "jest --config jest.config.js",
|
|
73
73
|
"format": "prettier '**/*' --write",
|
|
74
74
|
"generate-types": "tsx ./scripts/generate-types.ts && pnpm format",
|
|
@@ -98,35 +98,36 @@
|
|
|
98
98
|
"docs"
|
|
99
99
|
],
|
|
100
100
|
"devDependencies": {
|
|
101
|
-
"@babel/preset-env": "^7.
|
|
101
|
+
"@babel/preset-env": "^7.24.0",
|
|
102
102
|
"@babel/preset-typescript": "^7.23.3",
|
|
103
103
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
104
104
|
"@rollup/plugin-terser": "^0.4.4",
|
|
105
|
-
"@rollup/plugin-typescript": "^11.1.
|
|
106
|
-
"@types/jest": "^29.5.
|
|
107
|
-
"@types/node": "^
|
|
108
|
-
"@types/websocket": "^1.0.
|
|
109
|
-
"@types/ws": "^8.5.
|
|
110
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
111
|
-
"dotenv": "^16.
|
|
112
|
-
"eslint": "^8.
|
|
113
|
-
"
|
|
114
|
-
"jest
|
|
105
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
106
|
+
"@types/jest": "^29.5.12",
|
|
107
|
+
"@types/node": "^18.11.9",
|
|
108
|
+
"@types/websocket": "^1.0.10",
|
|
109
|
+
"@types/ws": "^8.5.10",
|
|
110
|
+
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
111
|
+
"dotenv": "^16.4.5",
|
|
112
|
+
"eslint": "^8.57.0",
|
|
113
|
+
"eslint-plugin-tsdoc": "^0.2.17",
|
|
114
|
+
"jest": "^29.7.0",
|
|
115
|
+
"jest-cli": "^29.7.0",
|
|
115
116
|
"jest-fetch-mock": "^3.0.3",
|
|
116
117
|
"jest-junit": "^16.0.0",
|
|
117
|
-
"jest-websocket-mock": "^2.
|
|
118
|
-
"mock-socket": "^9.
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
"
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
-
"
|
|
125
|
-
"ts-jest": "^29.1.0",
|
|
118
|
+
"jest-websocket-mock": "^2.5.0",
|
|
119
|
+
"mock-socket": "^9.3.1",
|
|
120
|
+
"openapi-typescript": "^6.7.5",
|
|
121
|
+
"prettier": "^3.2.5",
|
|
122
|
+
"publint": "^0.2.7",
|
|
123
|
+
"rimraf": "^5.0.5",
|
|
124
|
+
"rollup": "^4.13.0",
|
|
125
|
+
"ts-jest": "^29.1.2",
|
|
126
126
|
"tslib": "^2.5.3",
|
|
127
|
-
"typescript": "^5.
|
|
127
|
+
"typescript": "^5.4.2",
|
|
128
|
+
"typedoc": "^0.25.12"
|
|
128
129
|
},
|
|
129
130
|
"dependencies": {
|
|
130
|
-
"ws": "^8.
|
|
131
|
+
"ws": "^8.16.0"
|
|
131
132
|
}
|
|
132
133
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export const readFile = async function (
|
|
2
2
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3
|
-
path: string
|
|
3
|
+
path: string,
|
|
4
4
|
): Promise<ReadableStream<Uint8Array>> {
|
|
5
5
|
throw new Error(
|
|
6
|
-
"Interacting with the file system is not supported in this environment."
|
|
6
|
+
"Interacting with the file system is not supported in this environment.",
|
|
7
7
|
);
|
|
8
8
|
};
|
package/src/polyfills/fs/node.ts
CHANGED
package/src/services/base.ts
CHANGED
|
@@ -7,12 +7,12 @@ 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(
|
|
14
14
|
input: string,
|
|
15
|
-
init?: RequestInit | undefined
|
|
15
|
+
init?: RequestInit | undefined,
|
|
16
16
|
): Promise<Response> {
|
|
17
17
|
init = init ?? {};
|
|
18
18
|
init.headers = init.headers ?? {};
|
|
@@ -45,7 +45,7 @@ export abstract class BaseService {
|
|
|
45
45
|
|
|
46
46
|
protected async fetchJson<T>(
|
|
47
47
|
input: string,
|
|
48
|
-
init?: RequestInit | undefined
|
|
48
|
+
init?: RequestInit | undefined,
|
|
49
49
|
): Promise<T> {
|
|
50
50
|
const response = await this.fetch(input, init);
|
|
51
51
|
return response.json() as Promise<T>;
|
|
@@ -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
|
-
* @
|
|
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;
|
package/src/services/index.ts
CHANGED
|
@@ -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;
|
|
@@ -20,26 +20,26 @@ export class LemurService extends BaseService {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
questionAnswer(
|
|
23
|
-
params: LemurQuestionAnswerParams
|
|
23
|
+
params: LemurQuestionAnswerParams,
|
|
24
24
|
): Promise<LemurQuestionAnswerResponse> {
|
|
25
25
|
return this.fetchJson<LemurQuestionAnswerResponse>(
|
|
26
26
|
"/lemur/v3/generate/question-answer",
|
|
27
27
|
{
|
|
28
28
|
method: "POST",
|
|
29
29
|
body: JSON.stringify(params),
|
|
30
|
-
}
|
|
30
|
+
},
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
actionItems(
|
|
35
|
-
params: LemurActionItemsParams
|
|
35
|
+
params: LemurActionItemsParams,
|
|
36
36
|
): Promise<LemurActionItemsResponse> {
|
|
37
37
|
return this.fetchJson<LemurActionItemsResponse>(
|
|
38
38
|
"/lemur/v3/generate/action-items",
|
|
39
39
|
{
|
|
40
40
|
method: "POST",
|
|
41
41
|
body: JSON.stringify(params),
|
|
42
|
-
}
|
|
42
|
+
},
|
|
43
43
|
);
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -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}`, {
|
|
@@ -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.endUtteranceSilenceThreshold =
|
|
62
|
-
params.endUtteranceSilenceThreshold;
|
|
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
|
|
|
@@ -94,15 +93,15 @@ export class RealtimeTranscriber {
|
|
|
94
93
|
on(event: "open", listener: (event: SessionBeginsEventData) => void): void;
|
|
95
94
|
on(
|
|
96
95
|
event: "transcript",
|
|
97
|
-
listener: (transcript: RealtimeTranscript) => void
|
|
96
|
+
listener: (transcript: RealtimeTranscript) => void,
|
|
98
97
|
): void;
|
|
99
98
|
on(
|
|
100
99
|
event: "transcript.partial",
|
|
101
|
-
listener: (transcript: PartialTranscript) => void
|
|
100
|
+
listener: (transcript: PartialTranscript) => void,
|
|
102
101
|
): void;
|
|
103
102
|
on(
|
|
104
103
|
event: "transcript.final",
|
|
105
|
-
listener: (transcript: FinalTranscript) => void
|
|
104
|
+
listener: (transcript: FinalTranscript) => void,
|
|
106
105
|
): void;
|
|
107
106
|
on(event: "error", listener: (error: Error) => void): void;
|
|
108
107
|
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
@@ -136,7 +135,7 @@ export class RealtimeTranscriber {
|
|
|
136
135
|
return;
|
|
137
136
|
}
|
|
138
137
|
this.configureEndUtteranceSilenceThreshold(
|
|
139
|
-
this.endUtteranceSilenceThreshold
|
|
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
|
-
*
|
|
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,27 +19,23 @@ import {
|
|
|
23
19
|
import { FileService } from "../files";
|
|
24
20
|
import { getPath } from "../../utils/path";
|
|
25
21
|
|
|
26
|
-
export class TranscriptService
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
Deletable<Transcript>,
|
|
32
|
-
Listable<TranscriptList>
|
|
33
|
-
{
|
|
34
|
-
constructor(params: BaseServiceParams, private files: FileService) {
|
|
22
|
+
export class TranscriptService extends BaseService {
|
|
23
|
+
constructor(
|
|
24
|
+
params: BaseServiceParams,
|
|
25
|
+
private files: FileService,
|
|
26
|
+
) {
|
|
35
27
|
super(params);
|
|
36
28
|
}
|
|
37
29
|
|
|
38
30
|
/**
|
|
39
31
|
* 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.
|
|
32
|
+
* @param params - The parameters to transcribe an audio file.
|
|
33
|
+
* @param options - The options to transcribe an audio file.
|
|
42
34
|
* @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
|
|
43
35
|
*/
|
|
44
36
|
async transcribe(
|
|
45
37
|
params: TranscribeParams,
|
|
46
|
-
options?: TranscribeOptions
|
|
38
|
+
options?: TranscribeOptions,
|
|
47
39
|
): Promise<Transcript> {
|
|
48
40
|
const transcript = await this.submit(params);
|
|
49
41
|
return await this.waitUntilReady(transcript.id, options);
|
|
@@ -51,43 +43,49 @@ export class TranscriptService
|
|
|
51
43
|
|
|
52
44
|
/**
|
|
53
45
|
* 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.
|
|
46
|
+
* @param params - The parameters to start the transcription of an audio file.
|
|
55
47
|
* @returns A promise that resolves to the queued transcript.
|
|
56
48
|
*/
|
|
57
49
|
async submit(params: SubmitParams): Promise<Transcript> {
|
|
58
|
-
const { audio, ...createParams } = params;
|
|
59
50
|
let audioUrl;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
let transcriptParams: TranscriptParams | undefined = undefined;
|
|
52
|
+
if ("audio" in params) {
|
|
53
|
+
const { audio, ...audioTranscriptParams } = params;
|
|
54
|
+
if (typeof audio === "string") {
|
|
55
|
+
const path = getPath(audio);
|
|
56
|
+
if (path !== null) {
|
|
57
|
+
// audio is local path, upload local file
|
|
58
|
+
audioUrl = await this.files.upload(path);
|
|
59
|
+
} else {
|
|
60
|
+
// audio is not a local path, assume it's a URL
|
|
61
|
+
audioUrl = audio;
|
|
62
|
+
}
|
|
65
63
|
} else {
|
|
66
|
-
// audio is
|
|
67
|
-
audioUrl = audio;
|
|
64
|
+
// audio is of uploadable type
|
|
65
|
+
audioUrl = await this.files.upload(audio);
|
|
68
66
|
}
|
|
67
|
+
transcriptParams = { ...audioTranscriptParams, audio_url: audioUrl };
|
|
69
68
|
} else {
|
|
70
|
-
|
|
71
|
-
audioUrl = await this.files.upload(audio);
|
|
69
|
+
transcriptParams = params;
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
const data = await this.fetchJson<Transcript>("/v2/transcript", {
|
|
75
73
|
method: "POST",
|
|
76
|
-
body: JSON.stringify(
|
|
74
|
+
body: JSON.stringify(transcriptParams),
|
|
77
75
|
});
|
|
78
76
|
return data;
|
|
79
77
|
}
|
|
80
78
|
|
|
81
79
|
/**
|
|
82
80
|
* Create a transcript.
|
|
83
|
-
* @param params The parameters to create a transcript.
|
|
84
|
-
* @param options The options used for creating the new transcript.
|
|
81
|
+
* @param params - The parameters to create a transcript.
|
|
82
|
+
* @param options - The options used for creating the new transcript.
|
|
85
83
|
* @returns A promise that resolves to the transcript.
|
|
86
84
|
* @deprecated Use `transcribe` instead to transcribe a audio file that includes polling, or `submit` to transcribe a audio file without polling.
|
|
87
85
|
*/
|
|
88
86
|
async create(
|
|
89
87
|
params: TranscriptParams,
|
|
90
|
-
options?: CreateTranscriptOptions
|
|
88
|
+
options?: CreateTranscriptOptions,
|
|
91
89
|
): Promise<Transcript> {
|
|
92
90
|
const path = getPath(params.audio_url);
|
|
93
91
|
if (path !== null) {
|
|
@@ -109,13 +107,13 @@ export class TranscriptService
|
|
|
109
107
|
|
|
110
108
|
/**
|
|
111
109
|
* 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.
|
|
110
|
+
* @param transcriptId - The ID of the transcript.
|
|
111
|
+
* @param options - The options to wait until the transcript is ready.
|
|
114
112
|
* @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
|
|
115
113
|
*/
|
|
116
114
|
async waitUntilReady(
|
|
117
115
|
transcriptId: string,
|
|
118
|
-
options?: PollingOptions
|
|
116
|
+
options?: PollingOptions,
|
|
119
117
|
): Promise<Transcript> {
|
|
120
118
|
const pollingInterval = options?.pollingInterval ?? 3_000;
|
|
121
119
|
const pollingTimeout = options?.pollingTimeout ?? -1;
|
|
@@ -138,7 +136,7 @@ export class TranscriptService
|
|
|
138
136
|
|
|
139
137
|
/**
|
|
140
138
|
* Retrieve a transcript.
|
|
141
|
-
* @param id The identifier of the transcript.
|
|
139
|
+
* @param id - The identifier of the transcript.
|
|
142
140
|
* @returns A promise that resolves to the transcript.
|
|
143
141
|
*/
|
|
144
142
|
get(id: string): Promise<Transcript> {
|
|
@@ -147,20 +145,18 @@ export class TranscriptService
|
|
|
147
145
|
|
|
148
146
|
/**
|
|
149
147
|
* Retrieves a page of transcript listings.
|
|
150
|
-
* @param
|
|
148
|
+
* @param params - The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
|
|
151
149
|
*/
|
|
152
|
-
async list(
|
|
153
|
-
parameters?: ListTranscriptParams | string
|
|
154
|
-
): Promise<TranscriptList> {
|
|
150
|
+
async list(params?: ListTranscriptParams | string): Promise<TranscriptList> {
|
|
155
151
|
let url = "/v2/transcript";
|
|
156
|
-
if (typeof
|
|
157
|
-
url =
|
|
158
|
-
} else if (
|
|
152
|
+
if (typeof params === "string") {
|
|
153
|
+
url = params;
|
|
154
|
+
} else if (params) {
|
|
159
155
|
url = `${url}?${new URLSearchParams(
|
|
160
|
-
Object.keys(
|
|
156
|
+
Object.keys(params).map((key) => [
|
|
161
157
|
key,
|
|
162
|
-
|
|
163
|
-
])
|
|
158
|
+
params[key as keyof ListTranscriptParams]?.toString() || "",
|
|
159
|
+
]),
|
|
164
160
|
)}`;
|
|
165
161
|
}
|
|
166
162
|
const data = await this.fetchJson<TranscriptList>(url);
|
|
@@ -176,7 +172,7 @@ export class TranscriptService
|
|
|
176
172
|
|
|
177
173
|
/**
|
|
178
174
|
* Delete a transcript
|
|
179
|
-
* @param id The identifier of the transcript.
|
|
175
|
+
* @param id - The identifier of the transcript.
|
|
180
176
|
* @returns A promise that resolves to the transcript.
|
|
181
177
|
*/
|
|
182
178
|
delete(id: string): Promise<Transcript> {
|
|
@@ -186,21 +182,21 @@ export class TranscriptService
|
|
|
186
182
|
/**
|
|
187
183
|
* Search through the transcript for a specific set of keywords.
|
|
188
184
|
* 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
|
-
* @
|
|
185
|
+
* @param id - The identifier of the transcript.
|
|
186
|
+
* @param words - Keywords to search for.
|
|
187
|
+
* @returns A promise that resolves to the sentences.
|
|
192
188
|
*/
|
|
193
189
|
wordSearch(id: string, words: string[]): Promise<WordSearchResponse> {
|
|
194
190
|
const params = new URLSearchParams({ words: words.join(",") });
|
|
195
191
|
return this.fetchJson<WordSearchResponse>(
|
|
196
|
-
`/v2/transcript/${id}/word-search?${params.toString()}
|
|
192
|
+
`/v2/transcript/${id}/word-search?${params.toString()}`,
|
|
197
193
|
);
|
|
198
194
|
}
|
|
199
195
|
|
|
200
196
|
/**
|
|
201
197
|
* Retrieve all sentences of a transcript.
|
|
202
|
-
* @param id The identifier of the transcript.
|
|
203
|
-
* @
|
|
198
|
+
* @param id - The identifier of the transcript.
|
|
199
|
+
* @returns A promise that resolves to the sentences.
|
|
204
200
|
*/
|
|
205
201
|
sentences(id: string): Promise<SentencesResponse> {
|
|
206
202
|
return this.fetchJson<SentencesResponse>(`/v2/transcript/${id}/sentences`);
|
|
@@ -208,26 +204,26 @@ export class TranscriptService
|
|
|
208
204
|
|
|
209
205
|
/**
|
|
210
206
|
* Retrieve all paragraphs of a transcript.
|
|
211
|
-
* @param id The identifier of the transcript.
|
|
212
|
-
* @
|
|
207
|
+
* @param id - The identifier of the transcript.
|
|
208
|
+
* @returns A promise that resolves to the paragraphs.
|
|
213
209
|
*/
|
|
214
210
|
paragraphs(id: string): Promise<ParagraphsResponse> {
|
|
215
211
|
return this.fetchJson<ParagraphsResponse>(
|
|
216
|
-
`/v2/transcript/${id}/paragraphs
|
|
212
|
+
`/v2/transcript/${id}/paragraphs`,
|
|
217
213
|
);
|
|
218
214
|
}
|
|
219
215
|
|
|
220
216
|
/**
|
|
221
217
|
* 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
|
-
* @
|
|
218
|
+
* @param id - The identifier of the transcript.
|
|
219
|
+
* @param format - The format of the subtitles.
|
|
220
|
+
* @param chars_per_caption - The maximum number of characters per caption.
|
|
221
|
+
* @returns A promise that resolves to the subtitles text.
|
|
226
222
|
*/
|
|
227
223
|
async subtitles(
|
|
228
224
|
id: string,
|
|
229
225
|
format: SubtitleFormat = "srt",
|
|
230
|
-
chars_per_caption?: number
|
|
226
|
+
chars_per_caption?: number,
|
|
231
227
|
): Promise<string> {
|
|
232
228
|
let url = `/v2/transcript/${id}/${format}`;
|
|
233
229
|
if (chars_per_caption) {
|
|
@@ -241,12 +237,12 @@ export class TranscriptService
|
|
|
241
237
|
|
|
242
238
|
/**
|
|
243
239
|
* Retrieve redactions of a transcript.
|
|
244
|
-
* @param id The identifier of the transcript.
|
|
245
|
-
* @
|
|
240
|
+
* @param id - The identifier of the transcript.
|
|
241
|
+
* @returns A promise that resolves to the subtitles text.
|
|
246
242
|
*/
|
|
247
243
|
redactions(id: string): Promise<RedactedAudioResponse> {
|
|
248
244
|
return this.fetchJson<RedactedAudioResponse>(
|
|
249
|
-
`/v2/transcript/${id}/redacted-audio
|
|
245
|
+
`/v2/transcript/${id}/redacted-audio`,
|
|
250
246
|
);
|
|
251
247
|
}
|
|
252
248
|
}
|