Class VOTClient

Hierarchy (view full)

Constructors

Properties

componentVersion: string = config.componentVersion

If you don't want to use the classic fetch


import { ofetch } from "ofetch";
import VOTClient from "../dist/client";
import { getVideoData } from "../dist/utils/videoData";

// https://github.com/unjs/ofetch
const client = new VOTClient({
fetchFn: ofetch.native,
});

const videoData = await getVideoData("https://youtu.be/LK6nLR1bzpI");
const response = await client.translateVideo({
videoData,
});
fetchOpts: Record<string, unknown>
getVideoDataFn: GetVideoDataFunction
headers: Record<string, string> = ...

Headers for interacting with Yandex API

headersVOT: Record<string, string> = ...

Headers for interacting with VOT Backend API

host: string
hostVOT: string
paths: {
    createSession: string;
    streamPing: string;
    streamTranslation: string;
    videoSubtitles: string;
    videoTranslation: string;
} = ...
requestLang:
    | "auto"
    | "ru"
    | "en"
    | "zh"
    | "ko"
    | "lt"
    | "lv"
    | "ar"
    | "fr"
    | "it"
    | "es"
    | "de"
    | "ja"
responseLang: "ru" | "en" | "kk"
schema: URLSchema
schemaVOT: URLSchema
sessions: VOTSessions = {}
userAgent: string = config.userAgent

Methods

  • Parameters

    Returns Promise<{
        expires: number;
        secretKey: string;
        uuid: string;
    }>

  • Parameters

    • body: unknown
    • headers: Record<string, string> = {}

    Returns {
        body: unknown;
        headers: {};
        method: string;
    }

    • body: unknown
    • headers: {}
      • method: string
    • Media with this format use VOT Backend API Not all video files in .mpd format are currently supported!

      Parameters

      • url: string

      Returns boolean


    • 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}`);

      Parameters

      Returns Promise<boolean>

    • 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,
      });

      Parameters

      • path: string
      • body: Uint8Array
      • headers: Record<string, string> = {}

      Returns Promise<ClientResponse>

    • The standard method for requesting the VOT Backend API

      Type Parameters

      • T = unknown

      Parameters

      • path: string
      • body: any
      • headers: Record<string, string> = {}

      Returns Promise<ClientResponse<T>>


    • 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}`);

      Parameters

      Returns Promise<VOTTypes.YandexType.StreamTranslationResponse>


    • 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({

      Parameters

      Returns Promise<VOTTypes.YandexType.VideoTranslationResponse>