soiz commited on
Commit
270fe9f
·
verified ·
1 Parent(s): 0f99187

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torchaudio
3
+ import gradio as gr
4
+
5
+ def process_audio_file(audio):
6
+ # 音声ファイルの読み込み
7
+ waveform, sample_rate = torchaudio.load(audio)
8
+
9
+ # Melスペクトログラム特徴量の抽出
10
+ transform = torchaudio.transforms.MelSpectrogram(sample_rate=sample_rate)
11
+ mel_spec = transform(waveform)
12
+
13
+ # 特徴量を .pth ファイルに保存
14
+ pth_file_path = "audio_features.pth"
15
+ torch.save(mel_spec, pth_file_path)
16
+
17
+ # pthファイルのパスを返す
18
+ return pth_file_path
19
+
20
+ # Gradioインターフェースの作成
21
+ interface = gr.Interface(
22
+ fn=process_audio_file,
23
+ inputs=gr.Audio(source="upload", type="filepath"),
24
+ outputs=gr.File(label="Download .pth File"),
25
+ title="Audio to .pth Converter",
26
+ description="Upload an audio file to convert it into a .pth file containing Mel Spectrogram features."
27
+ )
28
+
29
+ # アプリの実行
30
+ interface.launch()