Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
craigcmehil
Community Manager
Community Manager
0 Kudos

Recently I began to experiment with "Text to Speech" and "Speech to Text" technology. So if anyone has an interest or a need then this should prove interesting to you.



This is aimed at those running in a Windows environment and I have only tested this in such an environment.



To get started you will need to download the Microsoft Speech Development Kit, in fact I believe the newest version contains an example for this very topic.



Downloads available:


Microsoft Speech Application Software Development Kit (SASDK) Version 1.0

Speech SDK 5.1


More Information: Microsoft Speech <br>

<br>

Now these downloads and links are not 100% necessary for you as a developer, what is important is that the appropriate components are available on the client system loading your pages, OK it would be nice if you have them as well in order to test right?<br>

<br>

<br>

Once you've got things setup and in place the creation of your page goes as normal, you simply need to add in a few more items. Now this does require the use of an ActiveX object and therefore I will say this now. Use ActiveX at your own risk!<br>

<br>

With that out of the way here are the pieces you need to add into your page in order to enable them to speak.

<br>

<br>

<textarea rows="10" cols="70">

<SCRIPT LANGUAGE="JavaScript">

// Create the Sapi SpVoice object

var VoiceObj = new ActiveXObject("Sapi.SpVoice");

function SayIt( textId ) {

     // Speak the string in the edit box

     try {

       VoiceObj.Speak( textId, 1 );

     } catch(exception) {

       alert("Speak error");

     }

} // SayIt

function KeepQuiet() {

     // Speak empty string to Stop current speaking. The value "2" for

     // the second parameter corresponds to the SVSFPurgeBeforeSpeak

     // value in the SpeechVoiceSpeakFlags enumerated type.

     VoiceObj.Speak( "", 2 );

}

</SCRIPT>

<SCRIPT FOR="window" EVENT="OnQuit()" LANGUAGE="JavaScript">

     // Now you've created the object so don't

     // forget to gdet rid of it

     delete VoiceObj;

</SCRIPT>

</textarea>

<br>

<br>

Once you have that in place you can now add in your Form Buttons to activate and deactive the speech. As you can see there are 2 functions, they could be combined into one or done in other ways but for simplicity they are split into two here.<br>

<br>

<textarea rows="10" cols="70">

<htmlb:button text="Tell Me" onClientClick="SayIt(text1.value)" />

<htmlb:button text="Quiet Please!" onClientClick="KeepQuiet()" />

</textarea>

<br>

<br>

Now that we have that in there, let's finish up the page and see what we have.<br>

<br>

<textarea rows="10" cols="70">

<%

DATA: lt_example TYPE STRING.

 

lt_example = 'Welcome to Craigs example page'.

%>

<TEXTAREA ID=text1 COLS=50 ROWS=10 WRAP=VIRTUAL>Welcome to Craigs talking example</TEXTAREA>

<br>

<htmlb:button text="Tell Me" onClientClick="SayIt(text1.value)" />

<br>

<TEXTAREA ID=text2 COLS=50 ROWS=10 WRAP=VIRTUAL>Hope you enjoy it</TEXTAREA>

<br>

<htmlb:button text="Tell Me" onClientClick="SayIt(text2.value)" />

<br>

<br>

<br>

<htmlb:button text="Tell Me" onClientClick="SayIt('<%= lt_example %>')" />

<br>

<br>

<htmlb:button text="Quiet Please!" onClientClick="KeepQuiet()" />

</textarea>

<br>

<br>

That should just about cover all of the basics and leave you with a pretty good idea of how to integrate and use this type of technology.<br>

<br>

This series will close with one final weblog within the next week or so.<br>

<br>

<br>

6 Comments