Skip to main content

Clock chime

Project | Article by Maarten Tromp | Published , updated | 345 words

Some years ago, I lived very close to a clock tower. What surprised me was that I hardly noticed it toll, but always had a sense of what time it was. Now that I have moved house, I would like to replicate that feeling. Since we don't have a clock tower nearby, I decided to do the next best thing and write a simple script that plays some striking samples. Like clockwork.

Clock chime code screenshot
Clock chime code screenshot

Since I couldn't find an audio sample of that particular clock tower, I downloaded one from FreeSFX. I cut a shorter version of the sample for the repeated tolling, while the full-length sample is played at the end, with its nice, long sustain.

A small Python script is started every half hour by the cron daemon. It checks the time and plays the corresponding number of strikes. The first version had a bug that made the clock strike 13 times at high noon and midnight, but I decided it was hilarious and left it in. So far, nobody else seems to have noticed. Maybe I'm the only one counting the strikes.

The script runs on our home server, connected to some Trust computer speakers from the previous century. One speaker sits in the cupboard with the server; the other is connected via network cabling to the other side of the house. So wherever you are in the house, chances are you'll hear the clock strike.

Guests are sometimes surprised to hear our clock toll when there isn't a clock tower anywhere to be seen.

This code and article are released into the public domain. You can find the code, samples and cronjob fragment in the downloads directory of this article.

Update

Simpleaudio no longer works with modern versions of Python, so I replaced it with sounddevice and soundfile. While I was at it, I cleaned up the code and changed it so that the same sample is played for both short and long durations, instead of using two different samples. The new and improved version is available in the downloads directory of this article.