Powershell Text-To-Speech and fun with a 4yr old.

August 30th, 2011

I’m not so sure this fits in the “elegant code” theme, but it’s a “fun with code” topic that someone might enjoy. Especially if you have a little one.

My 4yr old is learning how to spell small and simple words like her name, “Mom”, “Dad”, etc, and continuing her exploration with letters on the keyboard. She’s been banging on a keyboard since her early years on babysmash. In fact I came home one day to find my monitor turned 90 degrees and about every possible admin window open in the background because of certain key combinations were not trapped by babysmash. But I digress…

For a while she was typing some text into notepad and asking me what it spelled.

“ajlkjwelsl” –> What’s that spell daddy?

I then thought it would be fun if the computer could give instant feedback about what she typed and in a matter of a minute or so I whipped up this little “game” which we had fun playing for a bit.

function Start-The-Fun()
{
	$voice = new-object -com SAPI.SpVoice;
	
	while($true)
	{
		write-host "->" -NoNewLine;
		$msg = read-host;
		$Voice.Speak( $msg, 1 ) | out-null;
	}
}

Just paste the function above as shown below and run it. Type some text (make sure your computer’s sound is on) and press enter to hear it.

image

I typed some of the usual things we say around the house and my 4yr old wouldn’t stop laughing…

Give it a try with your little ones (or big ones). Even let your non-techie significant other have a go – he/she may have some fun with it.

  • RayMartinsHair

    I have had the same type of household hilarity using google translate with my daughters. ;-)

  • Anonymous

    Alternatively you could hit the ‘voice’ button on http://translate.google.com (w/o translating)

    • Jason

      Nice, I hadn’t noticed that. I took a few sample sentences and compared the voice translation of the google one VS the build in windows 7 voice and the win7 once seemed to pronounce things a little better.

      But thanks for the tip anyway.

  • Anonymous

    This is awesome.

  • PM

    This is really great.  My kids love doing the same thing.  Can’t wait to get home and show them what Dad’s been up to at work.  (Gotta build that strong work ethic)  :-)

  • http://twitter.com/cromwellryan Ryan Cromwell

    That’s great!  Did something similar with my 4 yr old and his friend and they were asking for all kinds of things to be said.  Lots of fun.

  • http://www.kidcomputers.com Kid Computers

    I think the problem is that your pc is indeed 4 YEARS OLD!! you should goto buy a Gaming PC (a real computer) and ditch the kids computer.