Microsoft Agent Tutorial Chapter 2

xiaoxiao2021-03-06  54

Part 1 - Adding agent commands

To get the Agent to respond to userinput you will need to add commands.? Commands are a word or series of words the Agent waits for. Once one of the commands is spoken the agent will call the Commands () Event and return the name of The Command That Was SpokeN.

Name your agent control msagent. Add this to the form_load () Event: Msagent.Characters.Load "defaultcharacter"

Set agentchar = msagent.characters ("defaultcharacter") agentchar.commands.add "notepad", "NOTEPAD", "NOTEPAD", TRUE, TRUE

Private sub msagent_command (Byval UserInput As Object)

Msgbox userinput.name

End Sub

There, now try running it. Press SCROLLLOCK and then say your agents name to get him to appear. Once the agent has appeared press SCROLLLOCK again to get the agent to listen and then say the word "Notepad". A msgbox should appear with the Word Notepad in It, Since That Is The Name We Gave Our Command.

The first parameter listed above is the name that is what the Command () Event will return to you when your command is spoken. The next is the Caption parameter, which will determine how this command is displayed in the Agent Voice Commands Window. The third Is The Voice Property. The Voice Property Is What THE User Must Say To Evoke This Command. The Voice Property Does Not Have to Be The Same as The name or the caption.

Now Take a Look At this line of cotne:

Agentchar.commands.add "NOTEPAD", "Notepad", "[...] Notepad [...], True, True

Notice the ellipses in brackets? These have a special meaning to the Text to speech engine. These basically mean to ignore any speech before and after the word notepad. So you could say something like this "Open notepad please" and it will still return the "NOTEPAD" Command.? Be Careful When Using The Ellipses Though, Since They Slow Down Processing ConsideRably.?

Part 2 - IT's All GuessWork!

When a command is spoken the Agent takes its best guess and then returns you a command The command may not always be correct, since the Agent is really just making a guess Imagine this scenario:.. You have the agent setup to delete a database entry when the user speaks a specific command. Now you would want to ensure that MSAgent is fairly confident in the command before you wipe out valuable data. Thankfully MSAgent has a property designed to let you know just how certain the agent is about a command.

The UserInput Object Has A Confidence Property Designed Just for this purpose; The confidence property in msagent can range from -100 to 100. TRY THIS:

Private sub msagent_command (Byval UserInput As Object)

IF userinput.confidence> -50 Then

Msgbox userinput.name

Else

Msgbox "I Have" & UserInput.confide & "Confidence In That Command"

END IF

End Sub

Sometimes you want to have different confidence levels for different commands. There is a property for this as well. Each command object can have a confidence level specified and a confidence text specified. If the agents confidence level does not meet or exceed the confidence level you SET THEN The Confidence Text Will Be Displayed In The Agents Tooltip. Try Adding this to the form_load:

AgentChar.commands ("notepad"). Confidence = "50" AgentChar.commands ("notepad"). Confident = "WAS That notepad you wanted?"

Notice that when the agents confidence level is below 50 it will display the ConfidenceText in the tooltip. But you should also notice that the agent will still proceed with the command and show the msgbox. To avoid that you would need to add code to check the UserInput Confidence Setting and the command confidence setting to seeing. Something Like this:

IF userinput.confidence> agentchar.commands (userinput.name) .confidetence the

Msgbox userinput.name

END IF

There is also other parameters to let you know what other commands the agent considered when guessing. You can get the name of the second best match using the UserInput.Alt1Name, and the third best match using the UserInput.Alt2Name properties. Each of these have .

Sometimes the agent will get a built in command like "Show" or "Hide". In this case no Command names are returned. So to determine if any command names are returned the best way is to check the Userinput.Count property. This will Tell youness, 2 or 3 guest. if the thing returned from the agent. if the thing. if................

转载请注明原文地址:https://www.9cbs.com/read-118169.html

New Post(0)