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
|
|
|
|
|
|
|
|
|
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-29 00:05:19 +08:00
|
|
|
io = gr.Interface(spectrogram, "audio", "plot
|
2020-08-28 23:56:03 +08:00
|
|
|
|
|
|
|
io.test_launch()
|
|
|
|
io.launch()
|