File size: 1,434 Bytes
b3dc9a2
 
 
 
 
 
 
 
 
 
9e3613e
 
b3dc9a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import gradio as gr
import numpy as np
from TTS.config import load_config
from TTS.utils.manage import ModelManager
from TTS.utils.synthesizer import Synthesizer


# vits_model = load_model()
# vits_model.tts('Alo')

config_path = 'weight_vits/config.json'
model_path = 'weight_vits/checkpoint_120000.pth'

synthesizer = Synthesizer(
        model_path,
        config_path,
        
    )

# def Vits_model():
    

#     tts = TTS(model_name = 'my_tts',
#               model_path=checkpoint_path,
#               config_path=config_path)

#     return tts

# vits_model = Vits_model()


def predict(text):
    text = text.lower()
    text = text.replace(".", " ")
    text = text.replace(",", "")
    text = text.replace(";", "")
    text = text.replace(":", "")
    text = text.replace("!", "")
    text = text.replace("?", "")
    text = text.replace("(", "")
    text = text.replace(")", "")
    audio = synthesizer.tts(text)

    audio = np.array(audio)
    return 16000,audio

gr.Interface(
    fn=predict,
    inputs="text",
    outputs="audio",

    examples=[
        "Sơn Tùng là ca sĩ nổi tiếng nhất Việt Nam.",
        "Tôi tên là Chu Văn Nam, đến từ Bắc Ninh",
        "Bác Hồ được biết đến không chỉ là một lãnh tụ xuất sắc mà còn là một nhà triết học, nhà cách mạng, và người tầm nhìn vĩ đại.",
    ],
    theme="default",
).launch(debug=False)