Googlefan commited on
Commit
21ae21d
1 Parent(s): 7f75fe9

feat: add app.py and requirements.txt for text-to-speech functionality

Browse files
Files changed (3) hide show
  1. .gitignore +2 -0
  2. app.py +46 -0
  3. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .aider*
2
+ venv/
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import hf_hub_download
3
+ from sbv2_bindings import TTSModel
4
+ from uuid import uuid4
5
+
6
+ bert = hf_hub_download("googlefan/sbv2_onnx_models", "deberta.onnx")
7
+ tokenizer = hf_hub_download("googlefan/sbv2_onnx_models", "tokenizer.json")
8
+ model = TTSModel.from_path(bert, tokenizer)
9
+
10
+
11
+ def load_and_synthesize(text: str, path: str, sdp: float = 0.0, speed: float = 1.0):
12
+ uid = str(uuid4())
13
+ path = path.split("/")
14
+ filename = path[-1]
15
+ repo_id = "/".join(path[:-1])
16
+ model.load_sbv2file_from_path(uid, hf_hub_download(repo_id, filename))
17
+ print("All setup is done!")
18
+ style_vector = model.get_style_vector(uid, 0, 1.0)
19
+ return model.synthesize(text, uid, style_vector, sdp, 1.0 / speed)
20
+
21
+
22
+ iface = gr.Interface(
23
+ fn=load_and_synthesize, # The function to call
24
+ inputs=[
25
+ gr.Textbox(lines=2, placeholder="テキスト"), # Text input
26
+ gr.Textbox(lines=1, max_lines=1, placeholder="パス"), # Path input
27
+ gr.Slider(
28
+ minimum=0.0, maximum=1.0, step=0.01, default=0.0, label="SDP"
29
+ ), # SDP input
30
+ gr.Slider(
31
+ minimum=0.5, maximum=2.0, step=0.1, default=1.0, label="Speed"
32
+ ), # Speed input
33
+ ],
34
+ outputs="audio",
35
+ title="SBV2音声合成",
36
+ description="テキストとモデルのパスを入力して音声を生成します。SDPと速度を調整して音声の質を変更できます。",
37
+ examples=[
38
+ "おはようございます。",
39
+ "googlefan/sbv2_personal_models/tenkas.sbv2",
40
+ 0.0,
41
+ 1.0,
42
+ ],
43
+ )
44
+
45
+ # Launch the Gradio app
46
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ git+https://github.com/tuna2134/sbv2-api#egg=sbv2_bindings&subdirectory=sbv2_bindings
2
+ gradio