Skip to main content

A Python CLI package for voice over subtitles, with the ability to embed in video, audio ducking, and dynamic voice changer for a single track; auto translating; download and upload to YouTube supports

Project description

Package for voice over subtitles:

  • with the ability to embed in video,
  • audio ducking,
  • dynamic voice changer for a single track. Add --voice-set-anchor at the beginning of the subtitle line. (Applies to all subsequent ones)

pip install -U FastDub


Install for Ubuntu

sudo apt update -y && sudo apt upgrade -y

sudo apt install python3 python3-pip ffmpeg espeak libxml2-dev libxslt1-dev

; libxml for translator functions

sudo python3 -m pip install -U pip setuptools wheel

sudo python3 -m pip install -U FastDub

Install all dependencies

pip install FastDub[ALL] # default

Youtube support

Youtube argument group

pip install FastDub[YT]

Process all videos from a channel

To get the channel id if it only has a username, run the JS code in the browser console:

document.querySelector("body>link").href

Then, in the input parameter, you can pass a link to the channel (with an id, not with a username) or a string of the format "c/CHANNEL_ID"

For example:

python -m fastdub -i "c/UCi-5OZ2tYuwMLIcEyOsbdRA" -yt

YouTube Search argument group

That the input data was a request to YouTube, they must begin with "?".

For Example:

python -m fastdub -i "?#python" -yt -yts-l 5

YouTube Upload argument group

pip install FastDub[YTU]

To download, you need to go to credentials (Create a new project if needed) > + Create credentials > OAuth Client ID > Desktop App

After filling in the required fields, DOWNLOAD JSON format and save to a working folder under the name client_secrets.json

  • Specifying the -ytu-ps argument as non-private may result in processing errors, but this was not observed during testing.

  • Please note that video uploads require a large amount of quota ( default has 10,000 per day)

Subtitles translate

Translate argument group

pip install FastDub[TR]

Usage

python -m fastdub --help

usage: fastdub [-h] [-rc {0,1,2}] [-ra | --cleanup-audio | -n-ra | --no-cleanup-audio] [-ev | --export-video | -n-ev | --no-export-video]
               [-l LANGUAGE] [-tc THREADS_COUNT] -i INPUT [-vf VIDEO_FORMAT] [-sf SUBTITLES_FORMAT] [-En EXCLUDE [EXCLUDE ...]]
               [-Eu EXCLUDE_UNDERSCORE] [-sc | --side-chain | -n-sc | --no-side-chain] [-sc-msl MIN_SILENCE_LEN] [-sc-st SILENCE_THRESH]
               [-sc-gdo GAIN_DURING_OVERLAY]
               [-v {microsoft irina desktop - russian,microsoft zira desktop - english united states),microsoft david desktop - english (united sta
tes,aleksandr-hq,arina,artemiy,evgeniy-eng,evgeniy-rus,lyubov,marianna,mikhail,pavel,tatiana,victoria,vitaliy,volodymyr,yuriy}]
               [-a ALIGN] [-v-set-a VOICE_SET_ANCHOR] [-ll {trace,debug,verbose,info,warning,error,fatal,panic,quiet}]
               [-y | --confirm | -n-y | --no-confirm] [-af AUDIO_FORMAT] [-wm WATERMARK] [-tb | --traceback | -n-tb | --no-traceback] [-yt]        
               [-ak API_KEYS [API_KEYS ...]] [-yts] [-yts-l YOUTUBE_SEARCH_LIMIT] [-yts-rg YOUTUBE_SEARCH_REGION] [-ytu]
               [-ytu-ps {private,public,unlisted}] [-ytu-t] [-tr] [--rewrite-srt | --no-rewrite-srt]
               [-ts {alibaba,argos,baidu,bing,caiyun,deepl,google,iciba,iflytek,itranslate,lingvanex,niutrans,mglip,papago,reverso,sogou,tencent,tr
anslateCom,utibet,yandex,youdao}]

fastdub is a tool for dubbing videos by subtitle files.

options:
  -h, --help            show this help message and exit
  -rc {0,1,2}, --remove-cache {0,1,2}
                        Remove all cache (_cached_texts directory) files
                                0 - No remove cache
                                1 - Delete cache before voice acting
                                2 - Delete cache after voice acting (default)
  -ra, --cleanup-audio, -n-ra, --no-cleanup-audio
                        Remove result audio if video exists (default True) (default: True)
  -ev, --export-video, -n-ev, --no-export-video
  -l LANGUAGE, --language LANGUAGE
                        Subtitles language (ru)
  -tc THREADS_COUNT, --threads-count THREADS_COUNT
                        Process count to download (pass to cpu count, < 2 to disable)
                                *N = N * cpu count

