Make your own free website on Tripod.com

Programming MS Agent using Visual Basic

This tutorial will explain how to program MS Agent using visual basic

Before you begin - check the Requirements

Make sure your OS is agent-ready and you have the required tools listed below. If you don't have install them by going to the install page.

In this tutorial I have explained how to program agent using Visual Basic 6.0, But Visual Basic 5.0 will be able to use this without any problems.

Introduction

In this agent tutorial I will explain how to program the MS Agent in Visual Basic. This tutorial is for those who have not tried programming Microsoft Agent technology in Visual Basic before.
In this tutorial I will explain you how to make a simple application using the character Merlin. Please read the topic below if you have just started learning MS Agent, If you like this tutorial & have learned agent from it, then please recommend it to others. And don't forget to link to MS Agent World. Thanks. Lets Gets started learning the Cool Microsoft Agent Technology.

What is Microsoft Agent ?

Microsoft® Agent is a set of programmable software services that supports the presentation of interactive animated characters within the Microsoft Windows® interface. Developers can use characters as interactive assistants to introduce, guide, entertain, or otherwise enhance their Web pages or applications in addition to the conventional use of windows, menus, and controls.
Microsoft Agent enables software developers and Web authors to incorporate a new form of user interaction, known as conversational interfaces, that leverages natural aspects of human social communication. In addition to mouse and keyboard input, Microsoft Agent includes optional support for speech recognition so applications can respond to voice commands. Characters can respond using synthesized speech, recorded audio, or text in a cartoon word balloon.
The conversational interface approach facilitated by the Microsoft Agent services does not replace conventional graphical user interface (GUI) design. Instead, character interaction can be easily blended with the conventional interface components such as windows, menus, and controls to extend and enhance your application's interface.
Microsoft Agent's programming interfaces make it easy to animate a character to respond to user input. Animated characters appear in their own window, providing maximum flexibility for where they can be displayed on the screen. Microsoft Agent includes an ActiveX® control that makes its services accessible to any programming languages that support ActiveX, including Web scripting languages such as Visual Basic® Scripting Edition (VBScript). This means that character interaction can be programmed even from HTML pages using the <OBJECT> tag.

Explanation MS Agent Technology in my own words
So, you just read the previous heading "What is Microsoft Agent" taken from MSDN. Got it what is Agent technology. I think no. when I was first introduced with this technology in Feb-01 I was also confused. Let me explain more about agent technology in my own words.

MS Agent Technology is basically a animation technology which allows you to display animated characters on your desktop. it uses SAPI 4.0 services to provide Text to Speech and Voice Recognition feature.

So,

If you install (MS Agent Control + Character) you will get a character with NO TTS, NO SR, NO Animation Sounds
If you install (
MS Agent Control + Character + SAPI 4.0) you will get a character with NO TTS, NO SR but With Animation Sounds
If you install (
MS Agent Control + Character + SAPI 4.0 + TTS Engine ) you will get a character with TTS, Animation Sound, But with no SR
If you Install (MS Agent Control + Character + SAPI 4.0+ TTS Engine + SR Engine) you will get a character with TTS, Animation Sound, and SR

Tip: You will also need a agent enabled app or website to view agent technology
Tip: If you have
SR Engine or Speech Control Panel than there is no need to install SAPI 4.0 Runtime


The Basics

Now as you have already understood what is MS Agent & what we can do with it, So its now time to learn some basics.
MS Agent can be programmed using the MS Agent Control or by directly accessing the control

Programming by Directly Accessing the Control Via Code
Now open VB. then follow steps listed below.

  1. From the Project Menu click Reference And Select Microsoft Agent Control 2.0
  2. Double Click the Form (You will now be in the Form Load Event) and Type
    Set Agent1 = New Agent
  3. In the Declarations section Type
    Public WithEvents Agent1 As Agent
    Public Character As IAgentCtlCharacterEx

Programming by MS Agent Control
Now open VB. then follow steps listed below.

  1. Right-click on the Toolbox and Select "Components" OR press Ctrl + T
  2. Scroll down the list until you see "Microsoft Agent Control 2.0". Select it and press OK. The MS Agent Control will appear in the toolbox.
  3. Double-click on the "Agent Icon" in the Toolbox OR click it once and draw it on the form.
    You have now added the MS Agent control to your form. This control will be invisible at run-time but visible at the design time.
  4. In the Declarations section Type
    Public Character As IAgentCtlCharacterEx

Loading a Character

Now add a command button to the form and change its caption to "Load Agent". Double Click the button and type.

To load the Default Character type
Agent1.Characters.Load "#1"
Set Character = Agent1.Characters("#1")
' Added to simplifying the code
Character.Show
' This Code will Show the character

To load a Custom Character Type
Agent1.Characters.Load "#1", "#2"
Set Character = Agent1.Characters("#2")
' Added to Simplifying the Code
Character.Show ' This Code will Show the character

Here
#1 means the ID of a character.
#2 means the file name of character. If you want to load Merlin you will need to enter its filename with extension like Merlin.acs


Telling Character to speak, think, move, play etc.


In this section I will explain you how to tell character to Speak, Think, Whisper, Move, Play Animation & gesture.

Telling Character to Speak
Add a command button and change its caption to Speak, Double Click the button and add this code
Character.Speak "Type Text here to Speak" 'Character will Speak using this code

Telling Character to Think
Add a command button and change its caption to Think, Double Click the button and add this code
 
Character.Think "Type Text Here to Think" 'Character will Think Using this Code

Telling Character to Whisper
Add a command button and change its caption to Whisper, Double Click the button and add this code
 
Character.Speak "\Chr=""Whisper""\Type text here" 'Character will whisper using this code

Moving the Character
Add a command button and change its caption to Move, Double Click the button and add this code
 
Character.MoveTo X, Y, At Speed 'Character will Move using this code
Here X = X pixels
Y = Y Pixels
Speed is a optional Field. It must be in millisecond

So, If you want to move character to middle of you screen and your screen size is 800 x 600 than
The Code will be
Character.MoveTo 400, 300, 1000

Playing Animations
Add a command button and change its caption to Play Anim, Double Click the button and add this code
Character.Play "Animation Name" 'This will play character's animation like greet

Using Gestures
Add a command button and change its caption to Gesture, Double Click the button and add this code
 
Character.GestureAt X, Y 'Character will gesture using this code

Here X = X pixels
Y = Y Pixels

So, If you want the character gesture at middle of you screen and your screen size is 800 x 600 than
The Code will be
Character.MoveTo 400, 300

Changing Character Size
Add a command button and change its caption to Change Size, Double Click the button and add this code
 
Character.Width = Width Value 'This code will change the character's width
 Character.Height = Height Value 'This code will change the character's height

Changing Character's Balloon Font Name and Size
Add a command button and change its caption to Balloon Font, Double Click the button and add this code

Character.Balloon.FontName = "Tahoma" 'This code will change the character's balloon Font name
Character.Balloon.FontSize = "14"
'This code will change the character's balloon Font Size

Changing Character's Voice
Add a command button and change its caption to Voice, Double Click the button and add this code
Character.TTSModeID = "GUID"
'This Code will Change the character's voice
Here GUID means values like {ca141fd0-ac7f-11d1-97A3-006008273000}
. You will need
this tool to get the different Voice GUID of Engines.

Thats All. You just leared how to program ms agent in visual basic. You will now be able to create ms agent programes using vb.

You can send you comments about this tutorial to me here
abhishek007p@hotmail.com

last Updated: 11-Jul-02 03:48 PM