2020-08-22 05:20:05 +08:00
|
|
|
# Demo: (Audio) -> (Image)
|
|
|
|
|
2020-08-20 19:57:07 +08:00
|
|
|
import gradio as gr
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import numpy as np
|
|
|
|
from scipy import signal
|
|
|
|
from scipy.io import wavfile
|
|
|
|
|
|
|
|
|
2020-08-22 05:20:05 +08:00
|
|
|
def spectrogram(audio):
|
2020-08-20 19:57:07 +08:00
|
|
|
sr, data = audio
|
|
|
|
data = np.delete(data, 1, 1).reshape(-1)
|
2020-08-22 05:20:05 +08:00
|
|
|
frequencies, times, spectrogram_data = signal.spectrogram(data.reshape(-1), sr, window="hamming")
|
|
|
|
plt.pcolormesh(times, frequencies, np.log10(spectrogram_data))
|
2020-08-20 19:57:07 +08:00
|
|
|
return plt
|
|
|
|
|
|
|
|
|
2020-08-22 05:20:05 +08:00
|
|
|
gr.Interface(spectrogram, "audio", "plot").launch()
|