Click here to Skip to main content
15,881,380 members
Articles / Programming Languages / C#
Article

Creating Cool Agent User Interfaces

Rate me:
Please Sign up or sign in to vote.
4.20/5 (13 votes)
14 Mar 20024 min read 253.5K   3.2K   83   35
This article describes using Microsoft agent to create user interfaces that display characters, like Office 2000 Office Assistants.

Contents

Overview

Microsoft Office 2000 uses animated characters, which it calls Office Assistants, to help users and provide assistance. With Microsoft Agent, you can add such characters to your own applications. You can even use the Office Assistants themselves – like The Genius or F1. Characters designed for use with Agent can do a variety of tasks – like speech synthesis and recognition, in addition to displaying a variety of animations.

Requirements

To be able to use this technology, you must have:

  1. The Microsoft Agent Core components.
  2. The Microsoft Agent Characters – Genie, Merlin, Robby, and Peedy.
  3. The Lernout and Hauspie Text-to-Speech engines for at least US English.
  4. The Microsoft Speech API 4.0a runtime.
  5. The Microsoft Speech Recognition Engine.

All these components are available from http://microsoft.com/msagent/downloads.htm. In addition, to use the Microsoft Office characters, you must have Office 2000. Office 97 characters are not compatible with Agent.

Using Microsoft Agent with the .NET Framework

Microsoft Agent is provided as an ActiveX control DLL. To use it within .NET, you can use the AxImp.exe utility provided with the .NET Framework SDK. Create a folder where you want to keep the imported libraries, and then use the command:

aximp %systemroot%\msagent\agentctl.dll

The makefile included in the download does this for you. This command should create two files: AxAgentObjects.dll and AgentObjects.dll. You are now ready to use Agent with .NET.

Programming Agent

Agent programming is easy because it relies completely on COM, and we don’t have to mess around with PInvoke or something. The first step to using Agent is to add the Agent ActiveX control in AxAgentObjects.dll to your project. Put it anywhere on a form; it is invisible at runtime. Next, you should add a member variable of type AgentObjects.IAgentCtlCharacterEx (from AgentObjects.dll) to your class. You should import the AgentObjects namespace into your application; this simplifies several tasks. Essentially, you must, at a minimum:

  1. Load the character you want, and provide a descriptive name to refer to it. In the Hello World sample, this is accomplished by the line AxAgent.Characters.Load("Genie", (object)"GENIE.ACS");
  2. Set your character variable to the character you just loaded. In the Hello World sample, this is accomplished by the line Character = AxAgent.Characters["Genie"];
  3. Set the correct language to use: Character.LanguageID = 0x409; sets the language to US English.
  4. Show the character: Character.Show(null);

These steps shall simply load and display the character.

Hello World Sample

Image 1

The mandatory Hello World sample requires the Genie character. The sample simply loads the character and displays him. You can also make him say something. To make the character talk, the character’s speak method is called, like this:

if(TextToSpeak.Text.Length == 0)  // Don't speak a zero-length
  return;                         // string.

//Make the character speak.
Character.Speak(TextToSpeak.Text, null);

As you can see, it’s very simple to use Agent.

Using Speech Recognition

Unlike the office assistants, you can make Agent characters talk and also respond to voice commands. Any commands you add shall also be available in the character’s context menu. Speech recognition is, by default, enabled only when you hold down the scroll lock key. All you have to do is to add new commands to the character object’s Commands collection. Then, you must add an event handler for the Agent control’s Command event. A boxed IAgentCtlUserInput object is supplied to the event handler as a parameter. You can access the command recognised by the IAgentCtlUserInput object’s Name property.

Interactive Hello World Sample

Image 2

The Interactive Hello World sample demonstrates basic speech recognition, as well as playing animation. First, the control and the character (Robby) are loaded and initialised, and then two commands are added:

