Thursday, July 03, 2014

Text to Speech from the Command Line On Windows in 6 Lines of Code

Back in the day, compiling a Linux kernel would take hours. To make life easier, I'd kick off the task and have it notify me when it was finished. Something like so:

 make ; notify "Whooo! We're done!"

When I was really feeling fancy, I'd setup notify to invoke an X10 controller, causing a light to blink on and off. That way, I wouldn't have to be in the room to know the task was done.

These days I'm on Windows, the Linux kernel can be (depending on your hardware and configuration) compiled in minutes, and I don't have X10 setup any longer (note to self: why the heck not?!). But, that doesn't mean I don't have long running tasks I need to kick off from the command line.

One possible solution: use a text to speech command to let me know a task is done. It's not as attention getting as flashing a light in another room, but it's still a solid form of notification. Looking around, it didn't appear as though there was a standard command line tool on Windows for doing text to speech. So, using this AutoHotKey example, I wrote my own.

;;
;; Simple text to speech command line tool. Inspired by:
;; http://www.autohotkey.com/board/topic/77686-text-to-speech-examples-for-autohotkey-v11/
;;
;; Usage: speak.ahk [words ...]
;;
engine := ComObjCreate("SAPI.SpVoice")

buffer := ""

Loop %0%
{
  word := %A_Index%
  buffer := buffer . " " . word
}

engine.Speak(buffer)

Now I can say:

  make ; speak "Compilation is finished."

and my computer will announce when the make command is done.

I'm telling you, AutoHotKey never ceases to amaze.

4 comments:

  1. Maybe you should just send yourself a text message when the build is complete.

    ReplyDelete
  2. > Maybe you should just send yourself a text message when the build is complete.

    That would work too. I wonder what the most efficient way to do that from the command line is?

    Another option which I'll almost certainly play with is to use: Auto Remote (https://play.google.com/store/apps/details?id=com.joaomgcd.autoremote) which allows you to make URL requests and have them invoke Tasker.

    From there, I can get my phone to vibrate, alarm or do anything else I want at the end of a build.

    ReplyDelete
  3. Greg H5:58 PM

    Google voice has libs to access their texting with perl / python. Not too hard to figure out.

    ReplyDelete
  4. Thanks Greg - I'll have to take a peek.

    ReplyDelete

LinkWithin

Related Posts with Thumbnails