Category: python

I got interested in seeing how do the spectral distribution of everyday sounds look like. So I got an app in my phone (Smart Recorder) and started recording them. The most interesting result (until now) is from the simplest sound I have recorded: a bottle of milk being filled at my kitchen’s tap. I present the audio, associated spectrogram and the theoretical analysis in this post. All the work is performed in Python, from reading the data to plotting.

Audio recording

As it sounds, it is just a bottle being filled with water. At the beginning (\(t\) < 1 second) there is nothing, until I open the tap. After about 32 seconds, the bottle is full and water is overflowing to the sink. There is a constant component lied to the impact of the particles on the bottom of the bottle/water column. Besides that, an indistinguishable and interesting tone that is changing in time can be heard. This sound is a resonance of air column with a closed-end (that is actually the water) and an open-end:

Change of resonance frequency with the air column height.

There is an increase of the frequency with the reduction of the wavelength \(\lambda\), that is linear in time until around 20 seconds. After that the increase is not constant due to the non linear modification of the available space for the air inside the bottle originated from the reduction of the diameter with the height.

So, in a month from now I’m going to participate at the 3 Minute Thesis contest at my university. As one can deduct by its name, the whole idea is presenting your PhD subject in only 3 minutes.

For practicing, I created a simple countdown video using Python, obviously it goes from 180 to 0. For that, I had to install FFMpeg so I could save in a different format than the HTML provided by the matplotlib’s Animation module when you have no real video writer available. The simplest way was just using the conda environment (the one I use for my Python coding):

conda install -c menpo ffmpeg

The idea is just make one frame per second, so FPS = 1, where each one of them is a centered text with the correspoding time, no axis. The bitrate could be reduced, to make a smaller video. As it’s just a simple countdown, there is not any major losses in the quality with a bitrate of 80 (but reduced from 2.44 MB to 1.82 MB). So the writer options were:

Using the default codec, it was running fine with the VLC player. Just to make it more general for sharing with my colleagues, I tried with Windows Media Player, and it was quite awful. So I just picked the MPEG-4 codec (as you can see in the previous extrait of the program), from the list of available codecs that you can see by typing in your terminal:

ffmpeg -codecs

A good improvement would be adding a bip when you reach 0 or something close to that. For the moment, the text color just changes to red.
You can check the complete script here: simple_countdown.py

If you got in here because you are also practicing for something similar, I hope this scripts helps you and wish you good luck. Once I do my presentation, I’ll problably put the video here, so stay tuned!