QTP Karaoke – Teaching QTP to Speak

PerfectoTopAd

Microsoft Speech API

I just found a Microsoft API that allows you to create QTP scripts with voice feedback. The speech API gives you the ability to use speech recognition and speech synthesis within your QTP scripts.

What you need to get started

Not sure how many actual business scripting uses you would actually need this for, but it’s cool to know it can be done. Here’s what you need to get started:

First, create an instance of the SAPI.SpVoice

Set voice = CreateObject(“SAPI.SpVoice”)

Next, use the Speak method to start the speaking of the text string.

Voice.Speak “Joe Colantonio Dot Com”

  • You can control other things like Volume (level of the voice) and Rate (how slow or fast you want the speaking rate to be). For the all the methods available take a look at:

http://msdn.microsoft.com/en-us/library/ms723615%28v=VS.85%29.aspx

Teaching QTP to “Sing”

Isn’t that cool!?! You can even read from a text file — which can create some interesting results, like having QTP read the text of this blog post, read the lyrics to your favorite song or quote lines from your favorite movie. Just be cautious if it asks, “Shall we play a game?” It wouldn’t be smart to answer, “How about Global Thermal Nuclear War?” (Those of you who’ve seen the movie War Games will get the reference…)

Code used to read from a text file for the video for this post:

Set voice = CreateObject(“SAPI.SpVoice”)

Set oFso = CreateObject(“Scripting.FileSystemObject”)

intReadWriteAppend = 1

Set strFileName = oFso.OpenTextFile(“C:\blogpost.txt”, 1, false)

      DO while strFileName.AtEndOfStream = false

             strFileLine = strFileName.Readline

             fVoice.Speak strFileLine

      LOOP

strFileName.Close

2 comments
sanjiv - August 12, 2013

Hi,
Is there any way to Get Text for any Speech (Voice)??
Please let me know, if have??
Just the reverse u explained??

Thanks in Advance,
Sanjiv

Reply
    Joe Colantonio - August 13, 2013

    Hmm that is a good question – I don’t know. You could have QTP call some speech to text program and write to a file. Anyone else have any suggestions for sanjiv.

    Reply
Click here to add a comment

Leave a comment: