Microsoft Agent Tutorial Chapter 2

原创 2004年09月10日 23:10:00
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 code:

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. Confidence properties 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.Confidence & " 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").ConfidenceText = "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 see if the latter is met or exceeded. Something like this:

If UserInput.Confidence > AgentChar.Commands(UserInput.Name).Confidence Then
	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 their own confidence scoring (Alt1Confidence, and Alt2Confidence). I guess one use for this would be to query the user showing all three choices and get the user to clarify the choice.

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 you if 1, 2 or 3 guesses were returned from the agent. If only two are returned then the Alt2Name property will be empty so there will be no use checking it.

Microsoft Agent Tutorial Chapter 1

Part 1 - Loading the Microsoft Agent ControlThe easiest way to load the agent control is to select i...
  • wm_ni
  • wm_ni
  • 2004-09-10 23:08:00
  • 749

Microsoft Agent 应用心得

最近项目中想实现一个能够实时提示用户、引导用户操作,并进行操作说明的帮助系统,当然通过winform中的help体制是可以实现的,但是不够友好,响应也不够及时。于是考虑使用msagent来实现。msa...
  • luyifeiniu
  • luyifeiniu
  • 2010-06-04 10:19:00
  • 5429

Microsoft Agent范例程序,你的系统中必须已经安装了Agent2.0以

  • 2006年02月23日 09:05
  • 1KB
  • 下载

Microsoft Agent技术简介

话题686854的标题是: 谁知道如何创建类似office2000助手模样的窗体? (100分)分类:图形图象 Blackdell (2001-10-23 10:26:00)  就是只显示一幅透明的图...
  • flyloafer
  • flyloafer
  • 2006-04-23 15:13:00
  • 3242

Microsoft Agent for win7

  • 2013年01月15日 00:54
  • 2.61MB
  • 下载

windows 7 不再支持Microsoft agent

微软原文:Welcome to Microsoft® Agent  Microsoft has decided to discontinue development of Microsoft Agen...
  • cxy1238
  • cxy1238
  • 2009-04-19 18:16:00
  • 1344

UML用户指南(Chapter5--关系)

  在UML中,事物之间相互联系的方式(无论是逻辑上的还是物理上的)都被创建为关系。在面向对象的建模中,有3种最重要的关系:依赖、关联和泛化。依赖(dependency)是使用关系。例如,水管依赖热水...
  • onewalkingman
  • onewalkingman
  • 2010-02-12 23:52:00
  • 469

UML(二)——关系

在UML中存在这四种关系(或者详细一点说是五种),下面列图表总结一下,由于CSDN表格中的单元格不好合并,就直接上图了...
  • xudepeng0813
  • xudepeng0813
  • 2011-08-20 21:18:11
  • 531

开发兼容Win7的Ms Agent程序

有时为了提高客户体验,往往会在程序中增加帮助系统,当年OfficeXP提供了一种叫助手精灵的帮助插件,一个小老头来帮助用户使用Office。现在Win7了,直接使用以往的Ms Agent来开发老头做使...
  • jacksonfan
  • jacksonfan
  • 2015-07-11 20:51:47
  • 783

用Microsoft Agent 控件与电脑交谈

Microsoft Agent 控件比Office 97中的助手功能更加丰富和强大,它提供的动画人物不仅有生动、有趣的动作,而且还能通过声卡、麦克风与用户进行交谈,这些功能使计算机更具人性魅力,其应用...
  • vrix
  • vrix
  • 2006-12-31 01:10:00
  • 861
收藏助手
不良信息举报
您举报文章:Microsoft Agent Tutorial Chapter 2
举报原因:
原因补充:

(最多只允许输入30个字)