File size: 1,050 Bytes
53b42ec
 
 
 
 
 
 
c29054b
 
53563e5
bd0061c
53b42ec
 
 
 
bd0061c
 
53b42ec
 
 
 
 
 
 
 
 
547bc75
53b42ec
 
 
547bc75
 
 
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
40
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