Click here to Skip to main content
Click here to Skip to main content

Creating Cool Agent User Interfaces

, 14 Mar 2002
Rate this:
Please Sign up or sign in to vote.
This article describes using Microsoft agent to create user interfaces that display characters, like Office 2000 Office Assistants.
<!-- Download Links -->

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

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

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):

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

Share

About the Author

Nikhil Dabas
President NikSci
India India
No Biography provided

Comments and Discussions

 
Questionmultilanguage support of speech api how?? Pinmember29181195-Mar-09 2:43 
AnswerRe: multilanguage support of speech api how?? PinmemberNikhil Dabas5-Mar-09 3:45 
GeneralMS Agent, why Scroll lock PinmemberMuammar©10-May-07 22:41 
GeneralPARSERS PinsussAnonymous25-Dec-04 9:29 
Generalrecongnition Pinmembermaitre cesar27-Apr-03 3:08 
Generalclass PinsussAnonymous24-Apr-03 0:16 
Generalaximp Pinmembermaitre cesar22-Apr-03 3:43 
GeneralRe: aximp Pinmember.S.Rod.22-Apr-03 3:46 
QuestionAgent output to voice modem? Pinsussjohn barden9-Oct-02 19:22 
AnswerRe: Agent output to voice modem? PinmemberNikhil Dabas10-Oct-02 11:23 
GeneralScroll lock button Pinmemberhappys24-Jul-02 4:26 
GeneralRe: Scroll lock button Pinmembermacromark20-May-03 20:47 
GeneralRe: Scroll lock button Pinmemberkikos french .NET developer11-Dec-03 5:47 
GeneralMSAgent voice recognition PinsussAnonymous23-Jul-02 7:21 
GeneralRe: MSAgent voice recognition Pinmemberhappys24-Jul-02 4:28 
GeneralMs agent PinmemberAnonymous17-Apr-02 4:58 
GeneralRe: Ms agent PinmemberMichael P Butler17-Apr-02 5:04 
QuestionHas anyone actually DONE anything with Agents ? PinmemberJim Crafton17-Mar-02 7:07 
AnswerRe: Has anyone actually DONE anything with Agents ? PinmemberNikhil Dabas17-Mar-02 23:26 
AnswerRe: Has anyone actually DONE anything with Agents ? PinmemberMichael P Butler17-Mar-02 23:49 
GeneralRe: Has anyone actually DONE anything with Agents ? PinmemberAnonymous24-Mar-02 3:29 
AnswerRe: Has anyone actually DONE anything with Agents ? PinsussAnonymous6-Aug-02 4:23 
GeneralRe: Has anyone actually DONE anything with Agents ? PinmemberJim Crafton6-Aug-02 4:30 
GeneralRe: Has anyone actually DONE anything with Agents ? PinmemberBui Huy Kien12-Dec-02 17:11 
GeneralRe: Has anyone actually DONE anything with Agents ? PinsussAnonymous11-Apr-05 11:21 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 15 Mar 2002
Article Copyright 2001 by Nikhil Dabas
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid