Do you remember the MsAgent? These small characters which help and guide you in Microsoft office applications?
The MsAgent get several other capabilities like vocal commands, and from this point they seem to be very useful in attractive and interactive ways.
In a speech enabled application they could make the scene as a bridge between the user and the computer : you tell it something and it makes the computer reacts to the thing you said.
The MsAgent is in fact a powerful character full of essential capacities to interact with the user.
So let's get a look on how to make a MsAgent react to your voice, and compare it to the previous components integrated in the Microsoft Speech Sdk.
Speech recognition permit you to associate one or many words to a command : when one word is recognized, an event will be generated.
In a first time you will have to declare the different references which correspond to the implementation of the MsAgent and declare the objects AxAgent
private AxAgentObjects.AxAgent agent;
private IAgentCtlCharacterEx myCharacter;
After that is done, you just have to initialize your agent by this way :
agent = new AxAgentObjects.AxAgent();
myCharacter = agent.Characters["Peedy"];
You see that you have to begin the initialization of the agent : it is just to add the Agent control to your form or to the object you want the MsAgent to interact with.
Then, You have to load a character, the one you have installed giving its path, and giving it a name.Let's now see how to create some commands for the MsAgent.
In this section we will see the way to create a entire command which will be able to be recognize by the MsAgent with an event.
This example is a creation of a command for a menu :
myCharacter.Commands.Caption = "Test";
myCharacter.Commands.Add("Say Hello", // Command name
(object)"Hello", // Display name
(object)"Hello", // SR Name
(object)true, // Enabled
(object)true); // Visible
To add a command, you just have to define a caption, for example here "Test"
, and then you will have to define the caracteristics of the command.
You add a command by giving it a name, the display name in the agent configuration, the word that the agent will react to, and finally options to activate it and enable it.
Now you just have created your first command, let's see how to make it recognized.
Finally, don't forget to enable the listening on your character :
The implementation is carried out by factual method called OnCommand
. Now let's see how does it work:
private void OnCommand(object sender, AxAgentObjects._AgentEvents_CommandEvent e)
ui = (IAgentCtlUserInput)e.userInput;
if (ui.Name.Equals("Say Hello"))
We take the user input with the object IagentCtlUserInput and we are able to get the command name you have implemented above.
You can create whatever you want in the if
, in this example we have make the agent speak.
This tutorial was originally written by SatanicPunker
Published by BunoCS
Latest update on September 24, 2013 at 04:10 AM by BunoCS.