Real-time Spectrogram#
import IPython.display as ipd
from mirdotcom import mirdotcom
mirdotcom.init()
ipd.YouTubeVideo("ydu12NfZd90", width=600, height=360)
Here is how you can create a real-time spectrogram in your terminal using PyAudio.
To see the example in action, run the script in this repo, realtime_spectrogram.py:
python3 realtime_spectrogram.py
The basic idea is simple. For every new audio buffer,
Take an FFT,
x_fft, of the audio buffer.Compute a
melspectrumfrom thex_fft.Print a string,
s, wheres[i]is'*'wherevermelspectrum[i]is above a threshold.
From here, you can manipulate this basic example to do more sophisticated real-time processing, e.g. involving machine learning models.