Real-time audio spectrum analyser


Hi, I would like to build a spectrum analyser with Scroll pHAT and pHAT DAC just like the tutorial in Pimoroni ( However, I want to analyse real time audio from a speech synthesis program (flite) on my Raspberry Pi Zero, instead of a wav file. What should I do to accomplish this in terms of the coding? Based on the tutorial, is the code below where I might have to modify?

sample_rate = wavfile.getframerate()
no_channels = wavfile.getnchannels()
chunk = 4096

output = aa.PCM(aa.PCM_PLAYBACK, aa.PCM_NORMAL)

I appreciate any advice on how I can go about working on this. Thanks!


There is, as far as I know, no way to modify this example to function in real-time. Short of capturing the output of your speech synthesis program to wav, and then generating a spectrum analysis from that.

Pi VU Meter was created to solve this problem, though:

git clone
cd pivumeter
./ scroll-phat

After running this, anything you play to default or pivumeter via ALSA should generate a spectrum analyser on Scroll pHAT.


Thanks for your reply. And if say, I wanted to use my TouchPhat instead, whereby ‘Back’, ‘A’, ‘B’, ‘C’, ‘D’, ‘Enter’ LED buttons would light up in response to the presence of certain frequencies (no need for amplitude magnitude display), would that be feasible as well? I note that pivumeter supports only several add-on devices.


The newer- still in development- version of Pi VU Meter has support for anything that has a Python library.

See the examples here:

To installer the newer version you would change your clone to:

git clone -b devel