Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,14 +10,17 @@ def audio_to_pth(audio):
|
|
10 |
# メルスペクトログラムに変換
|
11 |
mel_spectrogram = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=128)
|
12 |
|
13 |
-
#
|
14 |
mel_spectrogram_db = librosa.power_to_db(mel_spectrogram, ref=np.max)
|
15 |
|
16 |
# メルスペクトログラムをテンソルに変換
|
17 |
tensor = torch.tensor(mel_spectrogram_db)
|
18 |
|
|
|
|
|
|
|
19 |
# テンソルを .pth ファイルに保存
|
20 |
-
output_path = "
|
21 |
torch.save(tensor, output_path)
|
22 |
|
23 |
return output_path
|
@@ -27,8 +30,8 @@ iface = gr.Interface(
|
|
27 |
fn=audio_to_pth,
|
28 |
inputs=gr.Audio(type="filepath"),
|
29 |
outputs="file",
|
30 |
-
title="Audio to .PTH Converter",
|
31 |
-
description="Upload an audio file to convert it to a .pth file containing audio features in mel spectrogram format."
|
32 |
)
|
33 |
|
34 |
iface.launch()
|
|
|
10 |
# メルスペクトログラムに変換
|
11 |
mel_spectrogram = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=128)
|
12 |
|
13 |
+
# メルスペクトログラムを対数スケールに変換
|
14 |
mel_spectrogram_db = librosa.power_to_db(mel_spectrogram, ref=np.max)
|
15 |
|
16 |
# メルスペクトログラムをテンソルに変換
|
17 |
tensor = torch.tensor(mel_spectrogram_db)
|
18 |
|
19 |
+
# テンソルを5次元に変換
|
20 |
+
tensor = tensor.unsqueeze(0).unsqueeze(0).unsqueeze(0) # 5次元に拡張
|
21 |
+
|
22 |
# テンソルを .pth ファイルに保存
|
23 |
+
output_path = "audio_features_5d.pth"
|
24 |
torch.save(tensor, output_path)
|
25 |
|
26 |
return output_path
|
|
|
30 |
fn=audio_to_pth,
|
31 |
inputs=gr.Audio(type="filepath"),
|
32 |
outputs="file",
|
33 |
+
title="Audio to 5D Tensor .PTH Converter",
|
34 |
+
description="Upload an audio file to convert it to a .pth file containing a 5D tensor with audio features in mel spectrogram format."
|
35 |
)
|
36 |
|
37 |
iface.launch()
|