File size: 5,008 Bytes
c1e96e4
 
 
 
 
 
 
 
 
7c99d61
 
 
93b1dd3
7c99d61
8da7c99
3f83581
 
7f314ef
 
8da7c99
3f83581
c1e96e4
 
 
 
 
 
 
 
 
 
a362e37
c1e96e4
 
 
 
 
 
 
7632898
7c99d61
 
 
 
 
 
 
 
 
e32709c
 
 
 
 
 
 
bde8ebb
0ae2022
4f1e643
 
 
c1e96e4
a7848ca
 
 
 
 
 
 
 
7c99d61
 
 
 
4b98ce6
 
 
 
 
 
7c99d61
 
 
 
 
0b16e1e
 
5cb2195
7c99d61
772d708
350198c
d0dc3c5
7c99d61
 
 
 
d0dc3c5
772d708
7c99d61
f904385
e32709c
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import gradio as gr
import subprocess
import os
import json
import uuid
import requests
from pypipertts import PyPiper
pp=PyPiper()

def init():
    key_list=pp.key_list
    return(gr.update(label="Voice",choices=key_list,value="en_US-joe-medium",interactive=True))

def load_mod(instr="en_US-joe-medium"):
    load_mes=gr.Info(f"""Loading Model...<br>{instr}""",duration=2)
    pp.load_mod(instr=instr) 
    with open(pp.json_ob,'r') as f:
        #json_ob=json.dumps(f.read(),indent=4)
        json_ob=f.read()
    load_mes=gr.Info(f"Model Loaded<br>{instr}",duration=2)
    return json_ob


def save_set(model,length,noise,width,sen_pause):
    if not os.path.isdir(f'{os.getcwd()}/saved'):
        os.mkdir(f'{os.getcwd()}/saved')
    set_json={"model":model,"length":length,"noise":noise,"width":width,"pause":sen_pause}
    file_name=f'{model}__{length}__{noise}__{width}__{sen_pause}'.replace(".","_")
    with open(f'{os.getcwd()}/saved/{file_name}.json','w') as file:
        file.write(json.dumps(set_json,indent=4))
    file.close()
    return(f'{os.getcwd()}/saved/{file_name}.json')
def load_set(set_file):
    with open(set_file,'r') as file:
        set_json=json.loads(file.read())
    file.close()
    return(gr.update(value=set_json['model']),gr.update(value=set_json['length']),
           gr.update(value=set_json['noise']),gr.update(value=set_json['width']),
          gr.update(value=set_json['pause']))
txt="""PiperTTS is a powerful text-to-speech TTS node designed to convert written text into high-quality spoken audio. This node leverages advanced voice synthesis models to generate natural-sounding speech, making it an invaluable tool for AI developers looking to add a vocal element to their projects."""
def exp1():
    exp_file=f"./example/en_US-libritts-high__1_4__0_3__0_2__1.json"
    return(gr.update(value=txt),gr.update(value=exp_file))
def exp2():
    exp_file=f"./example/en_US-ryan-high__1__0_6__0_01__1.json"
    return(gr.update(value=txt),gr.update(value=exp_file))
def exp3():
    exp_file=f"./example/en_US-ljspeech-high__1__1__0_5__1.json"
    return(gr.update(value=txt),gr.update(value=exp_file))
def button_on(stream):
    if stream==True:
        return gr.update(interactive=True,visible=True),gr.update(interactive=False,visible=False)
    if stream==False:
        return gr.update(interactive=False,visible=False),gr.update(interactive=True,visible=True)
def clear_aud():
    return None
with gr.Blocks() as b:
    gr.HTML("""<h1 style='font-size:xxx-large;font-weight:900;'>Piper Fast TTS</h1>
    <h4>Piper: <a href='https://github.com/rhasspy/piper' target='_blank'>https://github.com/rhasspy/piper</a></h4>
    <h4>PyPiperTTS: <a href='https://github.com/broadfield-dev/PyPiperTTS' target='_blank'>https://github.com/broadfield-dev/PyPiperTTS</a></h4>
    """)
    with gr.Row():
        with gr.Column(scale=2):
            in_txt=gr.Textbox(label="Text",lines=10)
            names=gr.Dropdown()
            with gr.Row():
                stream_btn=gr.Button("Stream",interactive=True,visible=True)
                sub_btn=gr.Button(interactive=False,visible=False)
                cancel_btn=gr.Button("Stop")
            out_aud=gr.Audio(streaming=True, autoplay=True)        
        with gr.Column(scale=1):
            with gr.Accordion("Control"):
                stream=gr.Checkbox(label="Stream",info="Streaming is fast, but lower quality",value=True,interactive=True)
                length=gr.Slider(label="Length", minimum=0.01, maximum=10.0, value=1)
                # noise=gr.Slider(label="Noise", minimum=0.01, maximum=3.0, value=1)
                noise=1
                # width=gr.Slider(label="Noise Width", minimum=0.01, maximum=3.0, value=1)
                width=1
                # sen_pause=gr.Slider(label="Sentence Pause", minimum=0.1, maximum=10.0, value=1)
                sen_pause=1
                with gr.Tab("Save Settings"):
                    save_btn=gr.Button("Save")
                    save_file=gr.File()
                with gr.Tab("Load Settings"):
                    load_file=gr.File()
        with gr.Column(scale=1):
            with gr.Accordion("Model Config"):
                json_ob=gr.JSON(label="JSON")
    f1=stream.change(button_on,stream,[stream_btn,sub_btn])
    # f2=save_btn.click(save_set,[names,length,noise,width,sen_pause],save_file)
    f3=load_file.change(load_set,load_file,[names,length,noise,width,sen_pause])
    # f4=names.change(load_mod,names,json_ob).then(clear_aud,None,out_aud)
    f5=stream_btn.click(clear_aud,None,out_aud)
    f6=stream_btn.click(pp.stream_tts,[in_txt,names,length,noise,width,sen_pause],out_aud)
    f7=sub_btn.click(clear_aud,None,out_aud)
    f8=sub_btn.click(pp.tts,[in_txt,names,length,noise,width,sen_pause],out_aud)
    # cancel_btn.click(None,None,None,cancels=[f1,f2,f3,f4,f5,f6,f7,f8])
    cancel_btn.click(None,None,None,cancels=[f1,f3,f5,f6,f7,f8])
    b.load(init,None,names)

b.queue(default_concurrency_limit=20).launch(max_threads=40)