gradio/demo/spectogram/run.py
Ömer Faruk Özdemir cc0cff893f Format The Codebase
- black formatting
- isort formatting
2022-01-21 16:44:12 +03:00

24 lines
516 B
Python

import matplotlib.pyplot as plt
import numpy as np
from scipy import signal
import gradio as gr
def spectrogram(audio):
sr, data = audio
if len(data.shape) == 2:
data = np.mean(data, axis=0)
frequencies, times, spectrogram_data = signal.spectrogram(
data, sr, window="hamming"
)
plt.pcolormesh(times, frequencies, np.log10(spectrogram_data))
return plt
iface = gr.Interface(spectrogram, "audio", "plot")
iface.test_launch()
if __name__ == "__main__":
iface.launch()