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

Thats 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, its ALSA. I dont know how many attempts I have tried to get the final output of sound system. I always failed to do so since ALSA doesnt 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 cant 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 its cross-platform. If it worked, at least my script might also work on Mac. With a little tweak, it would work on Windows.

And thats the moment I recalled, I cant get the system output. However, I still finished to show a volume meter. I wont do more for spectrum because I dont 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 dont want to use physical wire to loop back. Unfortunately, I dont 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 cant 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 wont be process twice.

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

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

Sorry, my dearest terminal, you wont have sweet eye-candy to show off.