hayaton0005 commited on
Commit
025a8c9
·
verified ·
1 Parent(s): e55e137

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
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
- # Gradioで呼び出す推論&再生用関数
29
- def transcribe_and_play(wav_file):
30
- midi_path = infer_midi_from_wav(wav_file)
31
  wav_output_path = convert_midi_to_wav(midi_path)
32
  return wav_output_path, midi_path
33
 
34
- # Gradio UI
35
  interface = gr.Interface(
36
  fn=transcribe_and_play,
37
- inputs=gr.Audio(source="microphone", type="filepath", label="\u97f3\u58f0\u9332\u97f3"),
38
  outputs=[
39
- gr.Audio(label="\u30d4\u30a2\u30ce\u97f3\u3067\u518d\u751f"),
40
- gr.File(label="MIDI\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9")
41
  ],
42
- title="\u9f3b\u6b4c\u304b\u3089\u306eMIDI\u5909\u63db\u30c7\u30e2",
43
- description="\u9332\u97f3\u3057\u305f\u97f3\u58f0\u3092MIDI\u306b\u5909\u63db\u3057\u3001\u30d4\u30a2\u30ce\u97f3\u3067\u518d\u751f\u3057\u307e\u3059"
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()