mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-21 02:19:59 +08:00
21 lines
478 B
Python
21 lines
478 B
Python
# Demo: (Audio) -> (Image)
|
|
|
|
import gradio as gr
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
from scipy import signal
|
|
|
|
|
|
def spectrogram(audio):
|
|
sr, data = audio
|
|
data = np.delete(data, 1, 1).reshape(-1)
|
|
frequencies, times, spectrogram_data = signal.spectrogram(data.reshape(-1), sr, window="hamming")
|
|
plt.pcolormesh(times, frequencies, np.log10(spectrogram_data))
|
|
return plt
|
|
|
|
|
|
io = gr.Interface(spectrogram, "audio", "plot
|
|
|
|
io.test_launch()
|
|
io.launch()
|