Microsoft Agent Tutorial Chapter 1

xiaoxiao2021-03-06  57

Part 1 - Loading The Microsoft Agent Control

.

Alternative 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 associn 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 The. Before MS Agent You NEED To Specify What Character File To Open.

'Create a Character Object

Private Merlin As IAgentctlcharacterex

'Loading the default character by not supporting the DEFAULT CHARAC

'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 program. If you want to load the default character the code.

INSTEAD of doing this:

Msagent.Characters.Load "Merlin", "C: /Windows/msAgent/chars/merlin.acs"

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

Msagent.Characters.Load "defaultcharacter"

To show your character on the screen do the folload:

Merlin.show

You can also hide your character by doing this:

Merlin.hide

?

Part 3 - Speech and Animations

Now That You Haven 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 is one 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 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 expedition

Private Withevents Msagent As Agent

Private peedy as iAgentctlcharacterexprivate Merlin as IAgentctlcharacterex

Private sub flow_load ()

'Create An Instance of the Agent Control

SET MSAGENT = New Agent

'Loading 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 count." & _

"/ Mrk = 2 / now I am Reading line two." & _

"/ Mrk = 3 / and finally, i amread 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 fas 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

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

New Post(0)