Untertitel zu Audio, generieren Sie Audio/Sprache aus einer beliebigen Untertiteldatei mit Coqui-AI-TTs und synchronisieren Sie das Audio-Timing gemäß den Untertitelzeit.
Demo:
FFMPEG, Pydub, Librosa, Coqui-AI-TTS, FFMPEG-Python
pip install TTS
pip install git+https://github.com/bnsantoso/sub-to-audiopip install TTS
pip install subtoaudioffmpeg auf Linux
apt-get install ffmpegGrundlegende Verwendung ist sehr ähnlich wie bei Coqui-AI-TTs. Sie können ihre Dokumentation und die <Lang-ISO_Code> überprüfen.
HINWEIS: Verwenden Sie nicht überlappende Untertitel mit einem optimalen Zeichen pro Sekunde / CPS, um das beste Ergebnis zu erzielen
HINWEIS: Verwenden Sie Software wie Aegisub, um Ihren Untertitel zu bearbeiten
from subtoaudio import SubToAudio
# list all model
SubToAudio (). coqui_model ()
# get model index
model = SubToAudio (). coqui_model ()[ 1 ]
# The code will output 'yoursubtitle.wav' in the current directory.
sub = SubToAudio ( model_name = model )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = subtitle )
# you can choose 1100 different language using fairseq model
sub = SubToAudio ( fairseq_language = '<lang-iso_code>' )
subtitle = sub . subtitle ( "yoursubtitle.ass" )
sub . convert_to_audio ( sub_data = subtitle )
# specify model name
sub = SubToAudio ( model_name = "tts_models/multilingual/multi-dataset/your_tts" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = subtitle , output_path = "subtitle.wav" )
# specify model and config path
sub = SubToAudio ( model_path = "path/to/your/model.pth" config_path = "config/path.json" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = subtitle )
# speaker=tts.speakers[0] or None if model doesnt have multiple speakers
# language=tts.languages[0] or None if doesnt have multiple languages
# list speaker
sub . speakers ()
speaker1 = sub . speakers ()[ 1 ]
# list languages
sub . languages ()
langu = sub . languages ()[ 0 ]
sub = SubToAudio ( model_name = "tts_models/multilingual/multi-dataset/your_tts" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = subtitle , language = langu , speaker = speaker1 , output_path = "subtitle.wav" )
# Save temporary audio to current folder
sub = SubToAudio ( model_name = "tts_models/multilingual/multi-dataset/your_tts" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = subtitle , output_path = "subtitle.wav" , save_temp = True ) Um die Voice Conversion -Methode zu verwenden, müssen Sie voice_conversion:bool und speaker_wav:str -Paramater auf self.convert_to_audio übergeben. Die Sprachumwandlung kann nicht ausgeführt werden, wenn Ihr Modell mehrere Lautsprecher hat.
from subtoaudio import SubToAudio
sub = SubToAudio ( fairseq_language = "eng" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = subtitle , voice_conversion = True , speaker_wav = "voice.wav" , language = "en" )Um die Coqui Studio -API zu verwenden, müssen Sie die Umgebungsvariable coqui_studio_token konfigurieren.
import os
os . environ [ 'COQUI_STUDIO_TOKEN' ] = # yourapi Nach coqui_studio/en/<studio_speaker_name>/coqui_studio Token -Set können Sie das Coqui Studio -Modell erhalten
from subtoaudio import SubToAudio
sub = SubToAudio ( model_name = "coqui_studio/en/Torcull Diarmuid/coqui_studio" , progress_bar = False )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = subtitle , output_path = "subtitle.wav" , save_temp = True )
# use emotion paramater and speed paramater
sub . convert_to_audio ( sub_data = subtitle , output_path = "subtitle.wav" , emotion = "Happy" , speed = 1.5 ) Verwenden Sie den Parameter tempo_mode , um das Audio zu beschleunigen. Es gibt drei Tempo -Modi:
tempo_mode="all" : Dies beschleunigt alle Audio. Verwenden Sie tempo_speed=float um die Geschwindigkeit anzugeben.tempo_mode="overflow" : Dies beschleunigt das Audio, um der gesamten Untertiteldauer zuzüglich der leeren Dauer zu entsprechen, bevor der nächste Untertitel erscheint. 'tempo_limit' begrenzt die Geschwindigkeitssteigerung während des Überlaufs.tempo_mode="precise" : Dies beschleunigt das Audio, um der Dauer zu entsprechen, die der Untertitel erscheint. " from subtoaudio import SubToAudio
# Speed up tempo or speech rate
sub = SubToAudio ( model_name = "tts_models/de/thorsten/tacotron2-DDC" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = subtitle , tempo_mode = "all" , tempo_speed = 1.3 )
# Change the tempo or speech rate of all audio files , default is 1.2
sub = SubToAudio ( "tts_models/multilingual/multi-dataset/xtts_v1" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = subtitle , tempo_mode = "all" , tempo_speed = 1.3 )
# Change tempo or speech rate to audio that doesn't match the subtitle duration
sub = SubToAudio ( fairseq_language = "ind" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = subtitle , tempo_mode = "overflow" )
# Limit tempo speed on the overflow mode
sub = SubToAudio ( fairseq_language = "ind" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = subtitle , tempo_mode = "overflow" , tempo_limit = 1.2 )
# Match audio length to subtitle duration
sub = SubToAudio ( fairseq_language = "ind" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = subtitle , tempo_mode = "precise" ) Der Parameter shift_mode verschiebt das Audio, das nicht übereinstimmt, die Untertiteldauer.
shift_mode="right" : Verschieben Sie die Audiozeit nach rechts und verhindern Sie Audio -Überlappung.shift_mode="left" : Schicht Audio nach links und verhindern Sie Audio -Überlappung, aber seien Sie vorsichtig mit begrenzten Platz auf der linken Seite, da ein gewisser Audio möglicherweise verschwindet.shift_mode="interpose" : Schicht Audio auf mittlere Position und verhindern Sie rechts und links von Audio -Überlappungen. (Hinweis: Dieser Modus kann klobig sein. Verwenden Sie ihn also vorsichtig.)shift_mode="left-overlap" : Verschiebung Die Audiozeit nach links und ermöglicht eine Überlappung.shift_mode="interpose-overlap" : SHIFT-Audio in die Mitte der Position, und überlappen.2.5s shift_limit=int or "str" : Limit Audio Shift, verwenden from subtoaudio import SubToAudio
# shift mode with limit of 2 second to the right.
sub = SubToAudio ( fairseq_language = "vie" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = sub , tempo_mode = "overflow" , shift_mode = "right" , limit_shift = "2s" )
# shift audio to left position or, time before next subtitle appear
sub = SubToAudio ( fairseq_language = "fra" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = sub , shift_mode = "left-overlap" )
# shift to left, and limit shift only 1 sec.
sub = SubToAudio ( fairseq_language = "ind" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = sub , shift_mode = "left" , shift_limit = 1000 ) # 1000 = 1s from subtoaudio import SubToAudio
# Random Speaker will give you weird result when using bark model with SubToAudio
# Bark random
sub = SubToAudio ( "tts_models/multilingual/multi-dataset/bark" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = subtitle , tempo_mode = "overflow" )
# Tortoise random
sub = SubToAudio ( "tts_models/en/multi-dataset/tortoise-v2" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = subtitle , shift_mode = "overflow" , preset = "fast" )
# To use voice clone you need voice_dir and speaker paramater
# Voice Clone expecting .wav or .npz file inside folder speaker_1
# voice/speaker_1/hana.wav or voice/speaker_1/hana.npz
# if your speaker folder only have .wav file, it will generate .npz file after you runing it.
sub = SubToAudio ( "tts_models/multilingual/multi-dataset/bark" )
subtitle = sub . subtitle ( "yoursubtitle.srt" )
sub . convert_to_audio ( sub_data = subtitle , tempo_mode = "overflow" , voice_dir = "voice/" , speaker = "speaker_1" )
# same with bark, the folder structure like this 'voice/speaker2/ron.wav'
sub = SubToAudio ( "tts_models/en/multi-dataset/tortoise-v2" )
subtitle = sub . subtitle ( "yoursubtitle.ass" )
sub . convert_to_audio ( sub_data = subtitle , tempo_mode = "overflow" , voice_dir = "voice/" , speaker = "speaker2" )Eren, G. und das Coqui TTS -Team. (2021). Coqui TTS (Version 1.4) [Computersoftware]. https://doi.org/10.5281/zenodo.6334862