gradio/demo/spectogram/run.ipynb
Archit-Kohli 921716f618
Fixed visibility issue for all notebooks on GitHub (#5917)
* fixed visibility error in notebooks in github

* Delete fixNotebooks.py

deleted script used to fix notebooks

* Update generate_notebooks.py

fixed a small bug that prevented visibility of notebooks in GitHub
2023-10-15 18:16:57 -07:00

1.1 KiB

Gradio Demo: spectogram

In [ ]:
!pip install -q gradio scipy numpy matplotlib
In [ ]:
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


demo = gr.Interface(spectrogram, "audio", "plot")

if __name__ == "__main__":
    demo.launch()