Processing Spoken Commands

The real guts of this program are contained in the Command event, as shown in Listing 14.6. The UserInput object contains the name of the command that the speech recognition engine determines is the best match, so in this routine, I process each of the individual commands.

Listing 14.6: Agent1_Command Event in Agent Demo

Private Sub Agent1_Command(ByVal UserInput As Object)
Select Case LCase(UserInput.Name)
   
Case “bye bye”
   MyAgent.Speak “Bye bye”
   MyAgent.Play “Wave”
   Set MyRequest = MyAgent.Hide
   
Case “down”
   MyAgent.GestureAt MyAgent.Left, Screen.Height / Screen.TwipsPerPixelY
   MyAgent.Speak “All fall down.”
   
Case “happy”
   MyAgent.Play “Pleased”
   MyAgent.Speak “I’m happy.”
Case “hello”
   MyAgent.Speak “Hello Merlin.”
   MyAgent.Play “DoMagic1”
   MyAgent.Speak “Abracadabra, hocus pocus.”
   MyAgent.Play “DoMagic2”
   MyAgent.Speak “Visual Basic now can” & \Map=””spoke ith””=””spoketh””\.”
      
Case “left”
   MyAgent.GestureAt 0, MyAgent.Height
   MyAgent.Speak “Left is that away.”
   
Case “move”
   MyAgent.MoveTo Screen.Width / Screen.TwipsPerPixelX * Rnd, _
                  Screen.Height / Screen.TwipsPerPixelY * Rnd
   MyAgent.Speak “I like flying.”
   
Case “right”
   MyAgent.GestureAt Screen.Width / Screen.TwipsPerPixelX, MyAgent.Height
   MyAgent.Speak “Keep to the right.”
Case “sad”
   MyAgent.Play “Sad”
   MyAgent.Speak “I’m sad.”
Case “up”
   MyAgent.GestureAt MyAgent.Left, 0
   MyAgent.Speak “The sky is falling.”
Case Else
   MyAgent.Speak “I didn’t understand you.”
   MyAgent.Play “Confused”
End Select
End Sub

The processing for the “happy” command is typical of most of the commands I handle in this routine. The “happy” command tells the Agent server to play the “Pleased” animation and then speak the words “I’m happy.”

My favorite is the “hello” command. In this command, Merlin speaks three different times with an animation played in between each bit of speech. This activity takes a fair amount of time and can be entertaining. Note that in the second speech, the text includes a speech output tag. The \Map= tag allows the character to speak one thing and show something else in the character’s balloon.

The “move” command simply invokes the animation that moves the character from one place on the screen to another random location. Note that I had to convert the twips value to pixels for this method to work properly.

The “up” command (and the “down”, “left”, and “right” commands for that matter) directs the character to point at a location on the screen and speak a phrase.

If I can’t find a match of any of these commands, I will play the “Confused” animation and let the user know that the character didn’t understand what was said.

TIP: Play Misty for me: There are a large number of animations available for each character (for example, the Merlin character includes more than 100 different animations). See the documentation included with the Microsoft Agent software for more details about the animations available for each character.

© 1998 SYBEX Inc. All rights reserved.