Thursday, March 5, 2009

Working with Microsoft Speech API (SAPI)

SAPI or Speech Application Programming Interface is provided by Microsoft for converting text-to-speech and speech recognition.

Isn't it fun to have your own application which would read out text to you? Here is the sample vbscript code:

Dim name, sapi, reply
name = InputBox("Please enter your name","I would like to talk to you!")
Set sapi = CreateObject("sapi.spvoice")
Set sapi.Voice = sapi.GetVoices().Item(1)
reply = "Hello" & name
sapi.Speak reply
sapi.Speak "How are you doing?"

Save this code as "test.vbs" for example and run it. Enter your name in the prompt and enjoy the computer speaking to you :)

Explaining the code:
Line No.2 prompts the user to enter name. The name entered by user is saved in variable "name".
Line No.3 creates the sapi object for manipulation
Line No.4 selects the voice available in the system
Line No.5 adds Hello to the name
Line No.6 and 7 speaks out the string to the user

For more information on SAPI, Microsoft Speech API 5.3

No comments: