File size: 1,892 Bytes
cb01558
 
04e1fa4
cb01558
27dcd4f
cb01558
 
21ae21d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11721e5
21ae21d
 
11721e5
21ae21d
 
 
 
 
 
a58b40e
 
 
 
 
 
21ae21d
 
 
 
 
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
import os

os.system("curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y")
os.system(
    '. "$HOME/.cargo/env" && pip install -U "git+https://github.com/tuna2134/sbv2-api#egg=sbv2_bindings&subdirectory=sbv2_bindings"'
)

import gradio as gr
from huggingface_hub import hf_hub_download
from sbv2_bindings import TTSModel
from uuid import uuid4

bert = hf_hub_download("googlefan/sbv2_onnx_models", "deberta.onnx")
tokenizer = hf_hub_download("googlefan/sbv2_onnx_models", "tokenizer.json")
model = TTSModel.from_path(bert, tokenizer)


def load_and_synthesize(text: str, path: str, sdp: float = 0.0, speed: float = 1.0):
    uid = str(uuid4())
    path = path.split("/")
    filename = path[-1]
    repo_id = "/".join(path[:-1])
    model.load_sbv2file_from_path(uid, hf_hub_download(repo_id, filename))
    print("All setup is done!")
    style_vector = model.get_style_vector(uid, 0, 1.0)
    return model.synthesize(text, uid, style_vector, sdp, 1.0 / speed)


iface = gr.Interface(
    fn=load_and_synthesize,  # The function to call
    inputs=[
        gr.Textbox(lines=2, placeholder="テキスト"),  # Text input
        gr.Textbox(lines=1, max_lines=1, placeholder="パス"),  # Path input
        gr.Slider(
            minimum=0.0, maximum=1.0, step=0.01, value=0.0, label="SDP"
        ),  # SDP input
        gr.Slider(
            minimum=0.5, maximum=2.0, step=0.1, value=1.0, label="Speed"
        ),  # Speed input
    ],
    outputs="audio",
    title="SBV2音声合成",
    description="テキストとモデルのパスを入力して音声を生成します。SDPと速度を調整して音声の質を変更できます。",
    examples=[
        [
            "おはようございます。",
            "googlefan/sbv2_personal_models/tenkas.sbv2",
            0.0,
            1.0,
        ]
    ],
)

# Launch the Gradio app
iface.launch()