转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> VB.NET程序 >> 正文
Microsoft Agent Tutorial Chapter 1         ★★★★

Microsoft Agent Tutorial Chapter 1

作者:闵涛 文章来源:闵涛的学习笔记 点击数:816 更新时间:2009/4/23 16:39:01
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:

     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.


[聊天工具]Microsoft Office 2007简体中文版最新截图  [系统软件]delphi2005帮助系统使用了microsoft document exp…
[VB.NET程序]在VB.NET中应用Agent技术  [VB.NET程序]Microsoft Office,VB.NET编程 PIA使用小程序
[VB.NET程序]VBCOM TUTORIAL(3)  [VB.NET程序]VBCOM TUTORIAL(2)
[VB.NET程序]VBCOM TUTORIAL(1)  [Delphi程序]Borland与Microsoft关于Delphi的对话
[Delphi程序]Borland 公布支持 Microsoft  .NET平台产品策略  [Delphi程序]ms agent 经典用法
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台