File size: 988 Bytes
c094356
e55e137
025a8c9
c094356
e55e137
c094356
d4b96ca
 
025a8c9
d4b96ca
 
 
 
e55e137
025a8c9
d4b96ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import os
from infer import infer_midi_from_wav

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

# 推論関数(MIDI生成のみ)
def transcribe(audio_path):
    midi_path = infer_midi_from_wav(audio_path)
    return midi_path

# HTML再生用(replay.htmlを読み込む)
replay_html = open(os.path.join(BASE_DIR, "replay.html")).read()

# Gradio インターフェース
with gr.Blocks() as demo:
    gr.Markdown("## 鼻歌からのMIDI変換デモ")
    gr.Markdown("録音した音声をMIDIに変換し、ブラウザで再生できます。")

    with gr.Row():
        audio_input = gr.Audio(type="filepath", label="マイク録音")
        midi_output = gr.File(label="変換されたMIDI")

    run_btn = gr.Button("▶️ 変換")

    # MIDI変換ボタンを押すとMIDIファイルを出力
    run_btn.click(fn=transcribe, inputs=audio_input, outputs=midi_output)

    # HTMLによるMIDI再生UI
    gr.HTML(replay_html)

demo.launch()