assemblyai 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +119 -102
- package/dist/index.js +120 -103
- package/dist/services/base.d.ts +6 -4
- package/dist/services/files/index.d.ts +2 -2
- package/dist/services/index.d.ts +1 -1
- package/dist/services/lemur/index.d.ts +2 -2
- package/dist/services/realtime/factory.d.ts +5 -6
- package/dist/services/realtime/index.d.ts +2 -2
- package/dist/services/realtime/service.d.ts +2 -3
- package/dist/services/transcripts/index.d.ts +7 -7
- package/dist/types/asyncapi.generated.d.ts +20 -17
- package/dist/types/files/index.d.ts +1 -2
- package/dist/types/index.d.ts +6 -6
- package/dist/types/openapi.generated.d.ts +134 -108
- package/dist/types/services/index.d.ts +1 -1
- package/dist/types/transcripts/index.d.ts +16 -2
- package/package.json +2 -2
- package/src/index.ts +1 -1
- package/src/services/base.ts +44 -3
- package/src/services/files/index.ts +10 -12
- package/src/services/index.ts +10 -8
- package/src/services/lemur/index.ts +28 -27
- package/src/services/realtime/factory.ts +17 -12
- package/src/services/realtime/index.ts +2 -2
- package/src/services/realtime/service.ts +5 -6
- package/src/services/transcripts/index.ts +57 -55
- package/src/types/asyncapi.generated.ts +20 -17
- package/src/types/files/index.ts +2 -1
- package/src/types/index.ts +6 -6
- package/src/types/openapi.generated.ts +136 -108
- package/src/types/services/index.ts +1 -1
- package/src/types/transcripts/index.ts +16 -2
- package/dist/utils/axios.d.ts +0 -3
- package/src/utils/axios.ts +0 -19
package/src/services/base.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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
|
|
10
|
+
* @param params The parameters to use for the service.
|
|
10
11
|
*/
|
|
11
|
-
constructor(
|
|
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,8 +1,8 @@
|
|
|
1
1
|
// import the fs module instead if specific named exports
|
|
2
2
|
// to keep the assemblyai module more compatible. Some fs polyfills don't include `createReadStream`.
|
|
3
3
|
import fs from "fs";
|
|
4
|
-
import { BaseService } from "
|
|
5
|
-
import { UploadedFile, FileUploadParameters, FileUploadData } from "
|
|
4
|
+
import { BaseService } from "../base";
|
|
5
|
+
import { UploadedFile, FileUploadParameters, FileUploadData } from "../..";
|
|
6
6
|
|
|
7
7
|
export class FileService extends BaseService {
|
|
8
8
|
/**
|
|
@@ -15,16 +15,14 @@ export class FileService extends BaseService {
|
|
|
15
15
|
if (typeof input === "string") fileData = fs.createReadStream(input);
|
|
16
16
|
else fileData = input;
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
"
|
|
20
|
-
fileData,
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
);
|
|
27
|
-
|
|
18
|
+
const data = await this.fetchJson<UploadedFile>("/v2/upload", {
|
|
19
|
+
method: "POST",
|
|
20
|
+
body: fileData as BodyInit,
|
|
21
|
+
headers: {
|
|
22
|
+
"Content-Type": "application/octet-stream",
|
|
23
|
+
},
|
|
24
|
+
duplex: "half",
|
|
25
|
+
} as RequestInit);
|
|
28
26
|
return data.upload_url;
|
|
29
27
|
}
|
|
30
28
|
}
|
package/src/services/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
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 ||
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
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 "
|
|
12
|
-
import { BaseService } from "
|
|
11
|
+
} from "../..";
|
|
12
|
+
import { BaseService } from "../base";
|
|
13
13
|
|
|
14
14
|
export class LemurService extends BaseService {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
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
|
-
|
|
22
|
+
questionAnswer(
|
|
24
23
|
params: LemurQuestionAnswerParameters
|
|
25
24
|
): Promise<LemurQuestionAnswerResponse> {
|
|
26
|
-
|
|
25
|
+
return this.fetchJson<LemurQuestionAnswerResponse>(
|
|
27
26
|
"/lemur/v3/generate/question-answer",
|
|
28
|
-
|
|
27
|
+
{
|
|
28
|
+
method: "POST",
|
|
29
|
+
body: JSON.stringify(params),
|
|
30
|
+
}
|
|
29
31
|
);
|
|
30
|
-
return data;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
actionItems(
|
|
34
35
|
params: LemurActionItemsParameters
|
|
35
36
|
): Promise<LemurActionItemsResponse> {
|
|
36
|
-
|
|
37
|
+
return this.fetchJson<LemurActionItemsResponse>(
|
|
37
38
|
"/lemur/v3/generate/action-items",
|
|
38
|
-
|
|
39
|
+
{
|
|
40
|
+
method: "POST",
|
|
41
|
+
body: JSON.stringify(params),
|
|
42
|
+
}
|
|
39
43
|
);
|
|
40
|
-
return data;
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
7
|
-
|
|
6
|
+
RealtimeTemporaryTokenResponse,
|
|
7
|
+
} from "../..";
|
|
8
8
|
import { RealtimeService } from "./service";
|
|
9
|
+
import { BaseService } from "../base";
|
|
9
10
|
|
|
10
|
-
export class RealtimeServiceFactory {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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.
|
|
19
|
+
if (!params) params = { apiKey: this.rtFactoryParams.apiKey };
|
|
18
20
|
else if (!("token" in params) && !params.apiKey) {
|
|
19
|
-
params.apiKey = this.
|
|
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
|
|
28
|
+
const data = await this.fetchJson<RealtimeTemporaryTokenResponse>(
|
|
27
29
|
"/v2/realtime/token",
|
|
28
|
-
|
|
30
|
+
{
|
|
31
|
+
method: "POST",
|
|
32
|
+
body: JSON.stringify(params),
|
|
33
|
+
}
|
|
29
34
|
);
|
|
30
|
-
return
|
|
35
|
+
return data.token;
|
|
31
36
|
}
|
|
32
37
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "
|
|
2
|
-
export * from "
|
|
1
|
+
export * from "./factory";
|
|
2
|
+
export * from "./service";
|
|
@@ -8,13 +8,13 @@ import {
|
|
|
8
8
|
PartialTranscript,
|
|
9
9
|
FinalTranscript,
|
|
10
10
|
SessionBeginsEventData,
|
|
11
|
-
} from "
|
|
11
|
+
} from "../..";
|
|
12
12
|
import {
|
|
13
13
|
RealtimeError,
|
|
14
14
|
RealtimeErrorMessages,
|
|
15
15
|
RealtimeErrorType,
|
|
16
|
-
} from "
|
|
17
|
-
import
|
|
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():
|
|
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 "
|
|
1
|
+
import { BaseService } from "../base";
|
|
2
2
|
import {
|
|
3
3
|
ParagraphsResponse,
|
|
4
4
|
SentencesResponse,
|
|
@@ -14,8 +14,9 @@ import {
|
|
|
14
14
|
RedactedAudioResponse,
|
|
15
15
|
TranscriptListParameters,
|
|
16
16
|
WordSearchResponse,
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
BaseServiceParams,
|
|
18
|
+
PollingOptions,
|
|
19
|
+
} from "../..";
|
|
19
20
|
import { FileService } from "../files";
|
|
20
21
|
|
|
21
22
|
export class TranscriptService
|
|
@@ -26,8 +27,8 @@ export class TranscriptService
|
|
|
26
27
|
Deletable<Transcript>,
|
|
27
28
|
Listable<TranscriptList>
|
|
28
29
|
{
|
|
29
|
-
constructor(
|
|
30
|
-
super(
|
|
30
|
+
constructor(params: BaseServiceParams, private files: FileService) {
|
|
31
|
+
super(params);
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -46,19 +47,24 @@ export class TranscriptService
|
|
|
46
47
|
params.audio_url = uploadUrl;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
const
|
|
50
|
+
const data = await this.fetchJson<Transcript>("/v2/transcript", {
|
|
51
|
+
method: "POST",
|
|
52
|
+
body: JSON.stringify(params),
|
|
53
|
+
});
|
|
50
54
|
|
|
51
55
|
if (options?.poll ?? true) {
|
|
52
|
-
return await this.
|
|
56
|
+
return await this.waitUntilReady(data.id, options);
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
return
|
|
59
|
+
return data;
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
|
|
62
|
+
async waitUntilReady(
|
|
59
63
|
transcriptId: string,
|
|
60
|
-
options?:
|
|
64
|
+
options?: PollingOptions
|
|
61
65
|
): Promise<Transcript> {
|
|
66
|
+
const pollingInterval = options?.pollingInterval ?? 3_000;
|
|
67
|
+
const pollingTimeout = options?.pollingTimeout ?? -1;
|
|
62
68
|
const startTime = Date.now();
|
|
63
69
|
// eslint-disable-next-line no-constant-condition
|
|
64
70
|
while (true) {
|
|
@@ -66,14 +72,12 @@ export class TranscriptService
|
|
|
66
72
|
if (transcript.status === "completed" || transcript.status === "error") {
|
|
67
73
|
return transcript;
|
|
68
74
|
} else if (
|
|
69
|
-
|
|
70
|
-
(
|
|
75
|
+
pollingTimeout > 0 &&
|
|
76
|
+
Date.now() - startTime > pollingTimeout
|
|
71
77
|
) {
|
|
72
|
-
await new Promise((resolve) =>
|
|
73
|
-
setTimeout(resolve, options?.pollingInterval ?? 3_000)
|
|
74
|
-
);
|
|
75
|
-
} else {
|
|
76
78
|
throw new Error("Polling timeout");
|
|
79
|
+
} else {
|
|
80
|
+
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
}
|
|
@@ -83,9 +87,8 @@ export class TranscriptService
|
|
|
83
87
|
* @param id The identifier of the transcript.
|
|
84
88
|
* @returns A promise that resolves to the transcript.
|
|
85
89
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return res.data;
|
|
90
|
+
get(id: string): Promise<Transcript> {
|
|
91
|
+
return this.fetchJson<Transcript>(`/v2/transcript/${id}`);
|
|
89
92
|
}
|
|
90
93
|
|
|
91
94
|
/**
|
|
@@ -96,15 +99,17 @@ export class TranscriptService
|
|
|
96
99
|
parameters?: TranscriptListParameters | string
|
|
97
100
|
): Promise<TranscriptList> {
|
|
98
101
|
let url = "/v2/transcript";
|
|
99
|
-
let query: TranscriptListParameters | undefined;
|
|
100
102
|
if (typeof parameters === "string") {
|
|
101
103
|
url = parameters;
|
|
102
104
|
} else if (parameters) {
|
|
103
|
-
|
|
105
|
+
url = `${url}?${new URLSearchParams(
|
|
106
|
+
Object.keys(parameters).map((key) => [
|
|
107
|
+
key,
|
|
108
|
+
parameters[key as keyof TranscriptListParameters]?.toString() || "",
|
|
109
|
+
])
|
|
110
|
+
)}`;
|
|
104
111
|
}
|
|
105
|
-
const
|
|
106
|
-
params: query,
|
|
107
|
-
});
|
|
112
|
+
const data = await this.fetchJson<TranscriptList>(url);
|
|
108
113
|
for (const transcriptListItem of data.transcripts) {
|
|
109
114
|
transcriptListItem.created = new Date(transcriptListItem.created);
|
|
110
115
|
if (transcriptListItem.completed) {
|
|
@@ -112,7 +117,7 @@ export class TranscriptService
|
|
|
112
117
|
}
|
|
113
118
|
}
|
|
114
119
|
|
|
115
|
-
return data
|
|
120
|
+
return data;
|
|
116
121
|
}
|
|
117
122
|
|
|
118
123
|
/**
|
|
@@ -120,28 +125,22 @@ export class TranscriptService
|
|
|
120
125
|
* @param id The identifier of the transcript.
|
|
121
126
|
* @returns A promise that resolves to the transcript.
|
|
122
127
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return res.data;
|
|
128
|
+
delete(id: string): Promise<Transcript> {
|
|
129
|
+
return this.fetchJson(`/v2/transcript/${id}`, { method: "DELETE" });
|
|
126
130
|
}
|
|
127
131
|
|
|
128
132
|
/**
|
|
129
133
|
* Search through the transcript for a specific set of keywords.
|
|
130
134
|
* You can search for individual words, numbers, or phrases containing up to five words or numbers.
|
|
131
135
|
* @param id The identifier of the transcript.
|
|
132
|
-
* @param
|
|
136
|
+
* @param words Keywords to search for.
|
|
133
137
|
* @return A promise that resolves to the sentences.
|
|
134
138
|
*/
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
{
|
|
139
|
-
params: {
|
|
140
|
-
words: JSON.stringify(words),
|
|
141
|
-
},
|
|
142
|
-
}
|
|
139
|
+
wordSearch(id: string, words: string[]): Promise<WordSearchResponse> {
|
|
140
|
+
const params = new URLSearchParams({ words: words.join(",") });
|
|
141
|
+
return this.fetchJson<WordSearchResponse>(
|
|
142
|
+
`/v2/transcript/${id}/word-search?${params.toString()}`
|
|
143
143
|
);
|
|
144
|
-
return data;
|
|
145
144
|
}
|
|
146
145
|
|
|
147
146
|
/**
|
|
@@ -149,11 +148,8 @@ export class TranscriptService
|
|
|
149
148
|
* @param id The identifier of the transcript.
|
|
150
149
|
* @return A promise that resolves to the sentences.
|
|
151
150
|
*/
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
`/v2/transcript/${id}/sentences`
|
|
155
|
-
);
|
|
156
|
-
return data;
|
|
151
|
+
sentences(id: string): Promise<SentencesResponse> {
|
|
152
|
+
return this.fetchJson<SentencesResponse>(`/v2/transcript/${id}/sentences`);
|
|
157
153
|
}
|
|
158
154
|
|
|
159
155
|
/**
|
|
@@ -161,25 +157,32 @@ export class TranscriptService
|
|
|
161
157
|
* @param id The identifier of the transcript.
|
|
162
158
|
* @return A promise that resolves to the paragraphs.
|
|
163
159
|
*/
|
|
164
|
-
|
|
165
|
-
|
|
160
|
+
paragraphs(id: string): Promise<ParagraphsResponse> {
|
|
161
|
+
return this.fetchJson<ParagraphsResponse>(
|
|
166
162
|
`/v2/transcript/${id}/paragraphs`
|
|
167
163
|
);
|
|
168
|
-
return data;
|
|
169
164
|
}
|
|
170
165
|
|
|
171
166
|
/**
|
|
172
167
|
* Retrieve subtitles of a transcript.
|
|
173
168
|
* @param id The identifier of the transcript.
|
|
174
169
|
* @param format The format of the subtitles.
|
|
170
|
+
* @param chars_per_caption The maximum number of characters per caption.
|
|
175
171
|
* @return A promise that resolves to the subtitles text.
|
|
176
172
|
*/
|
|
177
|
-
async subtitles(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
173
|
+
async subtitles(
|
|
174
|
+
id: string,
|
|
175
|
+
format: SubtitleFormat = "srt",
|
|
176
|
+
chars_per_caption?: number
|
|
177
|
+
): Promise<string> {
|
|
178
|
+
let url = `/v2/transcript/${id}/${format}`;
|
|
179
|
+
if (chars_per_caption) {
|
|
180
|
+
const params = new URLSearchParams();
|
|
181
|
+
params.set("chars_per_caption", chars_per_caption.toString());
|
|
182
|
+
url += `?${params.toString()}`;
|
|
183
|
+
}
|
|
184
|
+
const response = await this.fetch(url);
|
|
185
|
+
return await response.text();
|
|
183
186
|
}
|
|
184
187
|
|
|
185
188
|
/**
|
|
@@ -187,11 +190,10 @@ export class TranscriptService
|
|
|
187
190
|
* @param id The identifier of the transcript.
|
|
188
191
|
* @return A promise that resolves to the subtitles text.
|
|
189
192
|
*/
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
redactions(id: string): Promise<RedactedAudioResponse> {
|
|
194
|
+
return this.fetchJson<RedactedAudioResponse>(
|
|
192
195
|
`/v2/transcript/${id}/redacted-audio`
|
|
193
196
|
);
|
|
194
|
-
return data;
|
|
195
197
|
}
|
|
196
198
|
}
|
|
197
199
|
|
|
@@ -14,19 +14,19 @@ type OneOf<T extends any[]> = T extends [infer Only]
|
|
|
14
14
|
: never;
|
|
15
15
|
|
|
16
16
|
export type AudioData = {
|
|
17
|
-
/** @description
|
|
17
|
+
/** @description Base64 encoded raw audio data */
|
|
18
18
|
audio_data: string;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
export type FinalTranscript = RealtimeBaseTranscript & {
|
|
22
22
|
/**
|
|
23
|
-
* @description Describes the type of message
|
|
23
|
+
* @description Describes the type of message
|
|
24
24
|
* @constant
|
|
25
25
|
*/
|
|
26
26
|
message_type: "FinalTranscript";
|
|
27
|
-
/** @description Whether the text
|
|
27
|
+
/** @description Whether the text is punctuated and cased */
|
|
28
28
|
punctuated: boolean;
|
|
29
|
-
/** @description Whether the text
|
|
29
|
+
/** @description Whether the text is formatted, for example Dollar -> $ */
|
|
30
30
|
text_formatted: boolean;
|
|
31
31
|
};
|
|
32
32
|
|
|
@@ -39,32 +39,35 @@ export type MessageType =
|
|
|
39
39
|
|
|
40
40
|
export type PartialTranscript = RealtimeBaseTranscript & {
|
|
41
41
|
/**
|
|
42
|
-
* @description Describes the type of message
|
|
42
|
+
* @description Describes the type of message
|
|
43
43
|
* @constant
|
|
44
44
|
*/
|
|
45
45
|
message_type: "PartialTranscript";
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
export type RealtimeBaseMessage = {
|
|
49
|
-
/** @description Describes the type of the message
|
|
49
|
+
/** @description Describes the type of the message */
|
|
50
50
|
message_type: MessageType;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
export type RealtimeBaseTranscript = {
|
|
54
|
-
/** @description End time of audio sample relative to session start, in milliseconds
|
|
54
|
+
/** @description End time of audio sample relative to session start, in milliseconds */
|
|
55
55
|
audio_end: number;
|
|
56
|
-
/** @description Start time of audio sample relative to session start, in milliseconds
|
|
56
|
+
/** @description Start time of audio sample relative to session start, in milliseconds */
|
|
57
57
|
audio_start: number;
|
|
58
58
|
/**
|
|
59
59
|
* Format: double
|
|
60
|
-
* @description The confidence score of the entire transcription, between 0 and 1
|
|
60
|
+
* @description The confidence score of the entire transcription, between 0 and 1
|
|
61
61
|
*/
|
|
62
62
|
confidence: number;
|
|
63
|
-
/** @description The timestamp for the partial transcript
|
|
63
|
+
/** @description The timestamp for the partial transcript */
|
|
64
64
|
created: Date;
|
|
65
|
-
/** @description The partial transcript for your audio
|
|
65
|
+
/** @description The partial transcript for your audio */
|
|
66
66
|
text: string;
|
|
67
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* @description An array of objects, with the information for each word in the transcription text.
|
|
69
|
+
* Includes the start and end time of the word in milliseconds, the confidence score of the word, and the text, which is the word itself.
|
|
70
|
+
*/
|
|
68
71
|
words: Word[];
|
|
69
72
|
};
|
|
70
73
|
|
|
@@ -85,27 +88,27 @@ export type RealtimeTranscript = PartialTranscript | FinalTranscript;
|
|
|
85
88
|
export type RealtimeTranscriptType = "PartialTranscript" | "FinalTranscript";
|
|
86
89
|
|
|
87
90
|
export type SessionBegins = RealtimeBaseMessage & {
|
|
88
|
-
/** @description Timestamp when this session will expire
|
|
91
|
+
/** @description Timestamp when this session will expire */
|
|
89
92
|
expires_at: Date;
|
|
90
93
|
/**
|
|
91
|
-
* @description Describes the type of the message
|
|
94
|
+
* @description Describes the type of the message
|
|
92
95
|
* @constant
|
|
93
96
|
*/
|
|
94
97
|
message_type: "SessionBegins";
|
|
95
|
-
/** @description Unique identifier for the established session
|
|
98
|
+
/** @description Unique identifier for the established session */
|
|
96
99
|
session_id: string;
|
|
97
100
|
};
|
|
98
101
|
|
|
99
102
|
export type SessionTerminated = RealtimeBaseMessage & {
|
|
100
103
|
/**
|
|
101
|
-
* @description Describes the type of the message
|
|
104
|
+
* @description Describes the type of the message
|
|
102
105
|
* @constant
|
|
103
106
|
*/
|
|
104
107
|
message_type: "SessionTerminated";
|
|
105
108
|
};
|
|
106
109
|
|
|
107
110
|
export type TerminateSession = RealtimeBaseMessage & {
|
|
108
|
-
/** @description
|
|
111
|
+
/** @description Set to true to end your real-time session forever */
|
|
109
112
|
terminate_session: boolean;
|
|
110
113
|
};
|
|
111
114
|
|
package/src/types/files/index.ts
CHANGED
package/src/types/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
1
|
+
export * from "./files";
|
|
2
|
+
export * from "./transcripts";
|
|
3
|
+
export * from "./realtime";
|
|
4
|
+
export * from "./services";
|
|
5
|
+
export * from "./asyncapi.generated";
|
|
6
|
+
export * from "./openapi.generated";
|