File size: 933 Bytes
270fe9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1392f63
270fe9f
 
 
 
 
 
 
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
import torch
import torchaudio
import gradio as gr

def process_audio_file(audio):
    # 音声ファイルの読み込み
    waveform, sample_rate = torchaudio.load(audio)

    # Melスペクトログラム特徴量の抽出
    transform = torchaudio.transforms.MelSpectrogram(sample_rate=sample_rate)
    mel_spec = transform(waveform)

    # 特徴量を .pth ファイルに保存
    pth_file_path = "audio_features.pth"
    torch.save(mel_spec, pth_file_path)

    # pthファイルのパスを返す
    return pth_file_path

# Gradioインターフェースの作成
interface = gr.Interface(
    fn=process_audio_file,
    inputs=gr.Audio(type="filepath"),  # source="upload" を削除
    outputs=gr.File(label="Download .pth File"),
    title="Audio to .pth Converter",
    description="Upload an audio file to convert it into a .pth file containing Mel Spectrogram features."
)

# アプリの実行
interface.launch()