File size: 995 Bytes
53b42ec
 
 
 
 
 
 
c29054b
 
53b42ec
af0ca18
53b42ec
 
 
 
c29054b
 
53b42ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
file_id = '1-uVNiBjN9d6GBZy3jubvgq7slyEgObyr'
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 = '1-6-cjb0fqLba-KD8WyusRMB_AaIbIds2'
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",output_name="test_audio.wav",model=fake_voice):

    model.tts_to_file(text,file_path=output_name)
    rate, data = wavfile.read(output_name)
    reduced_noise = nr.reduce_noise(y=data, sr=rate)
    wavfile.write(output_name, rate, reduced_noise)
    return output_name