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() |