petro-tts-app / inference.py
jhonparra18's picture
Update inference.py
547bc75
raw
history blame
1.05 kB
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 = '1jFhV3p9O6YZhTmK1DlJ5jq-Z2rqz-Av8'
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 = '1cnk0kzVkZVRl9ZWj1lHcnE2EmS28_0de'
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