File size: 1,557 Bytes
5db1c40
 
 
 
 
 
 
 
 
 
 
c7723ac
5db1c40
 
139957a
 
5db1c40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0344bb
5db1c40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from TTS.utils.download import download_url
from TTS.utils.synthesizer import Synthesizer
import gradio as gr
import tempfile

MAX_TXT_LEN = 800
Model_DIR = "models"
MODEL_URL = "https://huggingface.co/SpicyqSama007/Bert-VITS2-train-models/resolve/main/G_0.pth"
CONFIG_URL = "https://huggingface.co/SpicyqSama007/Bert-VITS2-train-models/resolve/main/config.json"

def download_model_and_config():
    if not os.path.exists(Model_DIR):
        os.makedirs(Model_DIR)
    download_url(MODEL_URL, Model_DIR, "model.pth")
    download_url(CONFIG_URL, Model_DIR, "config.json")
    return Model_DIR

download_model_and_config()

def tts(text: str):
    if len(text) > MAX_TXT_LEN:
        text = text[:MAX_TXT_LEN]
        print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
    print(text)

    #text = text.replace("I", "ӏ") #replace capital is with "Palochka" symbol

    #model_dir = BASE_DIR.format("male" if voice == "Male" else "female")

    # synthesize
    synthesizer = Synthesizer(f"{Model_DIR}/model.pth", f"{Model_DIR}/config.json")
    wavs = synthesizer.tts(text)

    # return output
    with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
        synthesizer.save_wav(wavs, fp)
        return fp.name

iface = gr.Interface(
    fn=tts,
    inputs=[
        gr.Textbox(
            label="Text",
            value="Default text here if you need it.",
        )
    ],
    outputs=gr.Audio(label="Output", type='filepath'),
    title="TTS",
    live=False
)

iface.launch(share=False)