WIDBA - The busiest DBA in Wisconsin, its all I do and I do it well

Thursday, September 22, 2011

Quoting Star Wars out loud on your PC (with Powershell)

I came across this great blog post at beefycode.com called "stupid Powershell tricks" and one trick is using Powershell and the text to speech COM object to have it translate text to voice.  The author used it for a much more interesting application than I have thus far, but this was too much fun.  My kids love Star Wars so I thought I would whip up a quick randomizer in Powershell to say various sayings from the movie.

  $voice = New-Object -ComObject SAPI.SPVoice
  $voice.Rate = -4
  function invoke-speech
      param([Parameter(ValueFromPipeline=$true)][string] $say )
         $voice.Speak($say) | out-null;   
 if(!(Test-Path alias:\out-voice)){
     new-alias -name out-voice -value invoke-speech;

[array]$quotes = @("I find your lack of faith disturbing"
    ,"Use the Force, Luke"
    ,"You don’t need to see his identification … These aren’t the droids you’re looking for … He can go about his business … Move along."
    ,"Help me Obi-Wan Kenobi. You’re my only hope"
    ,"May the Force be with you"
    ,"When I left you, I was but the learner, now I am the master"
    ,"Only a master of evil, Darth")

$random = New-Object  System.Random

$quotes[$random.next(0,$quotes.Length)] | out-voice

No comments:

Post a Comment