© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 27 - Phone Book Application Introducing Multimedia Using Microsoft Agent Outline 27.1 Microsoft Agent 27.2 Downloading Microsoft Agent Components 27.3 Test-Driving the Phone Book Application 27.4 Constructing the Phone Book Application 27.5 Wrap-Up
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Objectives In this tutorial, you will learn to: – Download components necessary to run Microsoft Agent. – Enhance Windows applications using multimedia. – Create applications that interact with users. – Use Microsoft Agent in a C# application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Microsoft Agent
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Microsoft Agent Microsoft Agent features: – Speech recognition engine : translates vocal sound input into a language the computer understands – Text-to-speech engine : translates typed words into sounds
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Downloading Microsoft Agent Components You should download and install three files: 1) Peedy.exe from the Microsoft Agent character files link 2) tv_enua.exe from the Microsoft Agent Text-to- speech engines link 3) actcnc.exe from the Microsoft Agent Speech recognition engines link 4) spchapi.exe from the SAPI 4.0 Runtime Support link (required for Windows XP only)
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Downloading Microsoft Agent Components Figure 27.1 Microsoft Web page containing Agent-related downloads. Text-to-speech engines link Character files link Speech-recognition engines link
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Downloading Microsoft Agent Components Figure 27.2 Location for downloading the Microsoft Agent character. Select the Peedy character here
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Phone Book Application Figure 27.3 Phone Book application Form. Run the application – Debug > Start
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Phone Book Application Figure 27.4 Peedy appears after Call Peedy Button is clicked. ComboBox disabled until Peedy arrives
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Phone Book Application Figure 27.5 Peedy in a resting pose.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Phone Book Application Figure 27.6 Selecting a name from the ComboBox. Disabled Call Peedy Button Call Peedy Button is disabled after Peedy appears
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Phone Book Application Figure 27.7 Peedy thinking. Peedy thinks after Howard is selected from the ComboBox
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Phone Book Application Figure 27.8 Peedy communicates Howard’s phone number.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Phone Book Application Figure 27.9 Peedy smiles after speaking phone number.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Phone Book Application Figure Peedy listening for a voice command. Pressing Scroll Lock displays a status box under Peedy Status box
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Phone Book Application Figure Peedy heard voice command.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Phone Book Application Figure Peedy displays requested phone number. Peedy returning number that corresponds to name spoken
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Phone Book Application Figure Context menu window. Commands in pop-up window Right click Peedy to select one of the names shown – Peedy performs same action resulting from selecting a name from the ComboBox
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Figure ACE table for the Phone Book application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Figure Tools menu. To make Microsoft Agent accessible – Windows Forms > Tools > Customize Toolbox… Select Microsoft Agent Control 2.0 from COM Components tab of Customize Toolbox…
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Select CheckBox Figure Customize Toolbox dialog.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Figure Agent Control in the Toolbox. Added Agent Control
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Figure Form format of Phone Book. Agent control added to Form
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Figure Phone Book Form with no functionality.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Figure Rearranging and commenting the new control declaration.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Figure Declaring and creating arrays in Phone Book. Create an Agent character variable List of names in phone book List of phone numbers
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Declaring a counter variable Adding names to the ComboBox Figure Adding items to the ComboBox.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Assigning Peedy to the Agent character variable Loading the Peedy character Figure Loading the Microsoft Agent character.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application The Add method takes five arguments: 1) Command name: enables access to the command from your program 2) string that appears in a context window when the user right clicks Peedy 3) string containing words for which Peedy listens when users speak a command 4) bool that specifies whether the command is enabled 5) bool that specifies whether the command is visible in the Commands context menu
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Figure Adding commands to Peedy’s context menu. Creating commands so that Peedy can recognize names when spoken
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application MoveTo takes three arguments : 1) x-coordinate (type short ) 2)y-coordinate (type short ) 3)Speed (type long, lower number is faster) Convert.ToInt16 converts a value to a short value short data type: like a long data type, but less accurate and uses less memory Cursor.Position stores the current position of the mouse pointer
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Make Peedy fly onto screen Move Peedy Figure Displaying the Microsoft Agent character. Create the Button ’s Click event handler
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Make Peedy waveMake Peedy speak instructions Make Peedy rest Figure Code that defines Microsoft Agent’s actions when Peedy first appears on the screen.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Enable the ComboBox and disable the Call Peedy Button Figure Disable btnCall after Peedy has appeared on the screen. Set the Call Peedy Button ’s Enabled property to false and cboName ’s Enabled property to true while the Agent character is shown.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Figure Event handler objMainAgent_Command defined Retrieve user input Cast operator converts e.userInput to an object of type AgentObjects.IAgentCtlUserInput so that its members can be accessed properly
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Figure Finding the spoken or selected name. Declaring a counter variable Peedy thinks and speaks telephone number, if found The for statement searches the array for the command name.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Figure Event handler cboName_SelectedIndexChanged defined. Declaring a counter variable Peedy thinks and speaks telephone number, if found Event handler executed when the user selects the name from the ComboBox.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Phone Book Application Figure Microsoft Agent HideEvent event handler. Reset application controls When the user selects Hide from Peedy’s context menu – E nable the Call Peedy Button
Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 40 PhoneBook.cs (1 of 9)
Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 41 PhoneBook.cs (2 of 9) Variable to hold Microsoft Agent character
Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 42 PhoneBook.cs (3 of 9)
Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 43 PhoneBook.cs (4 of 9) Loading Peedy Assigning the Peedy character
Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 44 PhoneBook.cs (5 of 9) Adding commands Showing Peedy Moving Peedy
Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 45 PhoneBook.cs (6 of 9) Command event handler Convert user input to type AgentObjcets.IAgentCtlUserIn- put Peedy waves and speaks instructions
Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 46 PhoneBook.cs (7 of 9)
Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 47 PhoneBook.cs (8 of 9) HideEvent event handler
Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 48 PhoneBook.cs (9 of 9)