sovits-test / main.py
atsushieee's picture
Update main.py
3b4551e
raw
history blame
4.43 kB
import gradio as gr
import os
import pytz
from datetime import datetime
import pandas as pd
import plotly.express as px
from svc_inference import main
# データの作成
data = {
'id': list(range(1, 57)), # 1から56までの数字
'x': [
28, 25, 5, 12, 8, 2, 0, -20, -15, -12, -20, 8, -30, 25, 0, 0, 2, -25,
-25, 20, 15, -2, 0, 15, -30, 15, 8, 28, -10, -22, 20, 20, 8, 20, 0,
0, -8, -10, -32, 0, 0, -8, 2, -25, -32, -20, -18, -5, 15, -22, -25,
-28, -30, 10, 25, 28
],
'y': [
0, -5, -15, -20, -18, -3, 8, 8, 12, 10, 10, -20, 6, -3, 12, -15, 12,
17, 10, -8, -15, -22, 8, 15, 10, -15, -18, -10, 8, 5, -10, -8, -25,
-5, -12, 12, 15, 6, 17, -12, -8, -8, 15, 17, 25, 4, 4, 0, 0, -20,
12, 12, 15, -19, 0, 0
]
}
df = pd.DataFrame(data)
def create_plot():
fig = px.scatter(df, x='x', y='y', text='id',
title='Interactive Numeric Scatter Plot')
# マーカーのスタイルを設定(紫系の色に設定)
fig.update_traces(
marker=dict(
size=10,
color='#663399', # 紫色
line=dict(color='#4B0082', width=1) # より暗い紫の境界線
),
textposition='top center'
)
# レイアウトの設定
fig.update_layout(
height=600,
width=800,
clickmode='event+select',
plot_bgcolor='#eeeeee',
paper_bgcolor='white',
xaxis=dict(
showgrid=True,
zeroline=True,
range=[-35, 35] # x軸の範囲を設定
),
yaxis=dict(
showgrid=True,
zeroline=True,
range=[-30, 30] # y軸の範囲を設定
)
)
return fig
def run_main(audio_file, shift, speaker_id):
# 固定の引数を設定
class Args:
pass
args = Args()
args.config = "configs/base.yaml"
args.model = "./vits_pretrain/sovits5.0.pretrain.pth"
speaker_str = f"{speaker_id:04d}"
args.spk = f"./configs/singers/singer{speaker_str}.npy"
args.wave = audio_file
print(audio_file)
args.shift = shift
# オプショナルパラメータのデフォルト値設定
args.ppg = None
args.vec = None
args.pit = None
args.enable_retrieval = False
args.retrieval_index_prefix = ""
args.retrieval_ratio = 0.5
args.n_retrieval_vectors = 3
args.hubert_index_path = None
args.whisper_index_path = None
args.debug = False
# 現在時刻を取得してファイル名を生成
jst = pytz.timezone('Asia/Tokyo')
now = datetime.now(jst)
date_str = now.strftime("%y%m%d")
time_str = now.strftime("%H%M%S")
output_filename = f"svc_id{speaker_str}_pitch{shift}_speed0_{date_str}_{time_str}.wav"
try:
main(args)
os.rename("svc_out.wav", output_filename) # ファイル名を変更
return output_filename # 新しいファイル名を返す
except Exception as e:
return None
# Gradio インターフェースの作成
with gr.Blocks() as demo:
gr.Markdown("# SVC 音声変換システム")
with gr.Row():
with gr.Column(scale=1.15):
plot = gr.Plot(value=create_plot())
with gr.Column(scale=1):
# 入力音声のアップロード
input_audio = gr.Audio(
label="変換したい音声をアップロード",
type="filepath" # ファイルパスとして取得
)
# Speaker ID の選択
speaker_id = gr.Number(
label="Speaker ID (1-56)",
value=1,
minimum=1,
maximum=56,
step=1
)
# Pitch シフトのスライダー
shift = gr.Slider(
minimum=-12,
maximum=12,
value=0,
step=1,
label="Pitch Shift(-12から+12の半音)"
)
# ボタン
run_btn = gr.Button(value="音声変換を実行", variant="primary", size="lg")
# 出力表示用
output_audio = gr.Audio(label="変換後の音声")
run_btn.click(
fn=run_main,
inputs=[input_audio, shift, speaker_id],
outputs=[output_audio]
)
# アプリケーションの起動
if __name__ == "__main__":
demo.launch()