Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +29 -25
- requirements.txt +1 -2
app.py
CHANGED
@@ -1,32 +1,36 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
|
|
|
|
|
|
3 |
from infer import infer_midi_from_wav
|
4 |
|
5 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
6 |
|
7 |
-
#
|
8 |
-
def
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
# Gradio インターフェース
|
16 |
-
with gr.Blocks() as demo:
|
17 |
-
gr.Markdown("## 鼻歌からのMIDI変換デモ")
|
18 |
-
gr.Markdown("録音した音声をMIDIに変換し、ブラウザで再生できます。")
|
19 |
-
|
20 |
-
with gr.Row():
|
21 |
-
audio_input = gr.Audio(type="filepath", label="マイク録音")
|
22 |
-
midi_output = gr.File(label="変換されたMIDI")
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
+
import soundfile as sf
|
4 |
+
import numpy as np
|
5 |
+
import pretty_midi
|
6 |
from infer import infer_midi_from_wav
|
7 |
|
8 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
9 |
|
10 |
+
# MIDI → WAV(サイン波ベースの簡易合成器)
|
11 |
+
def convert_midi_to_wav_sine(midi_path):
|
12 |
+
pm = pretty_midi.PrettyMIDI(midi_path)
|
13 |
+
waveform = pm.synthesize() # デフォルトは fs=22050Hz
|
14 |
+
wav_path = os.path.join(BASE_DIR, "synth_output.wav")
|
15 |
+
sf.write(wav_path, waveform, samplerate=22050)
|
16 |
+
return wav_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
# 推論関数(録音 → MIDI → WAV → 再生用)
|
19 |
+
def transcribe_and_play(audio_path):
|
20 |
+
midi_path = infer_midi_from_wav(audio_path)
|
21 |
+
wav_output_path = convert_midi_to_wav_sine(midi_path)
|
22 |
+
return wav_output_path, midi_path
|
23 |
+
|
24 |
+
# Gradio UI
|
25 |
+
interface = gr.Interface(
|
26 |
+
fn=transcribe_and_play,
|
27 |
+
inputs=gr.Audio(type="filepath", label="マイク録音"),
|
28 |
+
outputs=[
|
29 |
+
gr.Audio(label="ピアノ音で再生"),
|
30 |
+
gr.File(label="MIDIダウンロード")
|
31 |
+
],
|
32 |
+
title="鼻歌からのMIDI変換デモ",
|
33 |
+
description="録音した音声をMIDIに変換し、自動で再生します。"
|
34 |
+
)
|
35 |
+
|
36 |
+
interface.launch()
|
requirements.txt
CHANGED
@@ -17,8 +17,7 @@ tqdm
|
|
17 |
librosa
|
18 |
soundfile
|
19 |
gradio
|
20 |
-
|
21 |
-
|
22 |
|
23 |
|
24 |
# MIDI・音楽処理
|
|
|
17 |
librosa
|
18 |
soundfile
|
19 |
gradio
|
20 |
+
scipy
|
|
|
21 |
|
22 |
|
23 |
# MIDI・音楽処理
|