gradio/demo/spectogram.py

21 lines
478 B
Python
Raw Normal View History

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