Sous-titre à l'audio, générer audio / discours à partir de n'importe quel fichier de sous-titres à l'aide de Coqui-AI TTS et synchroniser le timing audio en fonction du sous-titre.
Démo:
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 sur linux
apt-get install ffmpegL'utilisation de base est très similaire à Coqui-AI TTS, vous pouvez vérifier leur documentation et le <ng-Iso_code>.
! Remarque: utilisez des sous-titres non chevauchants avec un caractère optimal par seconde / CPS pour un meilleur résultat
! Remarque: utilisez un logiciel comme Aegisub pour modifier votre sous-titre
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 ) Pour utiliser la méthode de conversion vocale, vous devez passer voice_conversion:bool et speaker_wav:str paramater sur self.convert_to_audio . La conversion vocale ne peut pas fonctionner si votre modèle a plusieurs haut-parleurs.
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" )Pour utiliser l'API Coqui Studio, vous devrez configurer la variable d'environnement Coqui_Studio_Token.
import os
os . environ [ 'COQUI_STUDIO_TOKEN' ] = # yourapi Après votre ensemble de jetons, vous pouvez obtenir un modèle de studio Coqui, vous pouvez suivre ce nom Convention coqui_studio/en/<studio_speaker_name>/coqui_studio
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 ) Utilisez le paramètre tempo_mode pour accélérer l'audio. Il y a trois modes de tempo:
tempo_mode="all" : cela accélère tout audio. Utilisez tempo_speed=float pour spécifier la vitesse.tempo_mode="overflow" : Cela accélère l'audio pour correspondre à la durée totale du sous-titre plus la durée vierge avant que le sous-titre suivant n'apparaisse. 'tempo_limit' limitera l'augmentation de la vitesse pendant le débordement.tempo_mode="precise" : cela accélère l'audio pour correspondre à la durée du sous-titre apparaît. " 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" ) Le paramètre shift_mode sera déplacé audio qui ne correspond pas à la durée des sous-titres.
shift_mode="right" : Shift Audio Temps vers la droite et empêcher le chevauchement audio.shift_mode="left" : Shift audio vers la gauche et empêchez le chevauchement audio, mais soyez prudent d'un espace limité sur le côté gauche, car un audio peut disparaître.shift_mode="interpose" : Suivi audio vers la position intermédiaire et empêcher la droite et la gauche de la chevauchement audio. (Remarque: ce mode peut être maladroit, alors utilisez-le avec prudence.)shift_mode="left-overlap" : Shift Audio Time vers la gauche, permettant le chevauchement.shift_mode="interpose-overlap" : Shift Audio vers la position moyenne, permettant le chevauchement.shift_limit=int or "str" : limiter l'audio shift, utilisez entier pour une milliseconde ou une chaîne comme 2.5s pour la seconde 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. et l'équipe Coqui TTS. (2021). Coqui TTS (version 1.4) [logiciel informatique]. https://doi.org/10.5281/zenodo.6334862