Microsoft Agent Tutorial Chapter 1

2008-04-10 03:07:24来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

Microsoft Agent Tutorial Chapter 1

Author: Abstractvb
Date: 4/22/2000 6:53:44 PM
ID: 83
Microsoft Agent Version 2 Needed.

This starts a beginner level and shows how to load the control, use speech output tags, animations and bookmarks.

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:

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Visual Basic 6 Naming Standards

下一篇:Microsoft Agent Tutorial Chapter 2