Code Monkey home page Code Monkey logo

autosub's Introduction

autosub

Machine translation for ASS subtitles via MS Translator on Azure


This python script uses the Microsoft Translator API (part of Azure Cognitive Services) to translate dialogue lines in ASS (Advanced Substation Alpha) subtitle files, from and to any of the supported languages. Some formatting tags and forced newlines may be sacrificed in the process.

Usage

Before using the script, you need to grab a key for the Translator service. You'll need an Azure account and set up the Translator service, then get one of the keys provided. The service allows translating some 2 million character per month for free. Should be more than enough for personal use of this script.

Prerequisites

  • Python 3.6 or newer
  • requests python module, ex. installed via pip
  • Translator API key

For ease of use, it is recommended to set the API key as environment variable TRANSLATOR_KEY read by the script. Alternatively, you can provide it on each run as the --key argument.

Using autosub from command line

The general CLI pattern is
autosub [-h] -l LANGUAGES [-s] [-v] [--key KEY] input [output]
Use -h to get help.

Required arguments:

  • Input and output are paths to your files. Point input to the source .ass file and provide a path to write the output. Output is stdout by default.
  • -l or --languages selects source and target language to configure the translator. Provided as source:target using laguage codes (ex. en:de) that can also be listed via the Translator API.

Optional arguments:

  • -s or --stream is a flag. Also, you probably shouln't use it. It tells the script to translate line by line instead of buffering more lines and sending them all at once. Maybe it's less memory intensive, maybe it's useless, but it's definitely slow.
  • -v or --verbose is a flag. This enables printing status messages onto stdout reporting what's happening. Obviously, when file output is stdout, this doesn't do anything. You don't want statuses in your output.
  • --key lets you provide the API key as an argument instead of setting it in environment.

Is this good?

No, of course not. Even if it doesn't screw up formatting or accidentaly skip lines, it's still just machine translation. Have fun.

Why did you...

  • ...use the Microsoft translator? Because I found it maybe does a better job here. Also, getting the API to work wasn't a nightmare.
  • ...make this? Because I'm a lazy retired fansubber. This is surprisingly useful for translating. It does a bulk of the work for you, then you just make it make sense.

Contributing

If you can make sense of the code, feel free to make any improvements, fixes, complete rewrites, whatever. I'll be here.

autosub's People

Contributors

oviovocny avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.