vot.js - v2.4.12
    Preparing search index...

    Class VOTWorkerClient<V>

    Type Parameters

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    apiToken: undefined | string

    If you don't want to use the classic fetch

    import { ofetch } from "ofetch";

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

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

    const videoData = await getVideoData("https://youtu.be/LK6nLR1bzpI", {
    fetchFn: ofetch.native,
    });
    fetchOpts: Record<string, unknown>
    headers: Record<string, string> = ...

    Headers for interacting with Yandex API

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

    Headers for interacting with VOT Backend API

    host: string
    hostSchemaRe: RegExp = ...
    hostVOT: string
    paths: {
        streamPing: string;
        streamTranslation: string;
        videoSubtitles: string;
        videoTranslation: string;
        videoTranslationAudio: string;
        videoTranslationCache: string;
        videoTranslationFailAudio: string;
    } = ...
    requestLang:
        | "auto"
        | "ru"
        | "en"
        | "zh"
        | "ko"
        | "lt"
        | "lv"
        | "ar"
        | "fr"
        | "it"
        | "es"
        | "de"
        | "ja"
    responseLang: "ru" | "en" | "kk"
    userAgent: string = config.userAgent

    Accessors

    Methods

    • Parameters

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

      Returns { body: unknown; headers: { [key: string]: string }; method: 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({

      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 "../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");

      Type Parameters

      • T = ArrayBuffer

      Parameters

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

      Returns Promise<VOTTypes.ClientType.ClientResponse<T>>

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

      Parameters

      Returns Promise<VOTTypes.YandexType.StreamTranslationResponse>