File size: 1,688 Bytes
8d910b7
28a1377
8d910b7
 
e7dae75
8d910b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84ce1b5
8d910b7
 
 
 
 
 
e7dae75
8d910b7
 
 
 
 
 
 
e7dae75
137f174
 
8d910b7
e7dae75
137f174
 
8d910b7
 
137f174
 
 
 
8d910b7
 
 
28a1377
8d910b7
137f174
8d910b7
 
28a1377
412fb14
8d910b7
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68

import tempfile ,os
from TTS.config import load_config
import gradio as gr

from TTS.utils.manage import ModelManager
from TTS.utils.synthesizer import Synthesizer


MAX_TXT_LEN = 800


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)

    model_path = os.getcwd() + "/best_model.pth"
    config_path = os.getcwd() + "/config.json"
   

    synthesizer = Synthesizer(
        model_path, config_path
    )


    # synthesize
    if synthesizer is None:
        raise NameError("model not found")
    wavs = synthesizer.tts(text)
    # return output
    with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
        synthesizer.save_wav(wavs, fp)
        return fp.name


description="""
This is a demo of persian text to speech model.


Model trained on this dataset : https://www.kaggle.com/datasets/magnoliasis/persian-tts-dataset-famale



"""
article= ""
examples=[
    ["مثنوی یکی از قالب های شعری است ک هر بیت قافیه ی جداگانه دارد"],
    ["در گلو ماند خس او سالها، چیست آن خس مهر جاه و مالها"],
]
iface = gr.Interface(
    fn=tts,
    inputs=[
        gr.Textbox(
            label="Text",
            value="زندگی فقط یک بار است؛ از آن به خوبی استفاده کن",
        )
    ],
    outputs=gr.Audio(label="Output",type='filepath'),
    examples=examplesو
    title="🗣️Persian ttt - glow_tts 🗣️",
    description=description,
    article=article,
    live=False
)
iface.launch(share=False)