Input:
  -i INPUT, --input INPUT
                        Input directory/YouTube Playlist/Video URL.
  -vf VIDEO_FORMAT, --video-format VIDEO_FORMAT
                        Video format (default: .mp4).
  -sf SUBTITLES_FORMAT, --subtitles-format SUBTITLES_FORMAT
                        Subtitles format (default: .srt).

Input Exclude:
  -En EXCLUDE [EXCLUDE ...], --exclude EXCLUDE [EXCLUDE ...]
                        Exclude <name> (glob)
  -Eu EXCLUDE_UNDERSCORE, --exclude-underscore EXCLUDE_UNDERSCORE
                        Exclude files starts with underscore

Audio Ducking:
  -sc, --side-chain, -n-sc, --no-side-chain
                        Enable audio side chain compress (ducking) (default: True)
  -sc-msl MIN_SILENCE_LEN, --min-silence-len MIN_SILENCE_LEN, --attack MIN_SILENCE_LEN
                        Minimum silence length in ms (default: 100)
  -sc-st SILENCE_THRESH, --silence-thresh SILENCE_THRESH
                        Silence threshold in dB
  -sc-gdo GAIN_DURING_OVERLAY, --gain-during-overlay GAIN_DURING_OVERLAY
                        Gain during overlay in dB (default: -11)

Voicer:
  -v {microsoft irina desktop - russian,microsoft zira desktop - english (united states),microsoft david desktop - english (united states),aleksand
r-hq,arina,artemiy,evgeniy-eng,evgeniy-rus,lyubov,marianna,mikhail,pavel,tatiana,victoria,vitaliy,volodymyr,yuriy}, --voice {microsoft irina deskto
p - russian,microsoft zira desktop - english (united states),microsoft david desktop - english (united states),aleksandr-hq,arina,artemiy,evgeniy-e
ng,evgeniy-rus,lyubov,marianna,mikhail,pavel,tatiana,victoria,vitaliy,volodymyr,yuriy}
                        SAPI voice for voice acting.
  -a ALIGN, --align ALIGN
                        Audio fit align (divisor)
                                1 = right
                                2 = center (default)
  -v-set-a VOICE_SET_ANCHOR, --voice-set-anchor VOICE_SET_ANCHOR
                        Anchor indicating voice actor change (default "!:")

FFMpeg Output:
  -ll {trace,debug,verbose,info,warning,error,fatal,panic,quiet}, --loglevel {trace,debug,verbose,info,warning,error,fatal,panic,quiet}
                        FFMpegWrapper loglevel
  -y, --confirm, -n-y, --no-confirm
                        Don't ask for confirmation (default: True)
  -af AUDIO_FORMAT, --audio-format AUDIO_FORMAT
                        Out audio files format (default wav)
  -wm WATERMARK, --watermark WATERMARK
                        Add watermark to output video

Terminal Output:
  -tb, --traceback, -n-tb, --no-traceback
                        Show debug traceback (default: False)


Translate:
  -tr, --translate      Translate input subtitles files
  --rewrite-srt, --no-rewrite-srt
                        Rewrite input subtitles files.
                        If not, add "_" to the beginning of the original subtitle file. (default: False)
  -ts {alibaba,argos,baidu,bing,caiyun,deepl,google,iciba,iflytek,itranslate,lingvanex,niutrans,mglip,papago,reverso,sogou,tencent,translateCom,uti
bet,yandex,youdao}, --translate-service {alibaba,argos,baidu,bing,caiyun,deepl,google,iciba,iflytek,itranslate,lingvanex,niutrans,mglip,papago,reve
rso,sogou,tencent,translateCom,utibet,yandex,youdao}
                        Subtitle translation service. (default google)

If the voice set after "!:" is not selected during voiceover, clear the cache with the -rc argument

Example

python -m fastdub -i DirToDub -v "Yuriy" --no-sidechain -sf vtt -vf mkv

All files in the folder will be voices (*.mkv, *.vtt)

Default is mp4 video and srt subtitles.

Then: name and name2 will be announced, and the results will be saved to a folder with the appropriate name.

YT Example

python -m fastdub -yt -i https://youtu.be/DD5UKQggXTc -v "Yuriy" -l ru

YouTube Search Example

python -m fastdub -yt -yts -i "#annoyingorange" -l ru

Translate Example

python -m fastdub -i DirToDub -tr -ts iciba -l ru

