需先自行申请 Google Cloud/Azure/DeepL 的 API 凭据并填入 cloud_service_settings.ini;必须安装 ffmpeg,否则音频拉伸不可用;默认只假设单一说话人,多说话人需按人拆 SRT 分别合成;开启两遍合成会翻倍 API 费用。
Auto-Synced-Translated-Dubs
ThioJoeAGPL-3.0更新放缓用字幕文件自动翻译视频文本,再通过 AI 语音合成生成配音音轨,并按字幕时间轴对齐口型,省去手动配音和打轴的麻烦。
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.
v0.21.0发布于 2025-01-28 01:07 UTC1,753star170fork同步于 2026-11-07 07:30 UTC
pip install -r requirements.txt
python main.py 硬件要求按 README 说明
README 未说明显存或 GPU 要求;需本地安装 ffmpeg,翻译与合成依赖云端 API,不在本地跑模型。
用现成 SRT 字幕自动翻译并生成与原视频同步的 AI 配音音轨
用字幕文件自动翻译视频文本,再通过 AI 语音合成生成配音音轨,并按字幕时间轴对齐口型,省去手动配音和打轴的麻烦。
核心能力
- 按字幕时间轴计算每句配音时长并拉伸对齐
- 支持 Google、Azure、Eleven Labs 神经语音合成
- 可批量按语言配置依次翻译与合成多条音轨
- 提供不翻译词表、手动翻译表、音素发音表等细粒度控制
- 附带 TrackAdder 等脚本合并音轨、翻译标题简介
容易踩的坑
内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README
- v0.21.00.21.0最新正式版2025-01-28 · 2025-01-28 01:07 UTC
🛠️ [0.21.0] Fixes
- Updated calls to Azure TTS Batch API so it should work again with the latest API version
- Added check for division by zero when calculating speech rate goal
📈 [0.21.0] New Features and Improvements
- Added
force_always_stretchoption to config, which will make it stretch the audio files after receiving from the TTS service even if it usually supports exact length, like Azure. Should come in handy if certain voices don't support specifying the exact length like some preview voices in Azure.
[0.21.0] Other Changes
- Some behind the scene changes to type hinting and enums instead of hard coded string references to improve reliability when making changes in the future
- v0.20.10.20.12024-02-12 · 2024-02-12 16:12 UTC
查看更新说明
📈 [0.20.0] New Features and Improvements
- New config option
increase_max_chars_for_extreme_speedswhich will temporarily increase the maximum number of characters per line for lines that have extreme speaking speeds, so they are more likely to be combined with lower speed subtitle - Added a check while building the audio file to alert the user if any clips might run too long and possibly overlap with the next clip so you can check the file after generation.
- The script will now auto calculate the average character-rate of the entire video and use that as the char rate goal.
- The user can change this behavior in the config file with the "speech_rate_goal" setting if they want.
- This just means the speech speed might be slightly more natural on average
- Now displays message to tell user that it's downloading batch audio files
- Now when in debug mode, it will put out a proper completed subtitle file, and a separate debug version of the file.
- Fixed a long standing un-noticed bug that was causing combined subtitle lines to be less than ideally optimized
- Speech speeds should be significantly improved on average across all languages
- Addressed some odd punctuation issues where the resulting subtitles would begin with a period or comma, have double punctuation, etc.
🟢 0.20.0 → 0.20.1:
- Updated Azure voices list link in batch.ini
- Updated requirements.txt with correct soundfile version and added aiohttp
- New config option
- v0.20.00.20.02024-01-29 · 2024-01-29 02:24 UTC
查看更新说明
📈 [0.20.0] New Features and Improvements
- New config option
increase_max_chars_for_extreme_speedswhich will temporarily increase the maximum number of characters per line for lines that have extreme speaking speeds, so they are more likely to be combined with lower speed subtitle - Added a check while building the audio file to alert the user if any clips might run too long and possibly overlap with the next clip so you can check the file after generation.
- The script will now auto calculate the average character-rate of the entire video and use that as the char rate goal.
- The user can change this behavior in the config file with the "speech_rate_goal" setting if they want.
- This just means the speech speed might be slightly more natural on average
- Now displays message to tell user that it's downloading batch audio files
- Now when in debug mode, it will put out a proper completed subtitle file, and a separate debug version of the file.
- Fixed a long standing un-noticed bug that was causing combined subtitle lines to be less than ideally optimized
- Speech speeds should be significantly improved on average across all languages
- Addressed some odd punctuation issues where the resulting subtitles would begin with a period or comma, have double punctuation, etc.
- New config option
- v0.19.00.19.02024-01-21 · 2024-01-21 00:52 UTC
查看更新说明
📈 [0.19.0] New Features and Improvements
-
Reduced fragmented TTS speech thanks to new logic in the subtitle combining function
- Controlled by new option in
config.inicalledprioritize_avoiding_fragmented_speech. On by default but can be disabled. - This will reduce the amount of times the TTS voice will sound like it's starting a new sentence even though it's in the middle of a sentence
- Controlled by new option in
-
Add config option
subtitle_gap_threshold_milliseconds, an advanced setting for controlling the largest gap between subtitle line timestamps where the script will consider combining them. SubtitleTrackRemover.pynow has the option to also remove a videos' localizations (aka translated titles and descriptions)- Now the script will also combine subtitles and output an srt file, even if the original language is the same as the target language.
-
- v0.18.10.18.12024-01-20 · 2024-01-20 00:38 UTC
查看更新说明
📝 [0.18.0] Major Fix / Improvement:
-
Fix Fragmented Translations - Now Much Higher Quality Translations
- Until now the script was really only able to translate each line of subtitles individually. This often resulted in extremely fragmented and awkward sentences, and poor translator word choice because of lack of context
- Now, a huge amount (if not all) of the subtitles will be fed to the translator as a single string so the translator will have full context and will have no fragmented sentences
- On a technical level, this took some weird workarounds where I put HTML tag markers at the end of each subtitle line before combining it into the string, such that the translator wouldn't remove them after the fact, so they could be used to put the exact part of the translation back in the correct subtitle timestamp
- This might work better with DeepL, which has more native support for this technique. Google Translate took some extra janky workarounds so if you have trouble with it let me know and I can try to further improve it.
📈 [0.18.0] Other Improvements
-
Added
TranscriptTranslator.pyto the tools folder. This simply lets you translate a basic transcript file as opposed to a subtitle file into multiple languages.
🟢 0.18.0 → 0.18.1:
- Fixed error caused by translator sometimes returning blank lines in some spots
-
用户点评
登录用户的真实使用记录,可按版本和硬件筛选共 0 条
还没有人点评。第一个说出真实体验的人最有价值。
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:
- Use Google Cloud/DeepL to automatically translate the text, and create new translated SRT files
- Use the timings of the subtitle lines to calculate the correct duration of each spoken audio clip
- Create text-to-speech audio clips of the translated text (using more realistic neural voices)
- 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
- 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
- Creates translated versions of the SRT subtitle file
- Batch processing of multiple languages in sequence
- Config files to save translation, synthesis, and language settings for re-use
- Allows detailed control over how the text is translated and synthesized
- Including: A "Don't Translate" phrase list, a manual translation list, a phoneme pronunciation list, and more
Additional Included Tools
TrackAdder.py: Adds all language audio tracks to a video file- With ability to merge a sound effects track into each language track
TitleTranslator.py: Translates a YouTube video Title and Description to multiple languagesTitleDescriptionUpdater.py: Uses YouTube API to update the localized titles and descriptions for a YouTube video using output of TitleTranslator.pySubtitleTrackRemover.py: Uses YouTube API to remove a specific audio track from a YouTube videoTranscriptTranslator.py: Translates an entire transcript of textTranscriptAutoSyncUploader.py: Using YouTube API, it lets you upload a transcript for a video, then have YouTube sync the text to the video- You can also upload multiple pre-translated transcripts and have YouTube sync it, assuming the language is supported
YouTube_Synced_Translations_Downloader.py: Using YouTube API, translate the captions of a video into the specified languages, then download the auto-synced subtitle file created by YouTube
Instructions
External Requirements:
- ffmpeg must be installed (https://ffmpeg.org/download.html)
Optional External Tools:
- Optional: Instead of ffmpeg for audio stretching, you could use the program'rubberband'
- I've actually found ffmpeg works better, but I'll still leave the option for rubberband if you want.
- If using Rubberband, yoou'll need the rubberband binaries. Specifically on [this page](https://github.com/ThioJoe/Auto-Synced-Translated-Dubs/blob/HEAD/(https://breakfastquay.com/rubberband/), find the download link for "Rubber Band Library v3.3.0 command-line utility" (Pick the Windows or MacOS version depending). Then extract the archive to find:
- On Windows: rubberband.exe, rubberband-r3.exe, and sndfile.dll
- On MacOS: rubberband, rubberband-r3
- Doesn't need to be installed, just put the above mentioned files in the same directory as main.py
Setup & Configuration
- 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
- Install the programs mentioned in the 'External Requirements' above.
- 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.
- 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
- Finally open
batch.inito 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_languagesvariable 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.
- In the top
Usage Instructions
- How to Run: After configuring the config files, simply run the main.py script using
python main.pyand let it run to completion- Resulting translated subtitle files and dubbed audio tracks will be placed in a folder called 'output'
- Optional: You can use the separate
TrackAdder.pyscript to automatically add the resulting language tracks to an mp4 video file. Requires ffmpeg to be installed.- Open the script file with a text editor and change the values in the "User Settings" section at the top.
- This will label the tracks so the video file is ready to be uploaded to YouTube. HOWEVER, the multiple audio tracks feature is only available to a limited number of channels. You will most likely need to contact YouTube creator support to ask for access, but there is no guarantee they will grant it.
- Optional: You can use the separate
TitleTranslator.pyscript if uploading to YouTube, which lets you enter a video's Title and Description, and the text will be translated into all the languages enabled inbatch.ini. They wil be placed together in a single text file in the "output" folder.
Additional Notes:
- This works best with subtitles that do not remove gaps between sentences and lines.
- For now the process only assumes there is one speaker. However, if you can make separate SRT files for each speaker, you could generate each TTS track separately using different voices, then combine them afterwards.
- It supports both Google Translate API and DeepL for text translation, and Google, Azure, and Eleven Labs for Text-To-Speech with neural voices.
- This script was written with my own personal workflow in mind. That is:
- I use OpenAI Whisper to transcribe the videos locally, then use Descript to sync that transcription and touch it up with corrections.
- Then I export the SRT file with Descript, which is ideal because it does not just butt the start and end times of each subtitle line next to each other. This means the resulting dub will preserve the pauses between sentences from the original speech. If you use subtitles from another program, you might find the pauses between lines are too short.
- The SRT export settings in Descript that seem to work decently for dubbing are 150 max characters per line, and 1 max line per card.
- The "Two Pass" synthesizing feature (can be enabled in the config) will drastically improve the quality of the final result, but will require synthesizing each clip twice, therefore doubling any API costs.
Currently Supported Text-To-Speech Services:
- Microsoft Azure
- Google Cloud
- Eleven Labs
Currently Supported Translation Services:
- Google Translate
- DeepL
For more information on supported languages by service:
- Google Cloud Translation Supported Languages
- Google Cloud Text-to-Speech Supported Languages
- Azure Text-to-Speech Supported Languages
- DeepL Supported Languages