forked from FOSWLY/vot-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
translateVideo.js
48 lines (46 loc) · 1.21 KB
/
translateVideo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import yandexRequests from "./yandexRequests.js";
import yandexProtobuf from "./yandexProtobuf.js";
export default async function translateVideo(
url,
requestLang,
responseLang,
translationHelp,
callback,
) {
// TODO: Use real duration (maybe)
// 0x40_75_50_00_00_00_00_00
const duration = 341;
await yandexRequests.requestVideoTranslation(
url,
duration,
requestLang,
responseLang,
translationHelp,
(success, response) => {
// console.log(success, response)
if (!success) {
callback(false, "Failed to request video translation");
return;
}
const translateResponse =
yandexProtobuf.decodeTranslationResponse(response);
// console.log(translateResponse)
switch (translateResponse.status) {
case 0:
callback(false, translateResponse.message);
return;
case 1: {
const hasUrl = translateResponse.url != null;
callback(
hasUrl,
hasUrl ? translateResponse.url : "Audio link not received",
);
return;
}
case 2:
callback(false, "The translation will take a few minutes");
return;
}
},
);
}