TTS for Incoming Email

Ding! New email. But what is it? Who's it from? What's it about? Is it worth getting up for? This article describes how to use tools to give different kinds of email a distinct audio signature. Think of it as talking caller ID for your email.


I assume that you:

  • Receive your mail on a UNIX system, and you have shell access on that system (or a way to set up a .procmailrc that will run on it);
  • Know, or can figure out, a little bit about procmail;
  • Know, or can figure out, a little bit about ssh port forwarding
  • Your UNIX server has the following software installed:
    • esdplay. This is a tool used for sending sounds to a remote system.
    • festival. This is a Text-to-Speech (TTS) engine.


The setup is simple: your email arrives on one box, but you're sitting at another:

          +-------------+             +---------------------+
          | UNIX server |             | Your Desktop/Laptop |
          +-------------+             +---------------------+

When new mail comes into your server, you want your system to announce it:

          +-------------+             +---------------------+
  mail--->| UNIX server |---[sound]-->| Your Desktop/Laptop |
          +-------------+             +---------------------+

The way I accomplish this is by using ESD, the Enlightenment Sound Daemon, also called esound. ESD is a daemon that runs on your desktop system, listening. A process can run on the UNIX system, connect to your ESD daemon, and feed it a sound to play.


ESD Daemon (on your Desktop)

ESD is available for all UNIXes; check your distribution for details. There's also a binary built for Windows and for Mac OS X. Get it, and start it up. One typical way to run it is:

$ esd -nobeeps -tcp -promiscuous

Now you're running the daemon... but that's on your desktop. The remote server has no way of knowing how to reach it. We fix that using ssh port forwarding.


I must assume that you have a way of ssh'ing into your UNIX mail server. Do so, but with this addition:

$ ssh -R 12345:localhost:16001 your.unix.server

(You can change the 12345, and may need to if that port is in use on your UNIX server.) What this does is tell your UNIX server that it can connect to port 12345 on itself, and that will actually be connecting (via tunnel) to your desktop system.

Test It

You should now be able to run a command on your UNIX server, and have a sound play on your desktop. Find a .wav file on your UNIX system (e.g. in /usr/share/sounds), or download this one. (Again, you want this .wav file on your UNIX server). Try playing it:

$ esdplay -s localhost:12345 Woody-Woodpecker.wav

(esdplay is pretty much standard on Linux distros. If your UNIX server doesn't have it, you may need to grab the source and compile it. That is beyond the scope of this document.) You should hear soothing, mellow tones on your speaker. If you don't, um, call or write Ed. No point in continuing unless you've got sound working.

Announcing Mail

This part of the process involves identifying incoming email and playing a suitable sound. You now know how to do the latter. The former is done with procmail.

# BEGIN: Anything sent directly to me

* ^TO(santiago|esm)@(||
    :0 ch
    | mail-announce

    :0 w: .incoming.lock

That is: any message sent to me, but not by a daemon process (that is, no bounces or cron mails), gets a copy piped, headers only, to the mail-announce script.

To be continued...