assemblyai 3.0.1 → 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 +20 -10
- package/dist/index.js +20 -10
- package/dist/services/transcripts/index.d.ts +4 -3
- package/dist/types/asyncapi.generated.d.ts +20 -17
- package/dist/types/index.d.ts +6 -6
- package/dist/types/openapi.generated.d.ts +116 -99
- package/dist/types/services/index.d.ts +1 -1
- package/dist/types/transcripts/index.d.ts +16 -2
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/services/transcripts/index.ts +25 -12
- package/src/types/asyncapi.generated.ts +20 -17
- package/src/types/index.ts +6 -6
- package/src/types/openapi.generated.ts +117 -99
- package/src/types/services/index.ts +1 -1
- package/src/types/transcripts/index.ts +16 -2
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
TranscriptListParameters,
|
|
16
16
|
WordSearchResponse,
|
|
17
17
|
BaseServiceParams,
|
|
18
|
+
PollingOptions,
|
|
18
19
|
} from "../..";
|
|
19
20
|
import { FileService } from "../files";
|
|
20
21
|
|
|
@@ -52,16 +53,18 @@ export class TranscriptService
|
|
|
52
53
|
});
|
|
53
54
|
|
|
54
55
|
if (options?.poll ?? true) {
|
|
55
|
-
return await this.
|
|
56
|
+
return await this.waitUntilReady(data.id, options);
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
return data;
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
async waitUntilReady(
|
|
62
63
|
transcriptId: string,
|
|
63
|
-
options?:
|
|
64
|
+
options?: PollingOptions
|
|
64
65
|
): Promise<Transcript> {
|
|
66
|
+
const pollingInterval = options?.pollingInterval ?? 3_000;
|
|
67
|
+
const pollingTimeout = options?.pollingTimeout ?? -1;
|
|
65
68
|
const startTime = Date.now();
|
|
66
69
|
// eslint-disable-next-line no-constant-condition
|
|
67
70
|
while (true) {
|
|
@@ -69,14 +72,12 @@ export class TranscriptService
|
|
|
69
72
|
if (transcript.status === "completed" || transcript.status === "error") {
|
|
70
73
|
return transcript;
|
|
71
74
|
} else if (
|
|
72
|
-
|
|
73
|
-
(
|
|
75
|
+
pollingTimeout > 0 &&
|
|
76
|
+
Date.now() - startTime > pollingTimeout
|
|
74
77
|
) {
|
|
75
|
-
await new Promise((resolve) =>
|
|
76
|
-
setTimeout(resolve, options?.pollingInterval ?? 3_000)
|
|
77
|
-
);
|
|
78
|
-
} else {
|
|
79
78
|
throw new Error("Polling timeout");
|
|
79
|
+
} else {
|
|
80
|
+
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
}
|
|
@@ -136,8 +137,9 @@ export class TranscriptService
|
|
|
136
137
|
* @return A promise that resolves to the sentences.
|
|
137
138
|
*/
|
|
138
139
|
wordSearch(id: string, words: string[]): Promise<WordSearchResponse> {
|
|
140
|
+
const params = new URLSearchParams({ words: words.join(",") });
|
|
139
141
|
return this.fetchJson<WordSearchResponse>(
|
|
140
|
-
`/v2/transcript/${id}/word-search
|
|
142
|
+
`/v2/transcript/${id}/word-search?${params.toString()}`
|
|
141
143
|
);
|
|
142
144
|
}
|
|
143
145
|
|
|
@@ -165,10 +167,21 @@ export class TranscriptService
|
|
|
165
167
|
* Retrieve subtitles of a transcript.
|
|
166
168
|
* @param id The identifier of the transcript.
|
|
167
169
|
* @param format The format of the subtitles.
|
|
170
|
+
* @param chars_per_caption The maximum number of characters per caption.
|
|
168
171
|
* @return A promise that resolves to the subtitles text.
|
|
169
172
|
*/
|
|
170
|
-
async subtitles(
|
|
171
|
-
|
|
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);
|
|
172
185
|
return await response.text();
|
|
173
186
|
}
|
|
174
187
|
|
|
@@ -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/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";
|