import gradio as gr from huggingface_hub import hf_hub_download from sbv2_bindings import TTSModel bert = hf_hub_download("googlefan/sbv2_onnx_models", "deberta.onnx") tokenizer = hf_hub_download("googlefan/sbv2_onnx_models", "tokenizer.json") def load_and_synthesize(text: str, path: str, sdp: float = 0.0, speed: float = 1.0): model = TTSModel.from_path(bert, tokenizer) uid = "default" path = path.split("/") filename = "/".join(path[2:]) repo_id = "/".join(path[:2]) model.load_sbv2file_from_path(uid, hf_hub_download(repo_id, filename)) print("All setup is done!") return model.synthesize(text, uid, 0, sdp, 1.0 / speed) iface = gr.Interface( fn=load_and_synthesize, concurrency_limit=1, inputs=[ gr.Textbox(lines=2, placeholder="テキスト"), gr.Textbox(lines=1, max_lines=1, placeholder="パス"), gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.0, label="SDP"), gr.Slider(minimum=0.5, maximum=2.0, step=0.1, value=1.0, label="Speed"), ], outputs="audio", title="SBV2音声合成", description="テキストとモデルのパスを入力して音声を生成します。SDPと速度を調整して音声の質を変更できます。", examples=[ [ "おはようございます。", "googlefan/sbv2_personal_models/tsukuyomi.sbv2", 0.0, 1.0, ], [ "今日の天気は晴れです。場所によっては雨が降るでしょう。", "googlefan/sbv2_personal_models/iroha.sbv2", 0.0, 1.1, ], ], ) iface.launch()