nakas commited on
Commit
b90c087
1 Parent(s): 05e7b81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -25
app.py CHANGED
@@ -1,31 +1,14 @@
1
- import librosa
2
  import gradio as gr
3
  import numpy as np
4
  import librosa
5
- import soundfile as sf
6
 
7
- def scale_minmax(X, min=0.0, max=1.0):
8
- X_std = (X - X.min()) / (X.max() - X.min())
9
- X_scaled = X_std * (max - min) + min
10
- return X_scaled
11
- def greet(name):
12
- print("np array" , name)
13
- #step 0 revert the things done to get back to the raw spectrogram
14
- # i
15
- #img = np.flip(img, axis=0) # put low frequencies at the bottom in image
16
- img = (255-name) *-1
17
- img = scale_minmax(img, 0, 1).astype(np.float64)
18
-
19
- # step1 - converting a wav file to numpy array and then converting that to mel-spectrogram
20
- S_inv = librosa.feature.inverse.mel_to_audio(img)
21
-
22
- #Export wav
23
-
24
- # step4 - save it as a wav file
25
- return (16000,S_inv)
26
- #mel -> audio
27
 
28
- iface = gr.Interface(fn=greet, inputs=gr.Image(label="Mel spectrogram", image_mode="L"), outputs=gr.Audio(label="Audio"))
29
- iface.launch()
 
 
30
 
31
- #Read melpectogram of npy file
 
 
 
 
1
  import gradio as gr
2
  import numpy as np
3
  import librosa
 
4
 
5
+ # import the librosa library for converting a Mel spectrogram image to audio
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ def mel_to_audio(mel_spectrogram):
8
+ # convert the Mel spectrogram image to audio using librosa
9
+ audio = librosa.feature.inverse.mel_to_audio(mel_spectrogram)
10
+ return audio
11
 
12
+ # create the gradio app
13
+ app = gr.Interface(mel_to_audio, "image", "audio")
14
+ app.launch()