Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
+
import os
|
| 4 |
+
import json
|
| 5 |
+
import uuid
|
| 6 |
+
import requests
|
| 7 |
+
from pypipertts import PyPiper
|
| 8 |
+
pp=PyPiper()
|
| 9 |
+
|
| 10 |
+
def init():
|
| 11 |
+
key_list=pp.key_list
|
| 12 |
+
return(gr.update(label="Voice",choices=key_list,value="en_US-joe-medium",interactive=True))
|
| 13 |
+
|
| 14 |
+
def load_mod(instr="en_US-joe-medium"):
|
| 15 |
+
pp.load_mod(instr=instr)
|
| 16 |
+
return pp.json_ob
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def save_set(model,length,noise,width,sen_pause):
|
| 20 |
+
if not os.path.isdir(f'{os.getcwd()}/saved'):
|
| 21 |
+
os.mkdir(f'{os.getcwd()}/saved')
|
| 22 |
+
set_json={"model":model,"length":length,"noise":noise,"width":width,"pause":sen_pause}
|
| 23 |
+
file_name=f'{model}__{length}__{noise}__{width}__{sen_pause}'.replace(".","_")
|
| 24 |
+
with open(f'{os.getcwd()}/saved/{file_name}.json','w') as file:
|
| 25 |
+
file.write(json.dumps(set_json,indent=4))
|
| 26 |
+
file.close()
|
| 27 |
+
return(f'{file_name}.json')
|
| 28 |
+
def load_set(set_file):
|
| 29 |
+
with open(set_file,'r') as file:
|
| 30 |
+
set_json=json.loads(file.read())
|
| 31 |
+
file.close()
|
| 32 |
+
return(gr.update(value=set_json['model']),gr.update(value=set_json['length']),
|
| 33 |
+
gr.update(value=set_json['noise']),gr.update(value=set_json['width']),
|
| 34 |
+
gr.update(value=set_json['pause']))
|
| 35 |
+
def exp(exp_file):
|
| 36 |
+
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."""
|
| 37 |
+
exp_file=f"./example/en_US-ljspeech-high_2__21_0__88_0__22_2__6.json"
|
| 38 |
+
return(gr.update(value=txt),gr.update(value=exp_file))
|
| 39 |
+
|
| 40 |
+
with gr.Blocks() as b:
|
| 41 |
+
state1=gr.State()
|
| 42 |
+
with gr.Row():
|
| 43 |
+
with gr.Column(scale=1):
|
| 44 |
+
exp1=gr.Button("Example 1")
|
| 45 |
+
json_ob=gr.JSON()
|
| 46 |
+
with gr.Column(scale=2):
|
| 47 |
+
in_txt=gr.Textbox(label="Text",lines=10)
|
| 48 |
+
names=gr.Dropdown()
|
| 49 |
+
sub_btn=gr.Button()
|
| 50 |
+
out_aud=gr.Audio(streaming=True, autoplay=True)
|
| 51 |
+
|
| 52 |
+
with gr.Column(scale=1):
|
| 53 |
+
with gr.Accordion("Control"):
|
| 54 |
+
length=gr.Slider(label="Length", minimum=0.01, maximum=25.0, value=5)
|
| 55 |
+
noise=gr.Slider(label="Noise", minimum=0.01, maximum=3.0, value=0.1)
|
| 56 |
+
width=gr.Slider(label="Noise Width", minimum=0.01, maximum=5.0, value=0.3)
|
| 57 |
+
sen_pause=gr.Slider(label="Sentence Pause", minimum=0.1, maximum=50.0, value=5.0)
|
| 58 |
+
with gr.Tab("Save Settings"):
|
| 59 |
+
save_file=gr.File()
|
| 60 |
+
save_btn=gr.Button("Save")
|
| 61 |
+
save_btn.click(save_set,[names,length,noise,width,sen_pause],save_file)
|
| 62 |
+
with gr.Tab("Load Settings"):
|
| 63 |
+
load_file=gr.File()
|
| 64 |
+
load_file.change(load_set,load_file,[names,length,noise,width,sen_pause])
|
| 65 |
+
#load_btn=gr.Button("Load").click(load_set,load_file,[names,length,noise,width,sen_pause])
|
| 66 |
+
exp1.click(exp,None,[in_txt,load_file])
|
| 67 |
+
names.change(load_mod,names,json_ob)
|
| 68 |
+
sub_btn.click(pp.tts,[in_txt,names,length,noise,width,sen_pause],out_aud)
|
| 69 |
+
b.load(init,None,names)
|
| 70 |
+
|
| 71 |
+
b.launch()
|