ThioJoe / Auto-Synced-Translated-Dubs

Automatically translates the text of a video based on a subtitle file, and then uses AI voice services to create a new dubbed & translated audio track where the speech is synced using the subtitle's timings.
GNU General Public License v3.0
1.56k stars 156 forks source link

Auto Synced & Translated Dubs

Automatically translates the text of a video into chosen languages based on a subtitle file, and also uses AI voice to dub the video, while keeping it properly synced to the original video using the subtitle's timings.

How It Works

If you already have a human-made SRT subtitles file for a video, this will:

  1. Use Google Cloud/DeepL to automatically translate the text, and create new translated SRT files
  2. Use the timings of the subtitle lines to calculate the correct duration of each spoken audio clip
  3. Create text-to-speech audio clips of the translated text (using more realistic neural voices)
  4. Stretch or shrink the translated audio clip to be exactly the same length as the original speech.
    • Optional (On by Default): Instead of stretching the audio clips, you can instead do a second pass at synthesizing each clip through the API using the proper speaking speed calculated during the first pass. This slightly improves audio quality.
    • If using Azure TTS, this entire step is not necessary because it allows specifying the desired duration of the speech before synthesis
  5. Builds the audio track by inserting the new audio clips at their correct time points. Therefore the translated speech will remain perfectly in sync with the original video.

More Key Features

Additional Included Tools

Instructions

External Requirements:

Optional External Tools:

Setup & Configuration

  1. Download or clone the repo and install the requirements using pip install -r requirements.txt
    • I wrote this using Python 3.9 but it will probably work with earlier versions too
  2. Install the programs mentioned in the 'External Requirements' above.
  3. Setup your Google Cloud (See Wiki), Microsoft Azure API access and/or DeepL API Token, and set the variables in cloud_service_settings.ini.
    • I recommend Azure for the TTS voice synthesizing because they have newer and better voices in my opinion, and in higher quality (Azure supports sample rate up to 48KHz vs 24KHz with Google).
    • Google Cloud is faster, cheaper and supports more languages for text translation, but you can also use DeepL.
  4. Set up your configuration settings in config.ini. The default settings should work in most cases, but read through them especially if you are using Azure for TTS because there are more applicable options you may want to customize.
    • This config includes options such as the ability to skip text translation, setting formats and sample rate, and using two-pass voice synthesizing
  5. Finally open batch.ini to set the language and voice settings that will be used for each run.
    • In the top [SETTINGS] section you will enter the path to the original video file (used to get the correct audio length), and the original subtitle file path
    • Also you can use the enabled_languages variable to list all the languages that will be translated and synthesized at once. The numbers will correspond to the [LANGUAGE-#] sections in the same config file. The program will process only the languages listed in this variable.
    • This lets you add as many language presets as you want (such as the preferred voice per language), and can choose which languages you want to use (or not use) for any given run.
    • Make sure to check supported languages and voices for each service in their respective documentation.

Usage Instructions


Additional Notes:

Currently Supported Text-To-Speech Services:

Currently Supported Translation Services:

For more information on supported languages by service:


For Result Examples See: Examples Wiki Page

For Planned Features See: Planned Features Wiki Page

For Google Cloud Project Setup Instructions See: Instructions Wiki Page

For Microsoft Azure Setup Instructions See: Azure Instructions Wiki Page