Skip to Content

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>

To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

  1. Gregor Wolf
    Hello Craig,

    I’ve tried imedeately the functionality. Unfortenately it runs only on an XP Client. My colleagues with Windows 2000 had no luck. Is there a link for a Plugin?

    Regards
    Gregor

    (0) 
    1. Craig Cmehil
      The best option I’ve found for the Win2k systems is at the link http://www.microsoft.com/speech there you can get the necessary stuff for the client.

      We’ve been having a bit of fun with this at work at the moment. Our alerts now are read to us instead of us reading them, this way we can continue working and only listen if something comes up.

      Although not the original purpose of the technology quite a nice “side effect”.

      (0) 
    1. Craig Cmehil
      Not sure if it’s browser settings or not the SayIt( text ) function takes text as the input parameter so for the textarea you can use

      text1.value
      [form name].text1.value

      Where form name is what you defined in the

      (0) 
      1. Craig Cmehil
        Sorry, you have to define a FORM tag on the page and then you can access the form field values. My example above is just the meat of the page between the form tag.
        (0) 
        1. Matthias Kasig

          foolish me – right, i forgot an id in my <htmlb:form>-tag – i am used to straight html. in the context of htmlb it’s not always easy to see, when to use what, and what is really necessary…<br/>thanx again, everything’s fine now,<br/>matthias

          (0) 

Leave a Reply