File size: 1,172 Bytes
c094356
e55e137
9bdb002
 
 
025a8c9
c094356
e55e137
c094356
9bdb002
 
 
 
 
656f75e
9bdb002
d4b96ca
9bdb002
 
 
 
 
 
 
 
 
 
 
c88f883
9bdb002
 
c88f883
 
9bdb002
 
 
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
34
35
36
37
import gradio as gr
import os
import soundfile as sf
import numpy as np
import pretty_midi
from infer import infer_midi_from_wav

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

# MIDI → WAV(サイン波ベースの簡易合成器)
def convert_midi_to_wav_sine(midi_path):
    pm = pretty_midi.PrettyMIDI(midi_path)
    waveform = pm.synthesize()  # デフォルトは fs=22050Hz
    wav_path = os.path.join(BASE_DIR, "synth_output.wav")
    sf.write(wav_path, waveform, samplerate=44100)
    return wav_path

# 推論関数(録音 → MIDI → WAV → 再生用)
def transcribe_and_play(audio_path):
    midi_path = infer_midi_from_wav(audio_path)
    wav_output_path = convert_midi_to_wav_sine(midi_path)
    return wav_output_path, midi_path

# Gradio UI
interface = gr.Interface(
    fn=transcribe_and_play,
    inputs=gr.Audio(type="filepath", label="マイク録音"),
    outputs=[
        gr.Audio(label="再生"),
        gr.File(label="MIDIダウンロード")
    ],
    title="鼻歌からのMIDI変換",
    description="録音した音声をMIDIに変換し、再生して確認、ダウンロードができます。"
)

interface.launch()