protected void LoadButton_Click(object sender, System.EventArgs e)
{
  // Load the Robby character.
  AxAgent.Characters.Load("Robby", (object)"ROBBY.ACS");
  Character = AxAgent.Characters["Robby"];
  StatusLabel.Text = Character.Name + " loaded.";
  // Set the language to US English.
  Character.LanguageID = 0x409;

  // Display the character.
  Character.Show(null);

  LoadButton.Enabled = false;

  // Display name for the commands.
  Character.Commands.Caption = "Hello World";

  Character.Commands.Add("Hello",  // Command name
    (object)"Say Hello",  // Display name
    (object)"([say](hello | hi) | good (day | morning | evening))", // SR String
    (object)true,  // Enabled
    (object)true);  // Visible

  Character.Commands.Add("Goodbye",  // Command name
    (object)"Goodbye",  // Display name
    (object)"(bye | goodbye | exit | close | quit)", // SR String
    (object)true,  // Enabled
    (object)true);  // Visible

  PromptLabel.Visible = true;
}

The speech recognition strings offer several options that the user can say; for example, saying ‘goodbye’, ‘bye’ and ‘close’ have the same effect. In all cases, the command name is passed to the event handler, so you don’t have to account for the various variations of the recognised string. In the event handler, a test is done for the command:

protected void AxAgent_Command(object sender, AxAgentObjects._AgentEvents_CommandEvent e)
{
  IAgentCtlUserInput ui;
  ui = (IAgentCtlUserInput)e.userInput;
  if(ui.Name == "Hello")
  {
    Character.Speak((object)"Hello. My name is Robby." +
      " Pleased to meet you.", null);

    PromptLabel.Text = "Say goodbye to dismiss Robby.";
  }
  if(ui.Name == "Goodbye")
  {
    Character.Speak((object)"It was nice talking to" +
      " you. Goodbye.", null);

    Character.Play("Wave");
    Character.Play("Hide");
  }
}

Animations are played with the character object’s play method.

The AgentDemo Application

If you see the Microsoft Agent site, you will see a Visual Basic sample that enumerates all animations present in a character. The AgentDemo application also does the same thing, only in C#. You can load all Agent and Microsoft Office characters and see a list of animations. Here’s a screenshot (with the Office 2000 F1 character loaded):

Image 3

This app is kinda redundant now, because Microsoft ships just such a sample with Beta 2. I just converted what I had done for Beta 1 to Beta 2 code.

A Note About Your Applications

Many people think that the Office Assistants are irritating. You must take care not to make your characters irritating, but instead helpful, and always provide an easily accessible option to turn them off.

History

15 Mar 2002 - updated source files.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
President NikSci
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionC++? Pin
Matt Newman4-Sep-01 16:19
Matt Newman4-Sep-01 16:19 
AnswerRe: C++? Pin
Nikhil Dabas5-Sep-01 7:44
Nikhil Dabas5-Sep-01 7:44 
Generalthanks! Pin
peterchen2-Sep-01 23:41
peterchen2-Sep-01 23:41 
GeneralSo Darn Annoying Pin
Brian C Hart4-Jun-01 20:46
professionalBrian C Hart4-Jun-01 20:46 
GeneralEvil! Evil I Tells YA! Pin
Pete Bassett25-May-01 4:20
Pete Bassett25-May-01 4:20 
GeneralRe: Evil! Evil I Tells YA! Pin
Chris Maunder25-May-01 4:34
cofounderChris Maunder25-May-01 4:34 
GeneralRe: Evil! Evil I Tells YA! Pin
Member 3813133-Dec-03 22:00
Member 3813133-Dec-03 22:00 
GeneralRe: Evil! Evil I Tells YA! Pin
Almighty Bob11-Aug-03 12:51
Almighty Bob11-Aug-03 12:51 
I'm right there with you on this one!

pure unadulterated evil. the lord of the underworld himself endorses this product! (or created it, I cant tell which)
GeneralOffice XP Pin
[James Pullicino]24-May-01 5:28
[James Pullicino]24-May-01 5:28 
GeneralRe: Office XP Pin
Nikhil Dabas24-May-01 6:58
Nikhil Dabas24-May-01 6:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.