File size: 781 Bytes
a8daa4b
b9442ae
c065b14
87d610a
b9442ae
027cd67
6437819
027cd67
 
 
 
abca20d
027cd67
b5b432f
 
d6d39f0
fcecdda
daab81b
b5b432f
7fdcdff
b90c087
027cd67
b90c087
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
import numpy as np
import librosa
from scipy.io.wavfile import write

# import the librosa library for converting a Mel spectrogram image to audio

def mel_to_audio(mel_spectrogram):
  # convert the Mel spectrogram image to a grayscale image to avoid the string indices must be integers error

  # convert the Mel spectrogram image to audio using librosa
  # specify the data type of the output array to avoid the same_kind casting error
  audio = librosa.feature.inverse.mel_to_audio(mel_spectrogram, dtype=np.float64)
  # Save the audio to a file
  output = 'output.wav'
  sample = 44100
  print (output)
  write(output, sample, audio.astype(np.float64))
  return output

# create the gradio app
app = gr.Interface(mel_to_audio, "image", "audio")
app.launch()