I wrote a script cap-vol-meter.py, which display sound level of default capture device (microphone). Here is a video.

That’s all for the script, you can read more how to use it in that page or use -h option.

1   Original idea

I was planning to show the current sound system output, in my case, it’s ALSA. I don’t know how many attempts I have tried to get the final output of sound system. I always failed to do so since ALSA doesn’t seem to give you that data.

I wanted to show the spectrum of current output. At first, I tried to show the sound level using PyAudio. Just like getting system out, I can’t get any via PyAudio. There is nothing returns. So, I switched to pyalsaaudio, which I have used before. I want to use PyAudio at first place because it’s cross-platform. If it worked, at least my script might also work on Mac. With a little tweak, it would work on Windows.

And that’s the moment I recalled, I can’t get the system output. However, I still finished to show a volume meter. I won’t do more for spectrum because I don’t do recording. I just want to have a terminal screensaver.

Anyway, I did so little research. I found this nice page about how to use Capture device to get system output. In its Record playing sound, I know there is no chance for my device. I don’t want to use physical wire to loop back. Unfortunately, I don’t have Mix. But I have Mux, which does loop back the sound, but the quality is really awful and the sound level is very low.

As for the ALSA file plugin, I had hope for it. But I can’t get it work, the output file never gets created. I need to do more research on asoundrc. I was thinking to write a listener which utilizes the support of pipe, let file pipe output to my listener program, then this program will will write a number of samples to a file, it overwrites every time. So whatever program needs the output, it just open and read those samples, then re-open and read again. Of course, there will be a number prefix before those samples, so same content won’t be process twice.

However, file is output per application, when a process opens a playback, ALSA creates the file. Therefore, it’s not truly the final output. In Audacity’s wiki, there is a section explains how to create files for each process.

I don’t know if other popular sound systems gives you the final output data. If they do, it’s no use for me, because I don’t know to install and configure for another. ALSA only fails me for this final output.

Sorry, my dearest terminal, you won’t have sweet eye-candy to show off.