yandex video translation API client written in typescript
This repository has been archived on 2024-10-01. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
  • TypeScript 100%
Find a file
2024-05-03 23:26:17 +05:00
assets chore(readme): dumb logo (by @otomir23) and a little disclaimer 2024-05-03 23:26:17 +05:00
proto feat(major): minor bug fixes and content class 2024-05-03 21:12:06 +05:00
src fix(errors): exporting the SubtitlesError/URLError in main script 2024-05-03 22:23:54 +05:00
.editorconfig chore(repository): extra files 2024-04-29 20:47:15 +05:00
.gitattributes chore(repository): extra files 2024-04-29 20:47:15 +05:00
.gitignore Initial commit 2024-04-29 20:32:59 +05:00
LICENSE.txt chore(repository): extra files 2024-04-29 20:47:15 +05:00
package-lock.json chore(readme): dumb logo (by @otomir23) and a little disclaimer 2024-05-03 23:26:17 +05:00
package.json chore(readme): dumb logo (by @otomir23) and a little disclaimer 2024-05-03 23:26:17 +05:00
README.md chore(readme): dumb logo (by @otomir23) and a little disclaimer 2024-05-03 23:26:17 +05:00
tsconfig.json build(package): package initialized 2024-04-29 20:58:16 +05:00

@tskau/vtrans

yandex video translation API client written in typescript

disclaimer

this library is UNOFFICIAL and NOT MADE OR AUTHORIZED by Yandex N.V. or ООО "ЯНДЕКС" (Yandex LLC).

this library is based on the results of reverse engineering and implements a client for a private API that is NOT INTENDED for use in software other than yandex.browser.

installation

npm install --save @tskau/vtrans
# yarn install @tskau/vtrans
# pnpm add @tskau/vtrans

usage example

// you can use require() to use tobalt
// const { Client } = require('@tskau/vtrans')
import { Client } from '@tskau/vtrans'

// you can use the vot-worker if you need
// https://github.com/FOSWLY/vot-worker
const client = new Client({ /* baseUrl: 'https://vot.toil.cc/' */ })

// translate the video
try {
  const translationResult = await client.translate({
    originalUrl: 'https://www.youtube.com/watch?v=rEQm1wU_b9M',
    originalLanguage: 'ru', // ru, en, zh, ko, ar, fr, it, es, de, ja
    translationLanguage: 'en' // ru, en, kk
  })

  if (translationResult.status === 'WORK_IN_PROGRESS') {
    translationResult.remainingTime // translation remaining time
                                    // can be undefined if it's not provided by server
  }

  if (translationResult.status === 'SUCCESS') {
    await translationResult.translation.content.stream() // readable stream
    await translationResult.translation.content.save('/tmp/dolphin-naprosilis-english.mp3') // save as file
    translationResult.translation.content.url // 'https://vtrans.s3-private.mds.yandex.net/...'

    translationResult.translation.duration // duration in seconds
  }
} catch (error) {
  // if error is TranslationError
  // then error message is likely in russian
  // because it's sourced from yandex servers
  console.log(error.message)
}

// fetch subtitles
try {
  const subtitlesResult = await client.getSubtitles({
    originalUrl: 'https://www.youtube.com/watch?v=rEQm1wU_b9M',
    originalLanguage: 'ru' // ru, en, zh, ko, kk, ar, fr, it, es, de, ja
  })

  subtitlesResult.original.language // 'ru'

  await subtitlesResult.original.content.stream() // readable stream
  await subtitlesResult.original.content.save('/tmp/dolphin-naprosilis-russian-yandex.json') // save as file
  subtitlesResult.original.content.url // 'https://brosubs.s3-private.mds.yandex.net/...'

  subtitlesResult.translations[0].language // 'en'

  await subtitlesResult.translations[0].content.stream() // readable stream
  await subtitlesResult.translations[0].content.save('/tmp/dolphin-naprosilis-english-yandex.json') // save as file
  subtitlesResult.translations[0].content.url // 'https://brosubs.s3-private.mds.yandex.net/...'
} catch (error) {
  console.log(error.message) // 'Subtitles not found'
}

acknowledgements

all this exists thanks to Toil's implementation of the CLI/browser extension.

check out the vot-cli (CLI) or voice-over-translation (browser extension).