Headers for interacting with Yandex API
Headers for interacting with VOT Backend API
Protected
api} from "../packages/core/src/types/yandex";
import VOTClient, { VOTWorkerClient } from "../packages/node/dist/client";
import { getVideoData } from "../packages/node/dist/utils/videoData";
// link + translationHelp (just for example, this is an unsupported domain)
response = await client.translateVideo({
videoData: videoDataTransHelp,
translationHelp: [
// subtitles file is optional in 2025
// {
Protected
getProtected
getMedia with this format use VOT Backend API Not all video files in .mpd format are currently supported!
WaitingStreamTranslationResponse,
} from "../packages/core/dist/types/yandex";
const client = new VOTClient();
const videoData = await getVideoData("https://youtu.be/JRi2sYaPsjc");
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, response.interval * 1000);
return;
}
if (isAbortedWaitingStream(response)) {
console.log(`Stream translation aborted! Message: ${response.message}`);
return;
}
console.log(`Success! URL: ${response.result.url}`);
const pingId = response.pingId;
setInterval(async () => {
await client.pingStream({
The standard method for requesting the Yandex API, if necessary, you can override how it is done in the example
import { getVideoData } from "../packages/node/dist/utils/videoData";
import { ClientResponse } from "../packages/core/dist/types/client";
// https://github.com/axios/axios
const client = new (class AxiosVOTClient extends VOTClient {
async request<T = unknown>(
path: string,
body: Uint8Array,
headers: Record<string, string> = {},
method = "POST",
): Promise<ClientResponse<T>> {
try {
const res = await axios({
url: `https://${this.host}${path}`,
method,
headers: {
...this.headers,
...headers,
},
data: body,
responseType: "arraybuffer",
...this.fetchOpts,
});
return {
success: res.status === 200,
data: res.data as T,
};
} catch (err) {
return {
success: false,
data: (err as Error)?.message,
};
}
}
//...
})();
const videoData = await getVideoData("https://youtu.be/LK6nLR1bzpI");
The standard method for requesting the VOT Backend API
Optional
partialAudio: undefinedOptional
headers: Record<string, string>Optional
headers: Record<string, string> WaitingStreamTranslationResponse,
} from "../packages/core/dist/types/yandex";
const client = new VOTClient();
const videoData = await getVideoData("https://youtu.be/JRi2sYaPsjc");
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, response.interval * 1000);
return;
}
if (isAbortedWaitingStream(response)) {
console.log(`Stream translation aborted! Message: ${response.message}`);
return;
}
console.log(`Success! URL: ${response.result.url}`);
const pingId = response.pingId;
setInterval(async () => {
await client.pingStream({
} from "../packages/core/src/types/yandex";
import VOTClient, { VOTWorkerClient } from "../packages/node/dist/client";
import { getVideoData } from "../packages/node/dist/utils/videoData";
import { config } from "../packages/shared/src";
const client = new VOTClient({
// https://oauth.yandex.ru
// apiToken: ""
// link + langs
response = await client.translateVideo({
videoData,
requestLang: "en",
responseLang: "ru",
});
console.log(response);
// live voices requires Yandex auth !!!
// You can set apiToken in VOTClient constructor
// or use headers.Cookie: "Session_id=..." in request
response = await client.translateVideo({
videoData,
requestLang: "en",
responseLang: "ru",
extraOpts: {
Protected
translateProtected
translate
If you don't want to use the classic fetch
Example