nakas commited on
Commit
38da35f
1 Parent(s): b5f40c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -23
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 matplotlib.pyplot as plt
 
 
7
 
8
- def scale_minmax(X, min=0.0, max=1.0):
9
- X_std = (X - X.min()) / (X.max() - X.min())
10
- X_scaled = X_std * (max - min) + min
11
- return X_scaled
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
- iface = gr.Interface(fn=greet, inputs= gr.Audio(source="upload",type="filepath"), outputs=gr.Image(type="pil",label="Mel spectrogram"))
27
- iface.launch()
 
 
 
 
 
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()