Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,29 @@
|
|
|
|
1 |
import torch
|
2 |
import torchaudio
|
3 |
-
import
|
|
|
4 |
|
5 |
-
def
|
6 |
-
#
|
7 |
-
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
mel_spec = transform(waveform)
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
torch.save(
|
16 |
|
17 |
-
|
18 |
-
return pth_file_path
|
19 |
|
20 |
-
# Gradio
|
21 |
-
|
22 |
-
fn=
|
23 |
-
inputs=gr.Audio(
|
24 |
-
outputs=
|
25 |
-
title="Audio to .
|
26 |
-
description="Upload an audio file to convert it
|
27 |
)
|
28 |
|
29 |
-
|
30 |
-
interface.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
import torch
|
3 |
import torchaudio
|
4 |
+
import librosa
|
5 |
+
import numpy as np
|
6 |
|
7 |
+
def audio_to_pth(audio):
|
8 |
+
# 音声ファイル(ファイルパス)を読み込む
|
9 |
+
y, sr = librosa.load(audio, sr=None)
|
10 |
|
11 |
+
# 音声データをテンソルに変換
|
12 |
+
tensor = torch.tensor(y)
|
|
|
13 |
|
14 |
+
# テンソルを .pth ファイルに保存
|
15 |
+
output_path = "audio_features.pth"
|
16 |
+
torch.save(tensor, output_path)
|
17 |
|
18 |
+
return output_path
|
|
|
19 |
|
20 |
+
# Gradio インターフェースの設定
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=audio_to_pth,
|
23 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
24 |
+
outputs="file",
|
25 |
+
title="Audio to .PTH Converter",
|
26 |
+
description="Upload an audio file to convert it to a .pth file containing audio features."
|
27 |
)
|
28 |
|
29 |
+
iface.launch()
|
|