Dubb_YouTube_Video / Text_to_speech.py
Rehman1603's picture
Update Text_to_speech.py
496bbeb verified
raw
history blame
860 Bytes
import torch
from TTS.api import TTS
# Get device
device = "cuda" if torch.cuda.is_available() else "cpu"
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
def Text_to_Speech(transcribe_data,lang,voice):
# List available 🐸TTS models
print(TTS().list_models())
# Init TTS
index=1
voice_list=[]
# Run TTS
# ❗ Since this model is multi-lingual voice cloning model, we must set the target speaker_wav and language
# Text to speech list of amplitude values as output
# Text to speech to a file
transcribe_data=list(filter(None,transcribe_data))
for data in transcribe_data:
if data is not None:
if voice is not None:
file_loc=tts.tts_to_file(text=data, speaker_wav=voice, language=lang, file_path=f"output{index}.wav")
voice_list.append(file_loc)
index+=1
return voice_list