assemblyai 2.0.0-beta → 2.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.
- package/README.md +148 -48
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +218 -123
- package/dist/index.js +225 -123
- package/dist/services/base.d.ts +0 -2
- package/dist/services/index.d.ts +7 -9
- package/dist/services/lemur/index.d.ts +6 -6
- package/dist/services/realtime/factory.d.ts +10 -0
- package/dist/services/realtime/index.d.ts +2 -16
- package/dist/services/realtime/service.d.ts +22 -0
- package/dist/services/transcripts/index.d.ts +37 -20
- package/dist/types/asyncapi.generated.d.ts +87 -0
- package/dist/types/index.d.ts +3 -4
- package/dist/types/openapi.generated.d.ts +685 -0
- package/dist/types/realtime/index.d.ts +30 -11
- package/dist/types/services/abstractions.d.ts +8 -36
- package/dist/types/services/index.d.ts +2 -5
- package/dist/types/transcripts/index.d.ts +5 -0
- package/dist/utils/axios.d.ts +3 -0
- package/dist/utils/errors/realtime.d.ts +1 -4
- package/package.json +16 -8
- package/src/index.ts +3 -0
- package/src/services/base.ts +1 -3
- package/src/services/files/index.ts +4 -4
- package/src/services/index.ts +18 -35
- package/src/services/lemur/index.ts +20 -16
- package/src/services/realtime/factory.ts +32 -0
- package/src/services/realtime/index.ts +2 -106
- package/src/services/realtime/service.ts +184 -0
- package/src/services/transcripts/index.ts +85 -63
- package/src/types/asyncapi.generated.ts +124 -0
- package/src/types/index.ts +3 -4
- package/src/types/openapi.generated.ts +834 -0
- package/src/types/realtime/index.ts +53 -13
- package/src/types/services/abstractions.ts +8 -40
- package/src/types/services/index.ts +2 -6
- package/src/types/transcripts/index.ts +5 -0
- package/src/utils/axios.ts +19 -0
- package/src/utils/errors/realtime.ts +5 -18
- package/dist/services/transcripts/redactions.d.ts +0 -14
- package/dist/services/transcripts/subtitles.d.ts +0 -12
- package/dist/types/core/index.d.ts +0 -2
- package/dist/types/core/params.d.ts +0 -2
- package/dist/types/core/segments.d.ts +0 -28
- package/dist/types/core/transcript.d.ts +0 -113
- package/dist/types/lemur/index.d.ts +0 -79
- package/dist/types/models/auto_chapter.d.ts +0 -8
- package/dist/types/models/auto_highlights.d.ts +0 -11
- package/dist/types/models/content_safety.d.ts +0 -25
- package/dist/types/models/entity_detection.d.ts +0 -7
- package/dist/types/models/index.d.ts +0 -8
- package/dist/types/models/pii.d.ts +0 -3
- package/dist/types/models/sentiment_analysis.d.ts +0 -9
- package/dist/types/models/shared.d.ts +0 -3
- package/dist/types/models/summarization.d.ts +0 -3
- package/dist/types/models/topic_detection.d.ts +0 -17
- package/dist/types/shared/index.d.ts +0 -2
- package/dist/types/shared/pagination.d.ts +0 -7
- package/dist/types/shared/timestamp.d.ts +0 -5
- package/src/services/transcripts/redactions.ts +0 -27
- package/src/services/transcripts/subtitles.ts +0 -26
- package/src/types/core/index.ts +0 -2
- package/src/types/core/params.ts +0 -3
- package/src/types/core/segments.ts +0 -29
- package/src/types/core/transcript.ts +0 -159
- package/src/types/lemur/index.ts +0 -97
- package/src/types/models/auto_chapter.ts +0 -9
- package/src/types/models/auto_highlights.ts +0 -14
- package/src/types/models/content_safety.ts +0 -34
- package/src/types/models/entity_detection.ts +0 -8
- package/src/types/models/index.ts +0 -8
- package/src/types/models/pii.ts +0 -32
- package/src/types/models/sentiment_analysis.ts +0 -11
- package/src/types/models/shared.ts +0 -4
- package/src/types/models/summarization.ts +0 -10
- package/src/types/models/topic_detection.ts +0 -21
- package/src/types/shared/index.ts +0 -2
- package/src/types/shared/pagination.ts +0 -8
- package/src/types/shared/timestamp.ts +0 -6
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import WebSocket from "ws";
|
|
2
|
+
import {
|
|
3
|
+
RealtimeEvents,
|
|
4
|
+
RealtimeListeners,
|
|
5
|
+
RealtimeServiceParams,
|
|
6
|
+
RealtimeMessage,
|
|
7
|
+
RealtimeTranscript,
|
|
8
|
+
PartialTranscript,
|
|
9
|
+
FinalTranscript,
|
|
10
|
+
SessionBeginsEventData,
|
|
11
|
+
} from "@/types";
|
|
12
|
+
import {
|
|
13
|
+
RealtimeError,
|
|
14
|
+
RealtimeErrorMessages,
|
|
15
|
+
RealtimeErrorType,
|
|
16
|
+
} from "@/utils/errors";
|
|
17
|
+
|
|
18
|
+
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
19
|
+
|
|
20
|
+
export class RealtimeService {
|
|
21
|
+
private realtimeUrl: string;
|
|
22
|
+
private sampleRate: number;
|
|
23
|
+
private wordBoost?: string[];
|
|
24
|
+
private apiKey?: string;
|
|
25
|
+
private token?: string;
|
|
26
|
+
private socket?: WebSocket;
|
|
27
|
+
private listeners: RealtimeListeners = {};
|
|
28
|
+
private sessionTerminatedResolve?: () => void;
|
|
29
|
+
|
|
30
|
+
constructor(params: RealtimeServiceParams) {
|
|
31
|
+
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
32
|
+
this.sampleRate = params.sampleRate ?? 16_000;
|
|
33
|
+
this.wordBoost = params.wordBoost;
|
|
34
|
+
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
35
|
+
if ("apiKey" in params) this.apiKey = params.apiKey;
|
|
36
|
+
if ("token" in params) this.token = params.token;
|
|
37
|
+
|
|
38
|
+
if (!(this.apiKey || this.token)) {
|
|
39
|
+
throw new Error("API key or temporary token is required.");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private connectionUrl(): URL {
|
|
44
|
+
const url = new URL(this.realtimeUrl);
|
|
45
|
+
|
|
46
|
+
if (url.protocol !== "wss:") {
|
|
47
|
+
throw new Error("Invalid protocol, must be wss");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const searchParams = new URLSearchParams();
|
|
51
|
+
if (this.token) {
|
|
52
|
+
searchParams.set("token", this.token);
|
|
53
|
+
}
|
|
54
|
+
searchParams.set("sample_rate", this.sampleRate.toString());
|
|
55
|
+
if (this.wordBoost && this.wordBoost.length > 0) {
|
|
56
|
+
searchParams.set("word_boost", JSON.stringify(this.wordBoost));
|
|
57
|
+
}
|
|
58
|
+
url.search = searchParams.toString();
|
|
59
|
+
|
|
60
|
+
return url;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
on(event: "open", listener: (event: SessionBeginsEventData) => void): void;
|
|
64
|
+
on(
|
|
65
|
+
event: "transcript",
|
|
66
|
+
listener: (transcript: RealtimeTranscript) => void
|
|
67
|
+
): void;
|
|
68
|
+
on(
|
|
69
|
+
event: "transcript.partial",
|
|
70
|
+
listener: (transcript: PartialTranscript) => void
|
|
71
|
+
): void;
|
|
72
|
+
on(
|
|
73
|
+
event: "transcript.final",
|
|
74
|
+
listener: (transcript: FinalTranscript) => void
|
|
75
|
+
): void;
|
|
76
|
+
on(event: "error", listener: (error: Error) => void): void;
|
|
77
|
+
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
78
|
+
on(event: RealtimeEvents, listener: (...args: any[]) => void) {
|
|
79
|
+
this.listeners[event] = listener;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
connect() {
|
|
83
|
+
return new Promise<SessionBeginsEventData>((resolve, _) => {
|
|
84
|
+
if (this.socket) {
|
|
85
|
+
throw new Error("Already connected");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const url = this.connectionUrl();
|
|
89
|
+
|
|
90
|
+
let headers;
|
|
91
|
+
if (this.token) {
|
|
92
|
+
headers = undefined;
|
|
93
|
+
} else if (this.apiKey) {
|
|
94
|
+
headers = { Authorization: this.apiKey };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
this.socket = new WebSocket(url.toString(), { headers });
|
|
98
|
+
|
|
99
|
+
this.socket.onclose = ({ code, reason }: WebSocket.CloseEvent) => {
|
|
100
|
+
if (!reason) {
|
|
101
|
+
if (code in RealtimeErrorType) {
|
|
102
|
+
reason = RealtimeErrorMessages[code as RealtimeErrorType];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
this.listeners.close?.(code, reason);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
this.socket.onerror = (errorEvent: WebSocket.ErrorEvent) => {
|
|
109
|
+
if (errorEvent.error) this.listeners.error?.(errorEvent.error as Error);
|
|
110
|
+
else this.listeners.error?.(new Error(errorEvent.message));
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
this.socket.onmessage = ({ data }: WebSocket.MessageEvent) => {
|
|
114
|
+
const message = JSON.parse(data.toString()) as RealtimeMessage;
|
|
115
|
+
if ("error" in message) {
|
|
116
|
+
this.listeners.error?.(new RealtimeError(message.error));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
switch (message.message_type) {
|
|
120
|
+
case "SessionBegins": {
|
|
121
|
+
const openObject: SessionBeginsEventData = {
|
|
122
|
+
sessionId: message.session_id,
|
|
123
|
+
expiresAt: new Date(message.expires_at),
|
|
124
|
+
};
|
|
125
|
+
resolve(openObject);
|
|
126
|
+
this.listeners.open?.(openObject);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
case "PartialTranscript": {
|
|
130
|
+
// message.created is actually a string when coming from the socket
|
|
131
|
+
message.created = new Date(message.created);
|
|
132
|
+
this.listeners.transcript?.(message);
|
|
133
|
+
this.listeners["transcript.partial"]?.(message);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case "FinalTranscript": {
|
|
137
|
+
// message.created is actually a string when coming from the socket
|
|
138
|
+
message.created = new Date(message.created);
|
|
139
|
+
this.listeners.transcript?.(message);
|
|
140
|
+
this.listeners["transcript.final"]?.(message);
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
case "SessionTerminated": {
|
|
144
|
+
this.sessionTerminatedResolve?.();
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
sendAudio(audio: ArrayBuffer) {
|
|
153
|
+
if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
|
|
154
|
+
throw new Error("Socket is not open for communication");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const payload = {
|
|
158
|
+
audio_data: Buffer.from(audio).toString("base64"),
|
|
159
|
+
};
|
|
160
|
+
this.socket.send(JSON.stringify(payload));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async close(waitForSessionTermination = true) {
|
|
164
|
+
if (this.socket) {
|
|
165
|
+
if (this.socket.readyState === WebSocket.OPEN) {
|
|
166
|
+
const terminateSessionMessage = `{"terminate_session": true}`;
|
|
167
|
+
if (waitForSessionTermination) {
|
|
168
|
+
const sessionTerminatedPromise = new Promise<void>((resolve, _) => {
|
|
169
|
+
this.sessionTerminatedResolve = resolve;
|
|
170
|
+
});
|
|
171
|
+
this.socket.send(terminateSessionMessage);
|
|
172
|
+
await sessionTerminatedPromise;
|
|
173
|
+
} else {
|
|
174
|
+
this.socket.send(terminateSessionMessage);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
this.socket.removeAllListeners();
|
|
178
|
+
this.socket.close();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
this.listeners = {};
|
|
182
|
+
this.socket = undefined;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -1,55 +1,42 @@
|
|
|
1
1
|
import BaseService from "@/services/base";
|
|
2
|
-
import TranscriptSubtitleService from "./subtitles";
|
|
3
2
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
SentencesBody,
|
|
3
|
+
ParagraphsResponse,
|
|
4
|
+
SentencesResponse,
|
|
7
5
|
Transcript,
|
|
8
6
|
TranscriptList,
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
CreateTranscriptParameters,
|
|
8
|
+
CreateTranscriptOptions,
|
|
11
9
|
Createable,
|
|
12
10
|
Deletable,
|
|
13
11
|
Listable,
|
|
14
12
|
Retrieveable,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
TranscriptListItem,
|
|
13
|
+
SubtitleFormat,
|
|
14
|
+
RedactedAudioResponse,
|
|
18
15
|
} from "@/types";
|
|
19
|
-
import TranscriptRedactionService from "./redactions";
|
|
20
16
|
import { AxiosInstance } from "axios";
|
|
21
17
|
import FileService from "../files";
|
|
22
18
|
|
|
23
19
|
export default class TranscriptService
|
|
24
20
|
extends BaseService
|
|
25
21
|
implements
|
|
26
|
-
Createable<Transcript,
|
|
22
|
+
Createable<Transcript, CreateTranscriptParameters, CreateTranscriptOptions>,
|
|
27
23
|
Retrieveable<Transcript>,
|
|
28
24
|
Deletable<Transcript>,
|
|
29
25
|
Listable<TranscriptList>
|
|
30
26
|
{
|
|
31
|
-
/**
|
|
32
|
-
* The subtitles service.
|
|
33
|
-
*/
|
|
34
|
-
public subtitles: TranscriptSubtitleService;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* The redactions service.
|
|
38
|
-
*/
|
|
39
|
-
public redactions: TranscriptRedactionService;
|
|
40
|
-
|
|
41
27
|
constructor(client: AxiosInstance, private files: FileService) {
|
|
42
28
|
super(client);
|
|
43
|
-
this.subtitles = new TranscriptSubtitleService(client);
|
|
44
|
-
this.redactions = new TranscriptRedactionService(client);
|
|
45
29
|
}
|
|
46
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Create a transcript.
|
|
33
|
+
* @param params The parameters to create a transcript.
|
|
34
|
+
* @param options The options used for creating the new transcript.
|
|
35
|
+
* @returns A promise that resolves to the newly created transcript.
|
|
36
|
+
*/
|
|
47
37
|
async create(
|
|
48
|
-
params:
|
|
49
|
-
|
|
50
|
-
pollingInterval: 3000,
|
|
51
|
-
pollingTimeout: 180000,
|
|
52
|
-
}
|
|
38
|
+
params: CreateTranscriptParameters,
|
|
39
|
+
options?: CreateTranscriptOptions
|
|
53
40
|
): Promise<Transcript> {
|
|
54
41
|
const path = getPath(params.audio_url);
|
|
55
42
|
if (path !== null) {
|
|
@@ -59,8 +46,8 @@ export default class TranscriptService
|
|
|
59
46
|
|
|
60
47
|
const res = await this.client.post<Transcript>("/v2/transcript", params);
|
|
61
48
|
|
|
62
|
-
if (
|
|
63
|
-
return await this.poll(res.data.id,
|
|
49
|
+
if (options?.poll ?? true) {
|
|
50
|
+
return await this.poll(res.data.id, options);
|
|
64
51
|
}
|
|
65
52
|
|
|
66
53
|
return res.data;
|
|
@@ -68,79 +55,114 @@ export default class TranscriptService
|
|
|
68
55
|
|
|
69
56
|
private async poll(
|
|
70
57
|
transcriptId: string,
|
|
71
|
-
|
|
58
|
+
options?: CreateTranscriptOptions
|
|
72
59
|
): Promise<Transcript> {
|
|
73
|
-
const {
|
|
74
|
-
pollingInterval,
|
|
75
|
-
pollingTimeout,
|
|
76
|
-
resolver = (t) => t.status === "completed" || t.status === "error",
|
|
77
|
-
} = settings;
|
|
78
60
|
const startTime = Date.now();
|
|
79
|
-
|
|
80
61
|
while (true) {
|
|
81
|
-
const transcript = await this.
|
|
82
|
-
if (
|
|
62
|
+
const transcript = await this.get(transcriptId);
|
|
63
|
+
if (transcript.status === "completed" || transcript.status === "error") {
|
|
83
64
|
return transcript;
|
|
84
|
-
} else if (
|
|
85
|
-
|
|
65
|
+
} else if (
|
|
66
|
+
Date.now() - startTime <
|
|
67
|
+
(options?.pollingTimeout ?? 180_000)
|
|
68
|
+
) {
|
|
69
|
+
await new Promise((resolve) =>
|
|
70
|
+
setTimeout(resolve, options?.pollingInterval ?? 3_000)
|
|
71
|
+
);
|
|
86
72
|
} else {
|
|
87
73
|
throw new Error("Polling timeout");
|
|
88
74
|
}
|
|
89
75
|
}
|
|
90
76
|
}
|
|
91
77
|
|
|
92
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Retrieve a transcript.
|
|
80
|
+
* @param id The identifier of the transcript.
|
|
81
|
+
* @returns A promise that resolves to the transcript.
|
|
82
|
+
*/
|
|
83
|
+
async get(id: string): Promise<Transcript> {
|
|
93
84
|
const res = await this.client.get<Transcript>(`/v2/transcript/${id}`);
|
|
94
85
|
return res.data;
|
|
95
86
|
}
|
|
96
87
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
88
|
+
// TODO: add options overload to support list querystring parameters
|
|
89
|
+
/**
|
|
90
|
+
* Retrieves a paged list of transcript listings.
|
|
91
|
+
* @param nextUrl The URL to retrieve the transcript list from. If not provided, the first page will be retrieved.
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
94
|
+
async list(nextUrl?: string | null): Promise<TranscriptList> {
|
|
95
|
+
const { data } = await this.client.get<TranscriptList>(
|
|
96
|
+
nextUrl ?? "/v2/transcript"
|
|
100
97
|
);
|
|
101
|
-
for (const transcriptListItem of data.transcripts
|
|
102
|
-
| TranscriptListItemInternal
|
|
103
|
-
| TranscriptListItem
|
|
104
|
-
)[]) {
|
|
98
|
+
for (const transcriptListItem of data.transcripts) {
|
|
105
99
|
transcriptListItem.created = new Date(transcriptListItem.created);
|
|
106
|
-
|
|
100
|
+
if (transcriptListItem.completed) {
|
|
101
|
+
transcriptListItem.completed = new Date(transcriptListItem.completed);
|
|
102
|
+
}
|
|
107
103
|
}
|
|
108
104
|
|
|
109
105
|
return data as unknown as TranscriptList;
|
|
110
106
|
}
|
|
111
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Delete a transcript
|
|
110
|
+
* @param id The identifier of the transcript.
|
|
111
|
+
* @returns A promise that resolves to the transcript.
|
|
112
|
+
*/
|
|
112
113
|
async delete(id: string): Promise<Transcript> {
|
|
113
114
|
const res = await this.client.delete<Transcript>(`/v2/transcript/${id}`);
|
|
114
115
|
return res.data;
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
/**
|
|
118
|
-
* Retrieve all
|
|
119
|
+
* Retrieve all sentences of a transcript.
|
|
120
|
+
* @param id The identifier of the transcript.
|
|
121
|
+
* @return A promise that resolves to the sentences.
|
|
122
|
+
*/
|
|
123
|
+
async sentences(id: string): Promise<SentencesResponse> {
|
|
124
|
+
const { data } = await this.client.get<SentencesResponse>(
|
|
125
|
+
`/v2/transcript/${id}/sentences`
|
|
126
|
+
);
|
|
127
|
+
return data;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Retrieve all paragraphs of a transcript.
|
|
119
132
|
* @param id The identifier of the transcript.
|
|
120
|
-
* @
|
|
121
|
-
* @return A promise that resolves to the retrieved resource.
|
|
133
|
+
* @return A promise that resolves to the paragraphs.
|
|
122
134
|
*/
|
|
123
|
-
|
|
124
|
-
const { data } = await this.client.get<
|
|
135
|
+
async paragraphs(id: string): Promise<ParagraphsResponse> {
|
|
136
|
+
const { data } = await this.client.get<ParagraphsResponse>(
|
|
137
|
+
`/v2/transcript/${id}/paragraphs`
|
|
138
|
+
);
|
|
125
139
|
return data;
|
|
126
140
|
}
|
|
127
141
|
|
|
128
142
|
/**
|
|
129
|
-
* Retrieve
|
|
143
|
+
* Retrieve subtitles of a transcript.
|
|
130
144
|
* @param id The identifier of the transcript.
|
|
131
|
-
* @
|
|
145
|
+
* @param format The format of the subtitles.
|
|
146
|
+
* @return A promise that resolves to the subtitles text.
|
|
132
147
|
*/
|
|
133
|
-
async
|
|
134
|
-
|
|
148
|
+
async subtitles(id: string, format: SubtitleFormat = "srt"): Promise<string> {
|
|
149
|
+
const { data } = await this.client.get<string>(
|
|
150
|
+
`/v2/transcript/${id}/${format}`
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
return data;
|
|
135
154
|
}
|
|
136
155
|
|
|
137
156
|
/**
|
|
138
|
-
* Retrieve
|
|
157
|
+
* Retrieve redactions of a transcript.
|
|
139
158
|
* @param id The identifier of the transcript.
|
|
140
|
-
* @return A promise that resolves to the
|
|
159
|
+
* @return A promise that resolves to the subtitles text.
|
|
141
160
|
*/
|
|
142
|
-
async
|
|
143
|
-
|
|
161
|
+
async redactions(id: string): Promise<RedactedAudioResponse> {
|
|
162
|
+
const { data } = await this.client.get<RedactedAudioResponse>(
|
|
163
|
+
`/v2/transcript/${id}/redacted-audio`
|
|
164
|
+
);
|
|
165
|
+
return data;
|
|
144
166
|
}
|
|
145
167
|
}
|
|
146
168
|
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// this file is generated by typescript/scripts/generate-types.ts
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
|
|
5
|
+
/** OneOf type helpers */
|
|
6
|
+
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
|
|
7
|
+
type XOR<T, U> = T | U extends object
|
|
8
|
+
? (Without<T, U> & U) | (Without<U, T> & T)
|
|
9
|
+
: T | U;
|
|
10
|
+
type OneOf<T extends any[]> = T extends [infer Only]
|
|
11
|
+
? Only
|
|
12
|
+
: T extends [infer A, infer B, ...infer Rest]
|
|
13
|
+
? OneOf<[XOR<A, B>, ...Rest]>
|
|
14
|
+
: never;
|
|
15
|
+
|
|
16
|
+
export type AudioData = {
|
|
17
|
+
/** @description Raw audio data, base64 encoded. This can be the raw data recorded directly from a microphone or read from an audio file. */
|
|
18
|
+
audio_data: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type FinalTranscript = RealtimeBaseTranscript & {
|
|
22
|
+
/**
|
|
23
|
+
* @description Describes the type of message.
|
|
24
|
+
* @constant
|
|
25
|
+
*/
|
|
26
|
+
message_type: "FinalTranscript";
|
|
27
|
+
/** @description Whether the text has been punctuated and cased. */
|
|
28
|
+
punctuated: boolean;
|
|
29
|
+
/** @description Whether the text has been formatted (e.g. Dollar -> $) */
|
|
30
|
+
text_formatted: boolean;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** @enum {string} */
|
|
34
|
+
export type MessageType =
|
|
35
|
+
| "SessionBegins"
|
|
36
|
+
| "PartialTranscript"
|
|
37
|
+
| "FinalTranscript"
|
|
38
|
+
| "SessionTerminated";
|
|
39
|
+
|
|
40
|
+
export type PartialTranscript = RealtimeBaseTranscript & {
|
|
41
|
+
/**
|
|
42
|
+
* @description Describes the type of message.
|
|
43
|
+
* @constant
|
|
44
|
+
*/
|
|
45
|
+
message_type: "PartialTranscript";
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type RealtimeBaseMessage = {
|
|
49
|
+
/** @description Describes the type of the message. */
|
|
50
|
+
message_type: MessageType;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type RealtimeBaseTranscript = {
|
|
54
|
+
/** @description End time of audio sample relative to session start, in milliseconds. */
|
|
55
|
+
audio_end: number;
|
|
56
|
+
/** @description Start time of audio sample relative to session start, in milliseconds. */
|
|
57
|
+
audio_start: number;
|
|
58
|
+
/**
|
|
59
|
+
* Format: double
|
|
60
|
+
* @description The confidence score of the entire transcription, between 0 and 1.
|
|
61
|
+
*/
|
|
62
|
+
confidence: number;
|
|
63
|
+
/** @description The timestamp for the partial transcript. */
|
|
64
|
+
created: Date;
|
|
65
|
+
/** @description The partial transcript for your audio. */
|
|
66
|
+
text: string;
|
|
67
|
+
/** @description An array of objects, with the information for each word in the transcription text. Includes the start/end time (in milliseconds) of the word, the confidence score of the word, and the text (i.e. the word itself). */
|
|
68
|
+
words: Word[];
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export type RealtimeError = {
|
|
72
|
+
error: string;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type RealtimeMessage =
|
|
76
|
+
| SessionBegins
|
|
77
|
+
| PartialTranscript
|
|
78
|
+
| FinalTranscript
|
|
79
|
+
| SessionTerminated
|
|
80
|
+
| RealtimeError;
|
|
81
|
+
|
|
82
|
+
export type RealtimeTranscript = PartialTranscript | FinalTranscript;
|
|
83
|
+
|
|
84
|
+
/** @enum {string} */
|
|
85
|
+
export type RealtimeTranscriptType = "PartialTranscript" | "FinalTranscript";
|
|
86
|
+
|
|
87
|
+
export type SessionBegins = RealtimeBaseMessage & {
|
|
88
|
+
/** @description Timestamp when this session will expire. */
|
|
89
|
+
expires_at: Date;
|
|
90
|
+
/**
|
|
91
|
+
* @description Describes the type of the message.
|
|
92
|
+
* @constant
|
|
93
|
+
*/
|
|
94
|
+
message_type: "SessionBegins";
|
|
95
|
+
/** @description Unique identifier for the established session. */
|
|
96
|
+
session_id: string;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export type SessionTerminated = RealtimeBaseMessage & {
|
|
100
|
+
/**
|
|
101
|
+
* @description Describes the type of the message.
|
|
102
|
+
* @constant
|
|
103
|
+
*/
|
|
104
|
+
message_type: "SessionTerminated";
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export type TerminateSession = RealtimeBaseMessage & {
|
|
108
|
+
/** @description A boolean value to communicate that you wish to end your real-time session forever. */
|
|
109
|
+
terminate_session: boolean;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export type Word = {
|
|
113
|
+
/**
|
|
114
|
+
* Format: double
|
|
115
|
+
* @description Confidence score of the word
|
|
116
|
+
*/
|
|
117
|
+
confidence: number;
|
|
118
|
+
/** @description End time of the word in milliseconds */
|
|
119
|
+
end: number;
|
|
120
|
+
/** @description Start time of the word in milliseconds */
|
|
121
|
+
start: number;
|
|
122
|
+
/** @description The word itself */
|
|
123
|
+
text: string;
|
|
124
|
+
};
|
package/src/types/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export type * from "./
|
|
2
|
-
export type * from "./lemur";
|
|
3
|
-
export type * from "./models";
|
|
1
|
+
export type * from "./transcripts";
|
|
4
2
|
export type * from "./realtime";
|
|
5
3
|
export type * from "./services";
|
|
6
|
-
export type * from "./
|
|
4
|
+
export type * from "./asyncapi.generated";
|
|
5
|
+
export type * from "./openapi.generated";
|