Click here to Skip to main content
6,293,171 members and growing! (11,856 online)
Email Password   helpLost your password?
Languages » C# » Applications     Intermediate

Announcer in C#.NET using Microsoft Agent

By Ashraf Mohamed

A tool to announce message, sing a song and tell a joke.
C++, C#.NET 1.0, Win2K, MFC, Dev
Posted:11 Jun 2003
Views:95,503
Bookmarked:52 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
18 votes for this article.
Popularity: 5.15 Rating: 4.10 out of 5
1 vote, 5.6%
1
1 vote, 5.6%
2
1 vote, 5.6%
3
6 votes, 33.3%
4
9 votes, 50.0%
5

I'm Genie

Picture 1. I'm genie

I'm Merlin

Picture 2. I'm Merlin

I'm Peedy

Picture 3. I'm Peedy

I'm Robby

Picture 4. I'm Robby

Overview

Microsoft� Agent is a software technology that enables an enriched form of user interaction that can make using and learning to use a computer, easier and more natural. Microsoft� Agent is a set of programmable software services that supports the presentation of interactive animated characters within the Microsoft Windows� interface I'm using Microsoft� Agent to develop this announcer. I have used four type of announcers here. They are Genie, Merlin, Peedy and Robby . More.. http://www.microsoft.com/msagent/default.asp.

This class demonstrates the use of following namespaces.

  • using System.Runtime.InteropServices
  • using System.Reflection
  • AgentServerObjects
  • AgentObjects

Things required, where to get and how to install

  1. You have to add reference AgentObjects.dll and AgentServerObjects.dll. You can get this two DLLs from F:\Program Files\Microsoft Visual Studio .NET\ FrameworkSDK\Samples\Technologies\Interop\Applications\MSAgent\AgentExplorer. Bear in mind, you have installed .NET in F:.

    Or Just go to F:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Samples\Technologies\Interop\Applications\MSAgent\Hello1 and take a look at read me.htm file how to get those DLLs. You just give, nmake all. This command will create AgentObjects.dll and AgentServerObjects.dll in hello1 folder.

    Or just use those DLLs from this setup. I have bind these DLLs with this setup.

    Assure those 2 DLLs in bin debug/release folder and add reference to solution explorer in you project.

  2. We have to put .acs in debug or release folder. Announcer will show error if .acs file is not there. You can get four .acs files from

    http://www.microsoft.com/msagent/downloads/user.asp. There you get genie, Merlin, Peedy and Robby, Microsoft agent character files (.acs)

    and put into release or debug folder.

  3. Just download and open the MicrosoftAgentApplication.sln file to use it.

    Before run this, you have to install Text to speech engine. Download Text-to-Speech Engineer tv_enua.exe American English - 1 MB from here http://www.microsoft.com/msagent/downloads/user.asp. I could not add this with my demo setup due to size restriction.

    Just click tv_enua.exe to install. Then announcer is ready to announce anything, sing a song and tell a joke.

Source code

I have given sample code to use it.

using System.Data;
using System.Drawing;
using System.Reflection; 
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel;
using System.Runtime.InteropServices; 

using AgentObjects;
using AgentServerObjects;

