Audio Out Over UART

There’s a reason that the bog-standard serial port will never die. It’s just so robust and simple. When you need a console that will absolutely work with minimal software and hardware, UART is the way to go. Because of this, UART hacks abound. Here’s a new one to us, and a challenge to our readers.

[Tiziano Bacocco] decided to use UART signals as a type of PWM to create audio. That’s right, he’s plugging the serial TX line straight into a speaker. This gives you eight possible PWM output voltage levels. The trick is using some Python code (using the awesome pyserial module) to down-quantize the audio data to fit these eight possible values and then push them out at the correct sampling rate. ffmpeg is used to pre-process the files.

While it sounds good enough for Mario (see video below), three-bit audio isn’t going to sound great for speech or complicated music. So here’s our challenge: redo this with DPCM. Instead of sending the voltage levels, you send the required voltage changes over the serial line. Since voice and music sound waves are continuous (in the mathematical sense), this can work out pretty well even with just a few cleverly selected bits of output.

Here’s a tutorial to get you started. You’ll need to integrate the output (think RC filter), and you’ll want to run it into an amplifier, but we bet it can output decent speech. And we bet it can be done in a few lines of Python. Post your solution in the comments below.

Still, [Tiziano]’s hack is fantastic. We love the simplicity of just plugging the serial out straight into an amplifier! That’s hard core.

Filed under: peripherals hacks