Default service is Google.

Other

The fastdub.utils module stores helper functions.

python -m pydoc -w fastdub

You can write your issues on GitHub in English or in Russian.

CHANGELOG


3.5.1

Subtitles

  • Исправлены возможные проблемы с разными кодировками (добавлен модуль chardet)

3.5.0

Voiceover Process

  • Добавлен аргумент --export-video (-ev): BooleanOptionalAction, если False (--no-export-video, -n-ev) экспортирует только аудио

3.4.2

  • Незначительные улучшения и оптимизации.

Subtitles

  • Класс TimeLabel теперь не является подклассом Line

3.4.1

  • Исправлена документация

3.4.0

General

  • Добавлена возможность накладывания водяного знака на видео (см. аргумент --watermark)

CLI

  • Bugfix
  • Аргумент --watermark. В него передаётся текст водяного знака.
  • Теперь, при запуске с консоли, показывается мини-баннер FastDub.

Voiceover Process

  • Bugfix
  • Теперь подогнанное аудио (которое начинается на '_') всегда удаляется, т.к это временный файл

FFMpeg Wrapper

  • Добавлен метод класса FFMpegWrapper.get_video_duration_s, который используется в FFMpegWrapper.get_video_duration_ms
  • В видео результат включаются: озвученное аудио, оригинальное аудио, субтитры, оригинальные субтитры (если есть)

Submodules

Translator

  • Теперь используется последняя версия модула translators

3.3.0

General

  • Реализован класс GlobalSettings

Audio Processing

  • Функция calc_speed_change_ffmpeg_arg по расчету аргумента -af ffmpeg для изменения скорости изменена.

    Значительно ускорена с применением другого алгоритма.

  • Оптимизирована функция side_chain.

Voiceover Process

  • Подгон длины аудио и TTS теперь объеденины в один процесс для увеличения производительности.
  • Теперь создаётся подпапка _result/_working_dir в которой сохраняются отдельные уже подогнанные строки субтитров. После чего все части склеиваются ffmpeg-ом. Значительно уменьшено потребление памяти.
  • moviepy больше не является зависимость, вместо этого парсится вывод ffmpeg

FFMpeg Wrapper

  • Теперь все аргументы преобразуются в строки перед вызовом check_call

3.2.0

CLI

  • Опущены необязательные type=str аргументы.
  • Изменена логика BooleanOptionalAction, теперь доступно как --no- так и -n- отрицание.
  • Аргумент --cleanup-audio теперь BooleanOptionalAction (по умолчанию True), --cleanup-level удалён.
  • Аргумент --voice-set-anchor (по умолчанию так же !:).
  • Аргумент --audio-format для выходного аудио (по умолчанию wav).
  • Аргумент --sidechain переименован в --side-chain.
  • Добавлено сокращение аргументу --traceback - -tb.

Voiceover Process

  • Bugfix.
  • Оптимизация подгона длительности дорожек (Fitting-а).

TTS

  • anchor аргумент (см. --voice-set-anchor).
  • Оптимизация смены голосов.

Submodules

YouTube

  • При multi-загрузке полностью загруженные видео удаляются с экрана (чтоб не занимать зря место).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

FastDub-3.5.1.tar.gz (45.0 kB view details)

Uploaded Source

Built Distribution

FastDub-3.5.1-py3-none-any.whl (53.6 kB view details)

Uploaded Python 3

File details

Details for the file FastDub-3.5.1.tar.gz.

File metadata

  • Download URL: FastDub-3.5.1.tar.gz
  • Upload date:
  • Size: 45.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for FastDub-3.5.1.tar.gz
Algorithm Hash digest
SHA256 3a9564e268f4ba6c98ef0c3cba5a73a171c02994af767d312f5e44d2b33ddb7c
MD5 6695b8f18b59e37b39ba1219d3c52e2d
BLAKE2b-256 d8280d4782e9e6cc98a46eac6874880956d79681d5c55c36474b9a82a9c6f1e0

See more details on using hashes here.

File details

Details for the file FastDub-3.5.1-py3-none-any.whl.

File metadata

  • Download URL: FastDub-3.5.1-py3-none-any.whl
  • Upload date:
  • Size: 53.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for FastDub-3.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 55d3b445997a71c0a3ab115f0f440099bcec001457460abc0050a495a76a20b5
MD5 10ae94d89d90c8c992a93b8cfa510674
BLAKE2b-256 997854aa3ec0db61a97cdb7493c6fd4806b13e398364a190b9280cd5eaeffb5a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page