File size: 3,180 Bytes
c1e96e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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"):
    pp.load_mod(instr=instr)
    return pp.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'{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']))
def exp(exp_file):
    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."""
    exp_file=f"./example/en_US-ljspeech-high_2__21_0__88_0__22_2__6.json"
    return(gr.update(value=txt),gr.update(value=exp_file))

with gr.Blocks() as b:
    state1=gr.State()
    with gr.Row():
        with gr.Column(scale=1):
            exp1=gr.Button("Example 1")
            json_ob=gr.JSON()
        with gr.Column(scale=2):
            in_txt=gr.Textbox(label="Text",lines=10)
            names=gr.Dropdown()
            sub_btn=gr.Button()
            out_aud=gr.Audio(streaming=True, autoplay=True)
            
        with gr.Column(scale=1):
            with gr.Accordion("Control"):
                length=gr.Slider(label="Length", minimum=0.01, maximum=25.0, value=5)
                noise=gr.Slider(label="Noise", minimum=0.01, maximum=3.0, value=0.1)
                width=gr.Slider(label="Noise Width", minimum=0.01, maximum=5.0, value=0.3)
                sen_pause=gr.Slider(label="Sentence Pause", minimum=0.1, maximum=50.0, value=5.0)
                with gr.Tab("Save Settings"):
                    save_file=gr.File()
                    save_btn=gr.Button("Save")
                    save_btn.click(save_set,[names,length,noise,width,sen_pause],save_file)
                with gr.Tab("Load Settings"):
                    load_file=gr.File()
                    load_file.change(load_set,load_file,[names,length,noise,width,sen_pause])
                    #load_btn=gr.Button("Load").click(load_set,load_file,[names,length,noise,width,sen_pause])
    exp1.click(exp,None,[in_txt,load_file])
    names.change(load_mod,names,json_ob)
    sub_btn.click(pp.tts,[in_txt,names,length,noise,width,sen_pause],out_aud)
    b.load(init,None,names)

b.launch()