nakas commited on
Commit
027cd67
1 Parent(s): abca20d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -2,14 +2,17 @@ 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
  # specify the data type of the output array to avoid the same_kind casting error
10
- mel_spectrogram = librosa.feature.melspectrogram(audio, dtype=np.float64)
11
- return mel_spectrogram
12
 
13
  # create the gradio app
14
- app = gr.Interface(audio_to_mel, "audio", "image")
15
  app.launch()
 
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 a grayscale image to avoid the string indices must be integers error
9
+ mel_spectrogram = np.mean(mel_spectrogram, axis=0)
10
+
11
+ # convert the Mel spectrogram image to audio using librosa
12
  # specify the data type of the output array to avoid the same_kind casting error
13
+ audio = librosa.feature.inverse.mel_to_audio(mel_spectrogram, dtype=np.float64)
14
+ return audio
15
 
16
  # create the gradio app
17
+ app = gr.Interface(mel_to_audio, "image", "audio")
18
  app.launch()