C# for Programmers, 2/e
 |
ISBN:
0-13-134591-5
© 2006
pages: ~1350
Order
|
This tutorial introduces Microsoft Agenta technology for enhancing Windows applications and Web pages with interactive animated characters that can speak to users and respond to user input via speech synthesis and speech recognition.
[Note: This tutorial (Part 1, Part 2, Part 3, Part 4, Part 5, Part 6, Part 7) is an excerpt (Section 17.14) of Chapter 17, Multimedia and Graphics, from our book C# for Programmers, 2/e. These articles may refer to other chapters or sections of the book that are not included here. Permission Information: Deitel, Harvey M. and Paul J., C# FOR PROGRAMMERS, ©2005, pp.692–706. Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle River, New Jersey.]
Introduction to Microsoft Agent (continued)
Responding to Selections from the
actionsCombo ComboBox
After the
GetAnimationNames method has been called, the user can select a value from the
actionsCombo ComboBox. Event handler
actionsCombo_SelectedIndexChanged (lines 122-128) stops any current animation, then plays the animation that the user selected from the
ComboBox, followed by the
RestPose animation.
Speaking the Text Typed by the User
You can also type text in the
TextBox and click
Speak. This causes event handler
speakButton_Click (line 45-55) to call
speaker method
Speak, supplying as an argument the text in
speechTextBox. If the user clicks
Speak without providing text, the character speaks,
"Please, type the words you want me to speak".
At any point in the program, the user can choose a different character from the
charactersCombo ComboBox. When this happens, the
SelectedIndexChanged event handler for
characterCombo (lines 67-71) executes. The event handler calls method
ChangeCharacter (lines 74-83) with the text in the
characterCombo as an argument. Method
ChangeCharacter stops any current animation, then calls the
Hide method of
speaker (line 77) to remove the current character from view. Line 78 assigns the newly selected character to
speaker, line 81 generates the character's animation names and commands, and line 82 displays the character via a call to method
Show.
Each time a user presses the
Scroll Lock key and speaks into a microphone or selects a command from the
Commands pop-up window, event handler
mainAgent_Command (lines 131-157) is called. This method is passed an argument of type
AxAgentObjects._AgentEvents_CommandEvent, which contains a single property,
userInput. The
userInput property returns an
Object that can be converted to type
AgentObjects.IAgentCtlUserInput. Lines 135-136 assign the
userInput object to an
IAgentCtlUserInput object named
command, which is used to identify the command, so the program can respond appropriately. Lines 139-144 use method
ChangeCharacter to change the current Agent character if the user speaks a character name. Microsoft Agent always will show a character when a user speaks its name; however, by controlling the character change, we can ensure that only one Agent character is displayed at a time. Lines 147-152 move the character to the current mouse location if the user invokes the
MoveToMouse command. Agent method
MoveTo takes
x- and
y-coordinate arguments and moves the character to the specified screen position, applying appropriate movement animations. For all other commands, we
Play the command name as an animation in line 156.
Page 1 | 2 | 3 | 4 | 5 | 6 | 7
Tutorial Index