Headers for interacting with Yandex API
Headers for interacting with VOT Backend API
const client = new VOTClient();
const url = "https://youtu.be/LK6nLR1bzpI";
});
console.log(response);
// subs
const subs = await client.getSubtitles({
videoData,
requestLang: "ru",
});
import { getVideoData } from "../dist/utils/videoData";
const client = new VOTClient();
const videoData = await getVideoData("https://youtu.be/nA9UZF-SZoQ");
let response: StreamTranslationResponse;
let inter: Timer;
function isAbortedWaitingStream(
response: StreamTranslationResponse,
): response is WaitingStreamTranslationResponse {
return !!(response as WaitingStreamTranslationResponse).message;
}
const fn = async () => {
response = await client.translateStream({
videoData,
requestLang: "en",
responseLang: "ru",
});
console.log(response);
clearTimeout(inter);
if (!response.translated && response.interval === 10) {
inter = setTimeout(fn, 10000);
return;
}
if (isAbortedWaitingStream(response)) {
console.log(`Stream translation aborted! Message: ${response.message}`);
return;
}
await client.pingStream({
pingId: response.pingId,
});
console.log(`Success! URL: ${response.result.url}`);
The standard method for requesting the Yandex API, if necessary, you can override how it is done in the example
import { getVideoData } from "../dist/utils/videoData";
// https://github.com/axios/axios
const client = new (class AxiosVOTClient extends VOTClient {
async request(
path: string,
body: Uint8Array,
headers: Record<string, string> = {},
): Promise<ClientResponse> {
try {
const res = await axios({
url: `https://${this.host}${path}`,
method: "POST",
headers: {
...this.headers,
...headers,
},
data: body,
responseType: "arraybuffer",
...this.fetchOpts,
});
return {
success: res.status === 200,
data: res.data as ClientResponse,
};
} catch (err: unknown) {
return {
success: false,
data: (err as Error)?.message,
};
}
}
})();
const videoData = await getVideoData("https://youtu.be/LK6nLR1bzpI");
const response = await client.translateVideo({
videoData,
});
The standard method for requesting the VOT Backend API
import { getVideoData } from "../dist/utils/videoData";
const client = new VOTClient();
const videoData = await getVideoData("https://youtu.be/nA9UZF-SZoQ");
let response: StreamTranslationResponse;
let inter: Timer;
function isAbortedWaitingStream(
response: StreamTranslationResponse,
): response is WaitingStreamTranslationResponse {
return !!(response as WaitingStreamTranslationResponse).message;
}
const fn = async () => {
response = await client.translateStream({
videoData,
requestLang: "en",
responseLang: "ru",
});
console.log(response);
clearTimeout(inter);
if (!response.translated && response.interval === 10) {
inter = setTimeout(fn, 10000);
return;
}
if (isAbortedWaitingStream(response)) {
console.log(`Stream translation aborted! Message: ${response.message}`);
return;
}
await client.pingStream({
pingId: response.pingId,
});
console.log(`Success! URL: ${response.result.url}`);
const client = new VOTClient();
const url = "https://youtu.be/LK6nLR1bzpI";
const videoData = await getVideoData(url);
// only link
let response = await client.translateVideo({
videoData,
});
console.log(response);
const videoDataTransHelp = await getVideoData("https://s3.toil.cc/vot/video");
// link + translationHelp (just for example, this is an unsupported domain)
response = await client.translateVideo({
videoData: videoDataTransHelp,
translationHelp: [
{
target: "subtitles_file_url",
targetUrl: "https://s3.toil.cc/vot/subs.vtt",
},
{
target: "video_file_url",
targetUrl: "https://s3.toil.cc/vot/video.mp4",
},
requestLang: "ru",
});
console.log(subs);
// translate weverse
const videoDataWeverse = await getVideoData(
"https://weverse.io/redvelvet/media/4-139332911",
);
response = await client.translateVideo({
Protected
translateProtected
translate
If you don't want to use the classic fetch
Example