assemblyai 4.3.0 → 4.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +161 -86
- package/dist/assemblyai.umd.js +65 -59
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/bun.mjs +60 -54
- package/dist/deno.mjs +60 -54
- package/dist/index.cjs +65 -59
- package/dist/index.mjs +65 -59
- package/dist/node.cjs +60 -54
- package/dist/node.mjs +60 -54
- 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 +3 -3
- 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 +722 -329
- package/dist/types/realtime/index.d.ts +2 -2
- package/dist/types/services/index.d.ts +0 -1
- package/dist/types/transcripts/index.d.ts +14 -5
- package/package.json +2 -1
- package/src/services/base.ts +1 -1
- package/src/services/files/index.ts +2 -2
- package/src/services/index.ts +1 -1
- package/src/services/lemur/index.ts +1 -1
- package/src/services/realtime/service.ts +7 -8
- package/src/services/transcripts/index.ts +47 -54
- package/src/types/asyncapi.generated.ts +62 -40
- package/src/types/openapi.generated.ts +726 -330
- package/src/types/realtime/index.ts +2 -2
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.3.2] - 2024-03-08
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Add `audio_url` property to `TranscribeParams` in addition to the `audio` property. You can use one or the other. `audio_url` only accepts a URL string.
|
|
8
|
+
- Add `TranscriptReadyNotification` type for the transcript webhook body.
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Update codebase to use TSDoc
|
|
13
|
+
- Update README.md with more samples
|
|
14
|
+
|
|
3
15
|
## [4.3.0] - 2024-02-15
|
|
4
16
|
|
|
5
17
|
### Added
|
package/README.md
CHANGED
|
@@ -16,9 +16,13 @@ The AssemblyAI JavaScript SDK provides an easy-to-use interface for interacting
|
|
|
16
16
|
which supports async and real-time transcription, as well as the latest LeMUR models.
|
|
17
17
|
It is written primarily for Node.js in TypeScript with all types exported, but also [compatible with other runtimes](./docs/compat.md).
|
|
18
18
|
|
|
19
|
-
##
|
|
19
|
+
## Documentation
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Visit the [AssemblyAI documentation](https://www.assemblyai.com/docs) for step-by-step instructions and a lot more details about our AI models and API.
|
|
22
|
+
|
|
23
|
+
## Quickstart
|
|
24
|
+
|
|
25
|
+
Install the AssemblyAI SDK using your preferred package manager:
|
|
22
26
|
|
|
23
27
|
```bash
|
|
24
28
|
npm install assemblyai
|
|
@@ -36,11 +40,9 @@ pnpm add assemblyai
|
|
|
36
40
|
bun add assemblyai
|
|
37
41
|
```
|
|
38
42
|
|
|
39
|
-
|
|
43
|
+
Then, import the `assemblyai` module and create an AssemblyAI object with your API key:
|
|
40
44
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
```javascript
|
|
45
|
+
```js
|
|
44
46
|
import { AssemblyAI } from "assemblyai";
|
|
45
47
|
|
|
46
48
|
const client = new AssemblyAI({
|
|
@@ -50,61 +52,94 @@ const client = new AssemblyAI({
|
|
|
50
52
|
|
|
51
53
|
You can now use the `client` object to interact with the AssemblyAI API.
|
|
52
54
|
|
|
53
|
-
##
|
|
55
|
+
## Speech-To-Text
|
|
56
|
+
|
|
57
|
+
### Transcribe audio and video files
|
|
58
|
+
|
|
59
|
+
<details open>
|
|
60
|
+
<summary>Transcribe an audio file with a public URL</summary>
|
|
54
61
|
|
|
55
62
|
When you create a transcript, you can either pass in a URL to an audio file or upload a file directly.
|
|
56
63
|
|
|
57
|
-
```
|
|
64
|
+
```js
|
|
58
65
|
// Transcribe file at remote URL
|
|
59
66
|
let transcript = await client.transcripts.transcribe({
|
|
60
67
|
audio: "https://storage.googleapis.com/aai-web-samples/espn-bears.m4a",
|
|
61
68
|
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
> **Note**
|
|
72
|
+
> You can also pass a local file path, a stream, or a buffer as the `audio` property.
|
|
73
|
+
|
|
74
|
+
`transcribe` queues a transcription job and polls it until the `status` is `completed` or `error`.
|
|
75
|
+
|
|
76
|
+
If you don't want to wait until the transcript is ready, you can use `submit`:
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
let transcript = await client.transcripts.submit({
|
|
80
|
+
audio: "https://storage.googleapis.com/aai-web-samples/espn-bears.m4a",
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
</details>
|
|
85
|
+
|
|
86
|
+
<details>
|
|
87
|
+
<summary>Transcribe a local audio file</summary>
|
|
62
88
|
|
|
89
|
+
When you create a transcript, you can either pass in a URL to an audio file or upload a file directly.
|
|
90
|
+
|
|
91
|
+
```js
|
|
63
92
|
// Upload a file via local path and transcribe
|
|
64
93
|
let transcript = await client.transcripts.transcribe({
|
|
65
94
|
audio: "./news.mp4",
|
|
66
95
|
});
|
|
67
96
|
```
|
|
68
97
|
|
|
69
|
-
> **Note
|
|
70
|
-
> You can also pass
|
|
98
|
+
> **Note:**
|
|
99
|
+
> You can also pass a file URL, a stream, or a buffer as the `audio` property.
|
|
71
100
|
|
|
72
101
|
`transcribe` queues a transcription job and polls it until the `status` is `completed` or `error`.
|
|
73
|
-
You can configure the polling interval and polling timeout using these options:
|
|
74
|
-
|
|
75
|
-
```javascript
|
|
76
|
-
let transcript = await client.transcripts.transcribe(
|
|
77
|
-
{
|
|
78
|
-
audio: "https://storage.googleapis.com/aai-web-samples/espn-bears.m4a",
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
// How frequently the transcript is polled in ms. Defaults to 3000.
|
|
82
|
-
pollingInterval: 1000,
|
|
83
|
-
// How long to wait in ms until the "Polling timeout" error is thrown. Defaults to infinite (-1).
|
|
84
|
-
pollingTimeout: 5000,
|
|
85
|
-
}
|
|
86
|
-
);
|
|
87
|
-
```
|
|
88
102
|
|
|
89
103
|
If you don't want to wait until the transcript is ready, you can use `submit`:
|
|
90
104
|
|
|
91
|
-
```
|
|
105
|
+
```js
|
|
92
106
|
let transcript = await client.transcripts.submit({
|
|
107
|
+
audio: "./news.mp4",
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
</details>
|
|
112
|
+
|
|
113
|
+
<details>
|
|
114
|
+
<summary>Enable additional AI models</summary>
|
|
115
|
+
|
|
116
|
+
You can extract even more insights from the audio by enabling any of our [AI models](https://www.assemblyai.com/docs/audio-intelligence) using _transcription options_.
|
|
117
|
+
For example, here's how to enable [Speaker diarization](https://www.assemblyai.com/docs/speech-to-text/speaker-diarization) model to detect who said what.
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
let transcript = await client.transcripts.transcribe({
|
|
93
121
|
audio: "https://storage.googleapis.com/aai-web-samples/espn-bears.m4a",
|
|
122
|
+
speaker_labels: true,
|
|
94
123
|
});
|
|
124
|
+
for (let utterance of transcript.utterances) {
|
|
125
|
+
console.log(`Speaker ${utterance.speaker}: ${utterance.text}`);
|
|
126
|
+
}
|
|
95
127
|
```
|
|
96
128
|
|
|
97
|
-
|
|
129
|
+
</details>
|
|
130
|
+
|
|
131
|
+
<details>
|
|
132
|
+
<summary>Get a transcript</summary>
|
|
98
133
|
|
|
99
134
|
This will return the transcript object in its current state. If the transcript is still processing, the `status` field will be `queued` or `processing`. Once the transcript is complete, the `status` field will be `completed`.
|
|
100
135
|
|
|
101
|
-
```
|
|
136
|
+
```js
|
|
102
137
|
const transcript = await client.transcripts.get(transcript.id);
|
|
103
138
|
```
|
|
104
139
|
|
|
105
|
-
If you created a transcript using
|
|
140
|
+
If you created a transcript using `.submit()`, you can still poll until the transcript `status` is `completed` or `error` using `.waitUntilReady()`:
|
|
106
141
|
|
|
107
|
-
```
|
|
142
|
+
```js
|
|
108
143
|
const transcript = await client.transcripts.waitUntilReady(transcript.id, {
|
|
109
144
|
// How frequently the transcript is polled in ms. Defaults to 3000.
|
|
110
145
|
pollingInterval: 1000,
|
|
@@ -113,11 +148,36 @@ const transcript = await client.transcripts.waitUntilReady(transcript.id, {
|
|
|
113
148
|
});
|
|
114
149
|
```
|
|
115
150
|
|
|
116
|
-
|
|
151
|
+
</details>
|
|
152
|
+
<details>
|
|
153
|
+
<summary>Get sentences and paragraphs</summary>
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
const sentences = await client.transcripts.sentences(transcript.id);
|
|
157
|
+
const paragraphs = await client.transcripts.paragraphs(transcript.id);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
</details>
|
|
161
|
+
|
|
162
|
+
<details>
|
|
163
|
+
<summary>Get subtitles</summary>
|
|
164
|
+
|
|
165
|
+
```js
|
|
166
|
+
const charsPerCaption = 32;
|
|
167
|
+
let srt = await client.transcripts.subtitles(transcript.id, "srt");
|
|
168
|
+
srt = await client.transcripts.subtitles(transcript.id, "srt", charsPerCaption);
|
|
169
|
+
|
|
170
|
+
let vtt = await client.transcripts.subtitles(transcript.id, "vtt");
|
|
171
|
+
vtt = await client.transcripts.subtitles(transcript.id, "vtt", charsPerCaption);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
</details>
|
|
175
|
+
<details>
|
|
176
|
+
<summary>List transcripts</summary>
|
|
117
177
|
|
|
118
178
|
This will return a page of transcripts you created.
|
|
119
179
|
|
|
120
|
-
```
|
|
180
|
+
```js
|
|
121
181
|
const page = await client.transcripts.list();
|
|
122
182
|
```
|
|
123
183
|
|
|
@@ -131,60 +191,18 @@ do {
|
|
|
131
191
|
} while (nextPageUrl !== null);
|
|
132
192
|
```
|
|
133
193
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
```javascript
|
|
137
|
-
const res = await client.transcripts.delete(transcript.id);
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
## Use LeMUR
|
|
141
|
-
|
|
142
|
-
Call [LeMUR endpoints](https://www.assemblyai.com/docs/API%20reference/lemur) to summarize, ask questions, generate action items, or run a custom task.
|
|
194
|
+
</details>
|
|
143
195
|
|
|
144
|
-
|
|
196
|
+
<details>
|
|
197
|
+
<summary>Delete a transcript</summary>
|
|
145
198
|
|
|
146
|
-
```
|
|
147
|
-
const
|
|
148
|
-
transcript_ids: ["0d295578-8c75-421a-885a-2c487f188927"],
|
|
149
|
-
answer_format: "one sentence",
|
|
150
|
-
context: {
|
|
151
|
-
speakers: ["Alex", "Bob"],
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
Question & Answer:
|
|
157
|
-
|
|
158
|
-
```javascript
|
|
159
|
-
const { response } = await client.lemur.questionAnswer({
|
|
160
|
-
transcript_ids: ["0d295578-8c75-421a-885a-2c487f188927"],
|
|
161
|
-
questions: [
|
|
162
|
-
{
|
|
163
|
-
question: "What are they discussing?",
|
|
164
|
-
answer_format: "text",
|
|
165
|
-
},
|
|
166
|
-
],
|
|
167
|
-
});
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
Action Items:
|
|
171
|
-
|
|
172
|
-
```javascript
|
|
173
|
-
const { response } = await client.lemur.actionItems({
|
|
174
|
-
transcript_ids: ["0d295578-8c75-421a-885a-2c487f188927"],
|
|
175
|
-
});
|
|
199
|
+
```js
|
|
200
|
+
const res = await client.transcripts.delete(transcript.id);
|
|
176
201
|
```
|
|
177
202
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
```javascript
|
|
181
|
-
const { response } = await client.lemur.task({
|
|
182
|
-
transcript_ids: ["0d295578-8c75-421a-885a-2c487f188927"],
|
|
183
|
-
prompt: "Write a haiku about this conversation.",
|
|
184
|
-
});
|
|
185
|
-
```
|
|
203
|
+
</details>
|
|
186
204
|
|
|
187
|
-
|
|
205
|
+
### Transcribe in real-time
|
|
188
206
|
|
|
189
207
|
Create the real-time transcriber.
|
|
190
208
|
|
|
@@ -255,11 +273,68 @@ Close the connection when you're finished.
|
|
|
255
273
|
await rt.close();
|
|
256
274
|
```
|
|
257
275
|
|
|
258
|
-
|
|
276
|
+
## Apply LLMs to your audio with LeMUR
|
|
259
277
|
|
|
260
|
-
|
|
278
|
+
Call [LeMUR endpoints](https://www.assemblyai.com/docs/api-reference/lemur) to apply LLMs to your transcript.
|
|
261
279
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
280
|
+
<details open>
|
|
281
|
+
<summary>Prompt your audio with LeMUR</summary>
|
|
282
|
+
|
|
283
|
+
```js
|
|
284
|
+
const { response } = await client.lemur.task({
|
|
285
|
+
transcript_ids: ["0d295578-8c75-421a-885a-2c487f188927"],
|
|
286
|
+
prompt: "Write a haiku about this conversation.",
|
|
287
|
+
});
|
|
265
288
|
```
|
|
289
|
+
|
|
290
|
+
</details>
|
|
291
|
+
|
|
292
|
+
<details>
|
|
293
|
+
<summary>Summarize with LeMUR</summary>
|
|
294
|
+
|
|
295
|
+
```js
|
|
296
|
+
const { response } = await client.lemur.summary({
|
|
297
|
+
transcript_ids: ["0d295578-8c75-421a-885a-2c487f188927"],
|
|
298
|
+
answer_format: "one sentence",
|
|
299
|
+
context: {
|
|
300
|
+
speakers: ["Alex", "Bob"],
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
</details>
|
|
306
|
+
|
|
307
|
+
<details>
|
|
308
|
+
<summary>Ask questions</summary>
|
|
309
|
+
|
|
310
|
+
```js
|
|
311
|
+
const { response } = await client.lemur.questionAnswer({
|
|
312
|
+
transcript_ids: ["0d295578-8c75-421a-885a-2c487f188927"],
|
|
313
|
+
questions: [
|
|
314
|
+
{
|
|
315
|
+
question: "What are they discussing?",
|
|
316
|
+
answer_format: "text",
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
});
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
</details>
|
|
323
|
+
<details>
|
|
324
|
+
<summary>Generate action items</summary>
|
|
325
|
+
|
|
326
|
+
```js
|
|
327
|
+
const { response } = await client.lemur.actionItems({
|
|
328
|
+
transcript_ids: ["0d295578-8c75-421a-885a-2c487f188927"],
|
|
329
|
+
});
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
</details>
|
|
333
|
+
<details>
|
|
334
|
+
<summary>Delete LeMUR request</summary>
|
|
335
|
+
|
|
336
|
+
```js
|
|
337
|
+
const response = await client.lemur.purgeRequestData(lemurResponse.request_id);
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
</details>
|
package/dist/assemblyai.umd.js
CHANGED
|
@@ -54,14 +54,14 @@
|
|
|
54
54
|
class BaseService {
|
|
55
55
|
/**
|
|
56
56
|
* Create a new service.
|
|
57
|
-
* @param params The parameters to use for the service.
|
|
57
|
+
* @param params - The parameters to use for the service.
|
|
58
58
|
*/
|
|
59
59
|
constructor(params) {
|
|
60
60
|
this.params = params;
|
|
61
61
|
}
|
|
62
62
|
fetch(input, init) {
|
|
63
|
-
var _a;
|
|
64
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
var _a;
|
|
65
65
|
init = init !== null && init !== void 0 ? init : {};
|
|
66
66
|
init.headers = (_a = init.headers) !== null && _a !== void 0 ? _a : {};
|
|
67
67
|
init.headers = Object.assign({ Authorization: this.params.apiKey, "Content-Type": "application/json" }, init.headers);
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
124
124
|
* Delete the data for a previously submitted LeMUR request.
|
|
125
|
-
* @param id ID of the LeMUR request
|
|
125
|
+
* @param id - ID of the LeMUR request
|
|
126
126
|
*/
|
|
127
127
|
purgeRequestData(id) {
|
|
128
128
|
return this.fetchJson(`/lemur/v3/${id}`, {
|
|
@@ -205,8 +205,7 @@
|
|
|
205
205
|
this.sampleRate = (_b = params.sampleRate) !== null && _b !== void 0 ? _b : 16000;
|
|
206
206
|
this.wordBoost = params.wordBoost;
|
|
207
207
|
this.encoding = params.encoding;
|
|
208
|
-
this.
|
|
209
|
-
params.end_utterance_silence_threshold;
|
|
208
|
+
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
210
209
|
if ("token" in params && params.token)
|
|
211
210
|
this.token = params.token;
|
|
212
211
|
if ("apiKey" in params && params.apiKey)
|
|
@@ -254,11 +253,11 @@
|
|
|
254
253
|
}
|
|
255
254
|
this.socket.binaryType = "arraybuffer";
|
|
256
255
|
this.socket.onopen = () => {
|
|
257
|
-
if (this.
|
|
258
|
-
this.
|
|
256
|
+
if (this.endUtteranceSilenceThreshold === undefined ||
|
|
257
|
+
this.endUtteranceSilenceThreshold === null) {
|
|
259
258
|
return;
|
|
260
259
|
}
|
|
261
|
-
this.configureEndUtteranceSilenceThreshold(this.
|
|
260
|
+
this.configureEndUtteranceSilenceThreshold(this.endUtteranceSilenceThreshold);
|
|
262
261
|
};
|
|
263
262
|
this.socket.onclose = ({ code, reason }) => {
|
|
264
263
|
var _a, _b;
|
|
@@ -333,8 +332,8 @@
|
|
|
333
332
|
}
|
|
334
333
|
/**
|
|
335
334
|
* Configure the threshold for how long to wait before ending an utterance. Default is 700ms.
|
|
336
|
-
* @param threshold The duration of the end utterance silence threshold in milliseconds
|
|
337
|
-
*
|
|
335
|
+
* @param threshold - The duration of the end utterance silence threshold in milliseconds.
|
|
336
|
+
* This value must be an integer between 0 and 20_000.
|
|
338
337
|
*/
|
|
339
338
|
configureEndUtteranceSilenceThreshold(threshold) {
|
|
340
339
|
this.send(`{"end_utterance_silence_threshold":${threshold}}`);
|
|
@@ -345,8 +344,8 @@
|
|
|
345
344
|
}
|
|
346
345
|
this.socket.send(data);
|
|
347
346
|
}
|
|
348
|
-
close(
|
|
349
|
-
return __awaiter(this,
|
|
347
|
+
close() {
|
|
348
|
+
return __awaiter(this, arguments, void 0, function* (waitForSessionTermination = true) {
|
|
350
349
|
if (this.socket) {
|
|
351
350
|
if (this.socket.readyState === WebSocket$1.OPEN) {
|
|
352
351
|
if (waitForSessionTermination) {
|
|
@@ -428,8 +427,8 @@
|
|
|
428
427
|
}
|
|
429
428
|
/**
|
|
430
429
|
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
|
|
431
|
-
* @param params The parameters to transcribe an audio file.
|
|
432
|
-
* @param options The options to transcribe an audio file.
|
|
430
|
+
* @param params - The parameters to transcribe an audio file.
|
|
431
|
+
* @param options - The options to transcribe an audio file.
|
|
433
432
|
* @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
|
|
434
433
|
*/
|
|
435
434
|
transcribe(params, options) {
|
|
@@ -440,45 +439,52 @@
|
|
|
440
439
|
}
|
|
441
440
|
/**
|
|
442
441
|
* Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
|
|
443
|
-
* @param params The parameters to start the transcription of an audio file.
|
|
442
|
+
* @param params - The parameters to start the transcription of an audio file.
|
|
444
443
|
* @returns A promise that resolves to the queued transcript.
|
|
445
444
|
*/
|
|
446
445
|
submit(params) {
|
|
447
446
|
return __awaiter(this, void 0, void 0, function* () {
|
|
448
|
-
const { audio } = params, createParams = __rest(params, ["audio"]);
|
|
449
447
|
let audioUrl;
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
448
|
+
let transcriptParams = undefined;
|
|
449
|
+
if ("audio" in params) {
|
|
450
|
+
const { audio } = params, audioTranscriptParams = __rest(params, ["audio"]);
|
|
451
|
+
if (typeof audio === "string") {
|
|
452
|
+
const path = getPath(audio);
|
|
453
|
+
if (path !== null) {
|
|
454
|
+
// audio is local path, upload local file
|
|
455
|
+
audioUrl = yield this.files.upload(path);
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
// audio is not a local path, assume it's a URL
|
|
459
|
+
audioUrl = audio;
|
|
460
|
+
}
|
|
455
461
|
}
|
|
456
462
|
else {
|
|
457
|
-
// audio is
|
|
458
|
-
audioUrl = audio;
|
|
463
|
+
// audio is of uploadable type
|
|
464
|
+
audioUrl = yield this.files.upload(audio);
|
|
459
465
|
}
|
|
466
|
+
transcriptParams = Object.assign(Object.assign({}, audioTranscriptParams), { audio_url: audioUrl });
|
|
460
467
|
}
|
|
461
468
|
else {
|
|
462
|
-
|
|
463
|
-
audioUrl = yield this.files.upload(audio);
|
|
469
|
+
transcriptParams = params;
|
|
464
470
|
}
|
|
465
471
|
const data = yield this.fetchJson("/v2/transcript", {
|
|
466
472
|
method: "POST",
|
|
467
|
-
body: JSON.stringify(
|
|
473
|
+
body: JSON.stringify(transcriptParams),
|
|
468
474
|
});
|
|
469
475
|
return data;
|
|
470
476
|
});
|
|
471
477
|
}
|
|
472
478
|
/**
|
|
473
479
|
* Create a transcript.
|
|
474
|
-
* @param params The parameters to create a transcript.
|
|
475
|
-
* @param options The options used for creating the new transcript.
|
|
480
|
+
* @param params - The parameters to create a transcript.
|
|
481
|
+
* @param options - The options used for creating the new transcript.
|
|
476
482
|
* @returns A promise that resolves to the transcript.
|
|
477
483
|
* @deprecated Use `transcribe` instead to transcribe a audio file that includes polling, or `submit` to transcribe a audio file without polling.
|
|
478
484
|
*/
|
|
479
485
|
create(params, options) {
|
|
480
|
-
var _a;
|
|
481
486
|
return __awaiter(this, void 0, void 0, function* () {
|
|
487
|
+
var _a;
|
|
482
488
|
const path = getPath(params.audio_url);
|
|
483
489
|
if (path !== null) {
|
|
484
490
|
const uploadUrl = yield this.files.upload(path);
|
|
@@ -496,13 +502,13 @@
|
|
|
496
502
|
}
|
|
497
503
|
/**
|
|
498
504
|
* Wait until the transcript ready, either the status is "completed" or "error".
|
|
499
|
-
* @param transcriptId The ID of the transcript.
|
|
500
|
-
* @param options The options to wait until the transcript is ready.
|
|
505
|
+
* @param transcriptId - The ID of the transcript.
|
|
506
|
+
* @param options - The options to wait until the transcript is ready.
|
|
501
507
|
* @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
|
|
502
508
|
*/
|
|
503
509
|
waitUntilReady(transcriptId, options) {
|
|
504
|
-
var _a, _b;
|
|
505
510
|
return __awaiter(this, void 0, void 0, function* () {
|
|
511
|
+
var _a, _b;
|
|
506
512
|
const pollingInterval = (_a = options === null || options === void 0 ? void 0 : options.pollingInterval) !== null && _a !== void 0 ? _a : 3000;
|
|
507
513
|
const pollingTimeout = (_b = options === null || options === void 0 ? void 0 : options.pollingTimeout) !== null && _b !== void 0 ? _b : -1;
|
|
508
514
|
const startTime = Date.now();
|
|
@@ -524,7 +530,7 @@
|
|
|
524
530
|
}
|
|
525
531
|
/**
|
|
526
532
|
* Retrieve a transcript.
|
|
527
|
-
* @param id The identifier of the transcript.
|
|
533
|
+
* @param id - The identifier of the transcript.
|
|
528
534
|
* @returns A promise that resolves to the transcript.
|
|
529
535
|
*/
|
|
530
536
|
get(id) {
|
|
@@ -532,20 +538,20 @@
|
|
|
532
538
|
}
|
|
533
539
|
/**
|
|
534
540
|
* Retrieves a page of transcript listings.
|
|
535
|
-
* @param
|
|
541
|
+
* @param params - The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
|
|
536
542
|
*/
|
|
537
|
-
list(
|
|
543
|
+
list(params) {
|
|
538
544
|
return __awaiter(this, void 0, void 0, function* () {
|
|
539
545
|
let url = "/v2/transcript";
|
|
540
|
-
if (typeof
|
|
541
|
-
url =
|
|
546
|
+
if (typeof params === "string") {
|
|
547
|
+
url = params;
|
|
542
548
|
}
|
|
543
|
-
else if (
|
|
544
|
-
url = `${url}?${new URLSearchParams(Object.keys(
|
|
549
|
+
else if (params) {
|
|
550
|
+
url = `${url}?${new URLSearchParams(Object.keys(params).map((key) => {
|
|
545
551
|
var _a;
|
|
546
552
|
return [
|
|
547
553
|
key,
|
|
548
|
-
((_a =
|
|
554
|
+
((_a = params[key]) === null || _a === void 0 ? void 0 : _a.toString()) || "",
|
|
549
555
|
];
|
|
550
556
|
}))}`;
|
|
551
557
|
}
|
|
@@ -561,7 +567,7 @@
|
|
|
561
567
|
}
|
|
562
568
|
/**
|
|
563
569
|
* Delete a transcript
|
|
564
|
-
* @param id The identifier of the transcript.
|
|
570
|
+
* @param id - The identifier of the transcript.
|
|
565
571
|
* @returns A promise that resolves to the transcript.
|
|
566
572
|
*/
|
|
567
573
|
delete(id) {
|
|
@@ -570,9 +576,9 @@
|
|
|
570
576
|
/**
|
|
571
577
|
* Search through the transcript for a specific set of keywords.
|
|
572
578
|
* You can search for individual words, numbers, or phrases containing up to five words or numbers.
|
|
573
|
-
* @param id The identifier of the transcript.
|
|
574
|
-
* @param words Keywords to search for.
|
|
575
|
-
* @
|
|
579
|
+
* @param id - The identifier of the transcript.
|
|
580
|
+
* @param words - Keywords to search for.
|
|
581
|
+
* @returns A promise that resolves to the sentences.
|
|
576
582
|
*/
|
|
577
583
|
wordSearch(id, words) {
|
|
578
584
|
const params = new URLSearchParams({ words: words.join(",") });
|
|
@@ -580,29 +586,29 @@
|
|
|
580
586
|
}
|
|
581
587
|
/**
|
|
582
588
|
* Retrieve all sentences of a transcript.
|
|
583
|
-
* @param id The identifier of the transcript.
|
|
584
|
-
* @
|
|
589
|
+
* @param id - The identifier of the transcript.
|
|
590
|
+
* @returns A promise that resolves to the sentences.
|
|
585
591
|
*/
|
|
586
592
|
sentences(id) {
|
|
587
593
|
return this.fetchJson(`/v2/transcript/${id}/sentences`);
|
|
588
594
|
}
|
|
589
595
|
/**
|
|
590
596
|
* Retrieve all paragraphs of a transcript.
|
|
591
|
-
* @param id The identifier of the transcript.
|
|
592
|
-
* @
|
|
597
|
+
* @param id - The identifier of the transcript.
|
|
598
|
+
* @returns A promise that resolves to the paragraphs.
|
|
593
599
|
*/
|
|
594
600
|
paragraphs(id) {
|
|
595
601
|
return this.fetchJson(`/v2/transcript/${id}/paragraphs`);
|
|
596
602
|
}
|
|
597
603
|
/**
|
|
598
604
|
* Retrieve subtitles of a transcript.
|
|
599
|
-
* @param id The identifier of the transcript.
|
|
600
|
-
* @param format The format of the subtitles.
|
|
601
|
-
* @param chars_per_caption The maximum number of characters per caption.
|
|
602
|
-
* @
|
|
605
|
+
* @param id - The identifier of the transcript.
|
|
606
|
+
* @param format - The format of the subtitles.
|
|
607
|
+
* @param chars_per_caption - The maximum number of characters per caption.
|
|
608
|
+
* @returns A promise that resolves to the subtitles text.
|
|
603
609
|
*/
|
|
604
|
-
subtitles(
|
|
605
|
-
return __awaiter(this,
|
|
610
|
+
subtitles(id_1) {
|
|
611
|
+
return __awaiter(this, arguments, void 0, function* (id, format = "srt", chars_per_caption) {
|
|
606
612
|
let url = `/v2/transcript/${id}/${format}`;
|
|
607
613
|
if (chars_per_caption) {
|
|
608
614
|
const params = new URLSearchParams();
|
|
@@ -615,8 +621,8 @@
|
|
|
615
621
|
}
|
|
616
622
|
/**
|
|
617
623
|
* Retrieve redactions of a transcript.
|
|
618
|
-
* @param id The identifier of the transcript.
|
|
619
|
-
* @
|
|
624
|
+
* @param id - The identifier of the transcript.
|
|
625
|
+
* @returns A promise that resolves to the subtitles text.
|
|
620
626
|
*/
|
|
621
627
|
redactions(id) {
|
|
622
628
|
return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
|
|
@@ -634,8 +640,8 @@
|
|
|
634
640
|
class FileService extends BaseService {
|
|
635
641
|
/**
|
|
636
642
|
* Upload a local file to AssemblyAI.
|
|
637
|
-
* @param input The local file path to upload, or a stream or buffer of the file to upload.
|
|
638
|
-
* @
|
|
643
|
+
* @param input - The local file path to upload, or a stream or buffer of the file to upload.
|
|
644
|
+
* @returns A promise that resolves to the uploaded file URL.
|
|
639
645
|
*/
|
|
640
646
|
upload(input) {
|
|
641
647
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -661,7 +667,7 @@
|
|
|
661
667
|
class AssemblyAI {
|
|
662
668
|
/**
|
|
663
669
|
* Create a new AssemblyAI client.
|
|
664
|
-
* @param params The parameters for the service, including the API key and base URL, if any.
|
|
670
|
+
* @param params - The parameters for the service, including the API key and base URL, if any.
|
|
665
671
|
*/
|
|
666
672
|
constructor(params) {
|
|
667
673
|
params.baseUrl = params.baseUrl || defaultBaseUrl;
|