Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,14 @@
|
|
1 |
-
import librosa
|
2 |
-
import librosa.display
|
3 |
-
import PIL
|
4 |
import gradio as gr
|
5 |
import numpy as np
|
6 |
-
import
|
|
|
|
|
7 |
|
8 |
-
def
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
def greet(audio):
|
13 |
-
path = audio
|
14 |
-
y, sr = librosa.load(path)
|
15 |
-
print(path)
|
16 |
-
np.clip(y,-1,1,out=y)
|
17 |
-
print(y)
|
18 |
-
|
19 |
-
mel = librosa.feature.melspectrogram(y=y, sr=sr)
|
20 |
-
# #https://stackoverflow.com/questions/56719138/how-can-i-save-a-librosa-spectrogram-plot-as-a-specific-sized-image/57204349#57204349
|
21 |
-
mel = np.log(mel + 1e-9)
|
22 |
-
img = scale_minmax(mel, 0, 255).astype(np.uint8)
|
23 |
-
img = 255-img
|
24 |
-
return img
|
25 |
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
+
import librosa
|
4 |
+
|
5 |
+
# import the librosa library for converting audio to a Mel spectrogram image
|
6 |
|
7 |
+
def audio_to_mel(audio):
|
8 |
+
# convert the audio to a Mel spectrogram image using librosa
|
9 |
+
mel_spectrogram = librosa.feature.melspectrogram(audio)
|
10 |
+
return mel_spectrogram
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# create the gradio app
|
13 |
+
app = gr.Interface(audio_to_mel, "audio", "image")
|
14 |
+
app.launch()
|