Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
-
from infer import infer_midi_from_wav
|
4 |
import subprocess
|
|
|
5 |
|
6 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
7 |
|
8 |
# MIDI → WAV 変換関数(fluidsynth使用)
|
9 |
def convert_midi_to_wav(midi_path):
|
10 |
-
soundfont_path = os.path.join(BASE_DIR, "soundfont.sf2") # SoundFont
|
11 |
wav_path = os.path.join(BASE_DIR, "synth_output.wav")
|
12 |
|
13 |
command = [
|
@@ -25,22 +25,22 @@ def convert_midi_to_wav(midi_path):
|
|
25 |
raise RuntimeError("fluidsynth conversion failed:\n" + result.stderr.decode())
|
26 |
return wav_path
|
27 |
|
28 |
-
#
|
29 |
-
def transcribe_and_play(
|
30 |
-
midi_path = infer_midi_from_wav(
|
31 |
wav_output_path = convert_midi_to_wav(midi_path)
|
32 |
return wav_output_path, midi_path
|
33 |
|
34 |
-
# Gradio
|
35 |
interface = gr.Interface(
|
36 |
fn=transcribe_and_play,
|
37 |
-
inputs=gr.Audio(
|
38 |
outputs=[
|
39 |
-
gr.Audio(label="
|
40 |
-
gr.File(label="MIDI
|
41 |
],
|
42 |
-
title="
|
43 |
-
description="
|
44 |
)
|
45 |
|
46 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
|
|
3 |
import subprocess
|
4 |
+
from infer import infer_midi_from_wav
|
5 |
|
6 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
7 |
|
8 |
# MIDI → WAV 変換関数(fluidsynth使用)
|
9 |
def convert_midi_to_wav(midi_path):
|
10 |
+
soundfont_path = os.path.join(BASE_DIR, "soundfont.sf2") # SoundFontファイルが必要
|
11 |
wav_path = os.path.join(BASE_DIR, "synth_output.wav")
|
12 |
|
13 |
command = [
|
|
|
25 |
raise RuntimeError("fluidsynth conversion failed:\n" + result.stderr.decode())
|
26 |
return wav_path
|
27 |
|
28 |
+
# 推論関数
|
29 |
+
def transcribe_and_play(audio_path):
|
30 |
+
midi_path = infer_midi_from_wav(audio_path)
|
31 |
wav_output_path = convert_midi_to_wav(midi_path)
|
32 |
return wav_output_path, midi_path
|
33 |
|
34 |
+
# Gradio インターフェース
|
35 |
interface = gr.Interface(
|
36 |
fn=transcribe_and_play,
|
37 |
+
inputs=gr.Audio(type="filepath", label="音声録音(マイク入力)", interactive=True), # ✅ 最新仕様
|
38 |
outputs=[
|
39 |
+
gr.Audio(label="ピアノ音で再生"),
|
40 |
+
gr.File(label="MIDIダウンロード")
|
41 |
],
|
42 |
+
title="鼻歌からのMIDI変換デモ",
|
43 |
+
description="録音した音声をMIDIに変換し、ピアノ音で再生します。"
|
44 |
)
|
45 |
|
46 |
interface.launch()
|