Microsoft Agent Tutorial Chapter 1

原创 2004年09月10日 23:08:00
Part 1 - Loading the Microsoft Agent Control

The easiest way to load the agent control is to select it from the controls menu in VB and just drop it on your form.

Alternatively you can add a reference to the Microsoft Agent Control 2.0 from the References menu item in Visual Basic and create an object for the control at runtime like this:

     Private WithEvents MSAgent As Agent
     Set MSAgent = New Agent

For the purposes of this text we will assume the name of the Agent Control is called "MSAgent".

?

?

Part 2 - Loading a Character

A Character file defines what your agent will look like, and all the character animations are stored there. Before you can begin programming for MS Agent you need to specify what character file to open.

     ‘Create a Character Object
     Private Merlin As IAgentCtlCharacterEx

     ‘Load the Default Character by not supplying
     ‘an ACS file
     MSAgent.Characters.Load "Merlin", _ 
            “c:/windows/msagent/chars/merlin.acs”

     ‘Set the Merlin object to our new character.
     Set Merlin = MSAgent.Characters("Merlin")

Microsoft Agent 2.0 has the ability to allow the user to enter in a default character to use with programs. If you want to load the default character the code looks just about the same.

Instead of doing this:

     MSAgent.Characters.Load "Merlin", “c:/windows/msagent/chars/merlin.acs”

We just need to leave out the path and the default will be used, like this:

     MSAgent.Characters.Load "DefaultCharacter"

To show your character on the screen do the following:

     Merlin.Show

You can also hide your character by doing this:

     Merlin.Hide

?

Part 3 - Speech and Animations


Now that you have the character appearing on the screen you just need to get it to do something. Enter the following command after the Merlin.Show command:

     Merlin.Speak "Hello World!"

As you can see it's easy to get the agent to say something, all you need to do is give it a string with the text to speak and it will talk. Now try this one:

     Merlin.Speak "HELLO WORLD!"

You will notice that the Agent will not speak the words, but will sound out each letter. Remember this when you send text to the agents as you may want to convert it to lowercase before you call the Speak command.

The problem with the Speak command is that the agent does not use things like inflections or dramatic pauses; things we use in everyday speech, so typically when getting the agent to speak long sentences it will sound rather monotone. Lucky this is where speech output tags come in handy.

Part 4 - Speech Output Tags

Speech output tags can be used to modify the way in which words are spoken. All tags start and end with a backslash, and modify the word following the output tag. Whitespace is important so be sure not to leave empty space after your output tag or else your tag will not work properly.

One good example of this is the Emphasis ("Emp") tag. This tag will force the agent to emphasize a word. First lets hear a phrase without the emphasis placed on any word:

     Merlin.Speak "I will emphasize this word."


Now try it with the emphasis tag on the word "this".

     Merlin.Speak "I will emphasize /emp/this word."


Some tags like the Character ("Chr") tag have a parameter you can pass. This parameter must be surrounded by quotes, but since this is a string and the whole text is already in quotes you have to use double-quotes so VB knows that the quotes are part of the string. So to use the "Whisper" parameter for the "Chr" tag we would do this:

     Merlin.Speak "/Chr=""Whisper""/This is an example of whispering."

Another example of a tag that has parameters is the Context ("Ctx") tag. This tag can be used for Email addresses and phone numbers. To see why you may want to use the tag try this:

     Merlin.Speak "me@someplace.com"

Notice Merlin said "me at someplace com" instead of "me at someplace dot com". That is because the period is never normally spoken by the agent. To get the agent to speak the period for an Email address you need to use the "Ctx" tag. Try this:

     Merlin.Speak "/Ctx=""Address"/webmaster@abstractvb.com."

?

Part 5 - Bookmarks

A bookmark is really just another speech output tag, ("Mrk") except for one difference, and that is that there is a special event tied to this tag. The bookmark tag is used to mark specific points in the text supplied to the agents Speak command. Once one of these tags is hit it will fire the BookMark event of the Agent control and pass it the ID you entered in the "Mrk" tag.

To demonstrate how to use bookmarks here is a small application.

You will need to Create a form and place this code in it. You will also need to put a label on the form and call it "Label1".

     Option Explicit
 
     Private WithEvents MSAgent As Agent
     Private Peedy As IAgentCtlCharacterEx
     Private Merlin As IAgentCtlCharacterEx
    
     Private Sub Form_Load()
     'Create an Instance of the Agent Control
     Set MSAgent = New Agent
    
     'Load the Merlin Character
     MSAgent.Characters.Load "Merlin",
     "c:/windows/msagent/chars/Merlin.acs"
     Set Merlin = MSAgent.Characters("Merlin")
    
     'Move the Character to the left
     Merlin.Left = 500
    
     'Show Merlin without playing the animation
     Merlin.Show True
    
     'Use bookmarks in the text to identify where merlin is
     Merlin.Speak "/Mrk=1/I am now reading line number one. " & _
                  "/Mrk=2/Now I am reading line two. " & _
                  "/Mrk=3/And finally, I am reading line three. /Mrk=4/ "
     End Sub
    
     Private Sub MSAgent_Bookmark(ByVal BookmarkID As Long)
     
     'When Merlin hits the point in the text above where
     'there is a bookmark tag this event is fired and the
     'ID in the Mrk tag is passed into here as the
     'BookMark ID
     Select Case BookmarkID
     Case 1
         Form1.Label1.Caption = "Merlin is currently Reading Line 1"

     Case 2
         Form1.Label1.Caption = "Merlin is currently Reading Line 2"

     Case 3
         Form1.Label1.Caption = "Merlin is currently Reading Line 3"

     Case 4
         Form1.Label1.Caption = "Merlin has finished Reading all lines"

     End Select
     End Sub

?

Part 6? - Animations

(Microsoft provides the complete animation list for all its characters on their website.)

Making the agent perform a specific animation is just one line of code. Try running this:
Merlin.Play "Read"

Notice the agent will read and then stop and go back to the default animation behavior. This is not true for all animations there are some that are called Looping Animations. These animations behave like their name suggests, they loop repeatedly. Try this:
Merlin.Play "Reading"

You will have to stop the above program because the Agent will continuing looping forever. One way to stop this is by using the "Stop" command.

Coding,我还能爱你多久?

  首先声明,我目前还在爱着,但不知能爱多久,如果CODING是一个既漂亮又有气质的MM,那么我将坚持爱到底,实际上我认为她不是,尽管或许它曾经给我们带来光荣与自豪,或许它曾经是如此地美丽动人,但社会...
  • harrymeng
  • harrymeng
  • 2004-05-29 22:38:00
  • 2511

Microsoft Agent Tutorial Chapter 2

Part 1 - Adding Agent CommandsTo get the Agent to respond to userinput you will need to add commands...
  • wm_ni
  • wm_ni
  • 2004-09-10 23:10:00
  • 666

Microsoft Agent for win7

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

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

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

Chapter 1 of Microsoft Visual C#

  • 2011年05月12日 00:48
  • 1.73MB
  • 下载

开发兼容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 1
举报原因:
原因补充:

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