A little evening programming project…

February 4, 2010 | Amateur Radio | By: Mark VandeWettering

Well, there wasn’t anything terrific on TV tonight, and I’ve had a little program kicking around in my head for a while, so I decided to set down and see if I could make some headway on it in a single evening of programming.

I used to have some Morse code practice cassette tapes a while ago. It used the Koch method, and was progressive. They began with just two letters, say K and M that were sent using Koch spacing (the space between letters were sent as if they were 5wpm, but the letters themselves were sent at 13wpm.) The tapes themselves were thus the combination of regular speech (giving you instructions) and Morse code. But I can’t find the tapes anymore, and even if I did have the tapes, I don’t have a cassette player, so they wouldn’t be of any immediate use. I went to HRO to see if they had any such thing on CD so that I could listen to them in my car, but ironically, the bottom seems to have fallen out of the Morse Code CD market, and they didn’t have any in stock.

So, I thought to myself, what would it take to make my own?

I’ve written programs to generate Morse code before. And most of the computers I use have some kind of speech synthesis capability (either the “say” command on Mac OS, or the festival speech synthesizer on Linux) so generating some reasonable if not exactly pleasing speech wouldn’t be that hard.

So, I tossed together a simple scripting language to wire the two together. It takes a simple script which consists of text which it translates directly into Morse code. The exception is any text which appears in double quotes. It gathers that text up, and passes it to the system speech synthesizer, and generates a sound file, which it then reopens, resamples to the same output rate as the rest of the morse code, and then returns to Morse mode. This isn’t all that hard because of the excellent libsndfile and libsamplerate libraries. There is some work left to be done, but the basics work. Here is the contents of a simple test script that I wrote:


"This is a test of the emergency broadcast system."
If this had been an actual emergency,
you would not have been using Morse code.

And here is the resulting .mp3 file, synthesized on my Macbook:

Morse synthesized by my “mscript” program (MP3)

The basics all work, but there are some additions to be made, to insert arbitrary wav files perhaps, to adjust timing, to implement Koch spacing and flexibility in changing the speed of Morse code inside a single document, and just other bits of cleanliness. Oh, and the Morse doesn’t have any shaping at all, so the transitions are a bit clicky. I can fix that pretty easily. Still, not bad for a couple of hours of tinkering with C, yacc, and lex.