Friday, August 1, 2008

Fun with PowerShell and the Speech API

I don't know why, but listening to a computer-generated voice reading things you type is just a lot of fun, and the potential for annoying your friends, neighbors, pets, and co-workers is endless.  Personally I blame my parents for buying me a Speak 'n' Spell when I was a kid.

Anyway, to that end, I present the following little ditty, a function I like to call Speak-String (which I usually alias to "say"), inspired by a few posts using the same trick that I've come across on the Internet.

function Speak-String([string]$message) {
  $speaker = new-object -com SAPI.SpVoice
  $speaker.Speak($message, 1)

Set-Alias say 'Speak-String'

PS C:\> Say "Would you like to play a game?"
PS C:\> Say "How about Global Thermonuclear War?"

No comments: