petro-tts-app / inference.py
jhonparra18's picture
new model weights
9e660e7
from TTS.api import TTS
from scipy.io import wavfile
import noisereduce as nr
import gdown
import os
cur_path=os.getcwd()
## download weights and config file ##checkpoint 565000
file_id = '1ZuCX7bMegfem3_hGb6OT64gzpmNwRwrn'
url = f'https://drive.google.com/uc?id='
output = f'{cur_path}/best_model.pth'
gdown.download(f"{url}{file_id}", output, quiet=False)
file_id = '1TMzqXDgqLwucusiG8HfAHBf5CozANAoe'
url = f'https://drive.google.com/uc?id='
output = f'{cur_path}/config.json'
gdown.download(f"{url}{file_id}", output, quiet=False)
##load model
fake_voice=TTS(model_path=f"{cur_path}/best_model.pth",
config_path=f"{cur_path}/config.json")
def text_to_speech(text="Hola soy gustavo petro y esto es una prueba",use_nr=True,output_name="test_audio.wav",model=fake_voice):
model.tts_to_file(text,file_path=output_name)
rate, data = wavfile.read(output_name)
if use_nr:
reduced_noise = nr.reduce_noise(y=data, sr=rate)
wavfile.write(output_name, rate, reduced_noise)
return output_name