Before we make a function to create an error files, we have to declare some variables that will be used in our function. This is an example of variables declaration and the main function is ErrorRoutine.

  AgentServer Srv = new AgentServer();  //Create a agent server

  //If unable to create show the error

  if (Srv == null) 
  {
    MessageBox.Show("ERROR: Agent Server couldn't be started!");
  }

  IAgentEx SrvEx;

  // The following cast does the QueryInterface to 

  //fetch IAgentEx interface from the IAgent interface,

  //directly supported by the object

  SrvEx = (IAgentEx) Srv;

  // First try to load the default character

  int dwCharID=0, dwReqID=0;
  try 
  {
    // null is used where VT_EMPTY variant is expected by the COM object

    String strAgentCharacterFile = null;
    //Check  microsoft agent character filename(.acs)  is empty 

    if (!strFileName.Equals(string.Empty))  
    {
    //Get the acs path

    strAgentCharacterFile = strPath + strFileName;
    }
    else
    {
    MessageBox.Show("Select Style");
    return;
    }

    if (!TxtSpeakInput.Text.Equals(string.Empty)) 
    {
    //load the acs file

    SrvEx.Load(strAgentCharacterFile, out dwCharID, out dwReqID);
    }
    else
    {
    MessageBox.Show("Enter Text");
    return;
    }
} 
catch (Exception) 
{
    MessageBox.Show("Failed to load Agent character! Exception details:");
}

   IAgentCharacterEx CharacterEx=null;
   SrvEx.GetCharacterEx(dwCharID, out CharacterEx);
   //CharacterEx.SetLanguageID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));


   // Show the character.  The first parameter tells Microsoft

   // Agent to show the character by playing an animation.

   CharacterEx.Show(0, out dwReqID);

   // Make the character speak

   // Second parameter will be transferred to the COM object as NULL

   CharacterEx.Speak(TxtSpeakInput.Text, null, out dwReqID);
}

Here, We can select a different announcer and enter different text to speak. Just try it. It is simple to use.

We can create our own character files. Just visit http://www.microsoft.com/msagent/downloads/user.asp to explore more..

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

About the Author

Ashraf Mohamed


Member
I am a system analyst and have been with Microsoft & Sun Technologies for more than 7 years. I have always been fascinated by java and .NET. I take lot of technical articles and writing them.

I am a Sun Certified Java Programmer for Java 2 Platform 1.4 , Web component developer Java 2 Platform - Enterprise Edition 1.4 and Microsoft certified developer using C#.NET in Web Development ASP.NET.

Visit my web site www.mohamedashraf.tk

Occupation: Web Developer
Location: United States United States

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 19 of 19 (Total in Forum: 19) (Refresh)FirstPrevNext
Questioncan any one give me some presentable eample of stack Pinmembersumaira manzoor20:10 1 Oct '08  
QuestionMultiple copies of same agent Pinmemberkrishnakumarp21:27 17 Jul '07  
Questionerror when manipulating from event handler Pinmemberscotru213:15 24 Jun '07  
AnswerRe: error when manipulating from event handler Pinmemberscotru215:00 24 Jun '07  
GeneralOutofMemoryexception Pinmemberjasaz22:53 2 Feb '07  
GeneralRe: OutofMemoryexception PinmemberMohamed Ashraf1:57 3 Feb '07  
Generalits working!!!! Pinmemberjasaz5:49 4 Feb '07  
QuestionCatch an event from character Pinmemberyellow_lucky2:28 4 May '06  
GeneralI donn't hear anything ... Pinmemberjmwatte11:47 20 Jul '05  
GeneralRe: I donn't hear anything ... Pinmemberlordhairballhome20:42 24 Aug '05  
General.Net compact framework Pinsusschad,Yang20:36 20 Feb '04  
GeneralRe: .Net compact framework Pinmembercontini5:54 16 Feb '05  
GeneralRe: .Net compact framework PinmemberEric Van de Kerckhove8:06 23 Feb '06  
Generalasp agents PinsussJerry Amadon13:19 13 Jan '04  
GeneralRe: asp agents PinsussAnonymous18:53 10 Oct '04  
GeneralLoad error.... PinmemberZippyBubbleHead19:34 17 Jun '03  
GeneralRe: Load error.... PinmemberMohamed Ashraf4:57 23 Jun '03  
General[Message Deleted] PinmemberVijayCh9:18 12 Jun '03  
GeneralRe: Images missing PinmemberMohamed Ashraf20:10 12 Jun '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 11 Jun 2003
Editor: Smitha Vijayan
Copyright 2003 by Ashraf Mohamed
Everything else Copyright © CodeProject, 1999-2009
Web16 | Advertise on the Code Project