Dubb_YouTube_Video / Text_to_speech.py
Rehman1603's picture
Update Text_to_speech.py
538626e verified
raw
history blame
No virus
1.1 kB
import torch
from TTS.api import TTS
import os
from TTS.utils.manage import ModelManager
model_name = "tts_models/multilingual/multi-dataset/xtts_v2"
model_manager = ModelManager()
model_manager.download_model(model_name)
# Get device
device = "cuda" if torch.cuda.is_available() else "cpu"
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2",progress_bar=False).to(device)
default_answer = "y"
answer = input()
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