Click here to play the demo (User need to install Microsoft Internet Explorer Speech Add-in 1.0 to play the demo).
How to play:
- User plays the X's and the computer plays the O's.
- User selects a square by saying the number-name of the square into the mike.
How it works:
This is a multimodal application (a web application that uses speech in conjunction with a graphical interface to interact with the user). In the program, I use three kinds of Speech objects. They are
- When the program opens,
welcomePrompt plays the instructions, using the text-to-speech engine. (The
prompt object is associated with the TTS engine.)
- When the text reading is complete,
askPositionListen turns on the speech recording function. (The
listenprompt object is associated with the speech recognition engine.)
- When a word is recorded and it matches a rule of the grammar, the program will call a function
yourChoice() such as
yourChoice() is an
onClick function such as
onClick = yourChoice().)
The following picture shows how an object prompt is associated with the speech recognition engine:
Using the code
<%@ Register TagPrefix="speech" Namespace="Microsoft.Speech.Web.UI"
Assembly="Microsoft.Speech.Web, Version=1.0.3200.0, Culture=neutral,
<body onload="OnLoad()" xmlns:speech="http://schemas.microsoft.com/speech/WebControls"
First, let's create the rules of the grammar.
Rule 1 - toplevel:
RuleRef and name it
Position as seen above and set its
script tag. Use the example image below.
Rule 2 - position
Add a list and some phrases and name them. The following chart shows the tic-tac-toe script tags. The one...nine represents the name of the squares. Also, select the
Constant and type the name in the "Enter value" text box for each
The code will be automatically generated, and will look like the box below.
We can find the rules for
Position in the code.
toplevel rule uses the
ruleref element to reference the
<item> represents a phrase. Each phrase can only have one word in this grammar.
- The script expression,
$._value= "xx", contained in the tag element, is executed when the speech recognizer follows a path through the grammar and finds the words or phrases that the tag element follows.
<one-of> represents a word list, or dictionary. When a user speaks one of the words in the list, the recognition engine recognizes that word.
<rule id="toplevel" scope="public">
<ruleref uri="#Position" type="application/srgs+xml"/>
<tag>$.Position = $$</tag>
<rule id="Position" scope="public">
<tag>$._value = "one"</tag>
<tag>$._value = "two"</tag>
The second step is to add a
listen element and set its properties like this:
The code will be generated as in the box below.
listen element specifies possible speech inputs and controls the speech recognition processes and results.
Grammar is one of the main elements of the
listen object. In the following,
OnClientReco= "yourChoice" means that if the speech is successfully recorded, the function
yourChoice will be called. The function is the same as
OnClientNoReco= "ListenStart" or
<speech:listen id= "AskPositionListen" runat="server" OnClientSilence=
"ListenStart" OnClientNoReco= "ListenStart"
OnClientReco= "yourChoice" MaxTimeout="15000"
EndSilence= "1000" InitialTimeout= "2000">
For example, once the user speaks a word and it activates the speech recognition engine,
yourChoice will be called. The code:
event.srcElement.recoResult.selectSingleNode("Position"); will return the value of the word.
var theNode = event.srcElement.recoResult.selectSingleNode("Position");
chName = theNode.text;
document.images[chName].src = "x.jpg";
Now, add the
prompt and set its properties:
<speech:Prompt id="welcomePrompt" runat= "server">
Welcome to Speech Tic-Tac-Toe! You play as theX's and the computer is the O's.
Select the square you want to put your X into by saying them.Good Luck!
The following shows how to use the
Users need to install Microsoft Internet Explorer Speech Add-in 1.0 in their computer in order to play the game.
Developers need to install Microsoft Speech Application SDK v1.0 Beta 3 in order to use the speech objects.