Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tskau/vtrans

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tskau/vtrans

yandex video translation API client written in typescript

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

vtrans

yandex video translation API client written in typescript

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).

FAQs

Package last updated on 03 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc