Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,20 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
import librosa
|
|
|
4 |
|
5 |
def audio_to_pth(audio):
|
6 |
# 音声ファイル(ファイルパス)を読み込む
|
7 |
y, sr = librosa.load(audio, sr=None)
|
8 |
|
9 |
-
#
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# テンソルを .pth ファイルに保存
|
13 |
output_path = "audio_features.pth"
|
@@ -18,10 +25,10 @@ def audio_to_pth(audio):
|
|
18 |
# Gradio インターフェースの設定
|
19 |
iface = gr.Interface(
|
20 |
fn=audio_to_pth,
|
21 |
-
inputs=gr.Audio(type="filepath"),
|
22 |
outputs="file",
|
23 |
title="Audio to .PTH Converter",
|
24 |
-
description="Upload an audio file to convert it to a .pth file containing audio features."
|
25 |
)
|
26 |
|
27 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
import librosa
|
4 |
+
import numpy as np
|
5 |
|
6 |
def audio_to_pth(audio):
|
7 |
# 音声ファイル(ファイルパス)を読み込む
|
8 |
y, sr = librosa.load(audio, sr=None)
|
9 |
|
10 |
+
# メルスペクトログラムに変換
|
11 |
+
mel_spectrogram = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=128)
|
12 |
+
|
13 |
+
# メルスペクトログラムを対数スケールに変換(TTSモデルに適した形式)
|
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 = "audio_features.pth"
|
|
|
25 |
# Gradio インターフェースの設定
|
26 |
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()
|