Spaces:
Running
Running
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() | |