How to use Microsoft Agent in C #

xiaoxiao2021-03-06  53

http://www.codeproject.com/csharp/usemsagentcsharp.asp

Download Demo - 24 KB Download Source - 8 KB

Introduction

Microsoft Agent is a technology used to add interactive animated characters to windows application or web page;. These characters act according to the user input via speech recognition engine, and also they can speak and tell the user something via text-to-speech engine Microsoft Provides Programmers Four Characters

A-Peddy B-Genie C-Merlin D-Robby.

Each Character Has ITS OWN Set of Animation

Background

I've searched well so many sites for code that I can use MS agent to provide help to end user. After searching the C # books, I've found some nice code that helped me to create this simple Application. Hope it can help as A Basic Architecture.

USING THE CODE

At first you should simply open VS.NET and then at the File menu click on New, Project From the New Project Dialog Box, choose the Windows Application template project and name it WindowsApplication1 like shown below.:

After you create the windows add a button to it and name it speak and add a RichTextBox and name it talk, you should add to it Microsoft Agent component, to do that click on the Customize toolbox from tool menu then the following Dialog will appear

Select Microsoft Agent control 2.0 and click ok. Now in your tool box at the end of it you will find a new item added to it "Microsoft Agent". Drag this item and drop it in your application, after drop "Microsoft Agent" the .NET WILL Generate A New Object from Type AxAgentObjects.Axagent As The Following

Namespace WindowsApplication1

{

///

/// summary description for Form1.

///

Public Class Form1: System.Windows.Forms.form

{

Private axAgentObjects.axagent axAgent1; ///

/// Required Designer Variable.

///

Private system.componentmodel.Container Components = NULL;

Public Form1 ()

{

//

// Required for Windows Form Designer Support

//

InitializationComponent ();

//

// Todo: Add Any Constructionor Code

// after InitializeComponent Call

//

}

Now create Object of type agentObjects.iagentctlcharacter and name this Object Speaker, Now at the loading function Write the Following

Private Void Form1_Load (Object Sender, System.EventArgs E)

{

Try

{

// load the character in the axagent1 Object -

// axAgent1 Can Load More Than One Character

THIS.AXAGENT1.CHARACTERS.LOAD ("Robby", "Robby.ACS");

// give the speaker object the character to show it

This.Speaker = this.axagent1.characters ["Robby"];

this.Speaker.show (0);

}

Catch (filenotfoundexception) // if the character NOT FOUND

{

MessageBox.show ("Invalid CharaTr location");

}

}

In The Speak Button Click Function Write The Following Code

Private Void Speak_Click (Object Sender, System.EventArgs E)

{

IF (this.talk.text! = "")

This.Speaker.Speak (this.talk.text, null);

Else

This.Speaker.Speak ("What Should I Say", NULL);

}

In The Speaker Objects You Will Find Some Useful Function That Help You To Control The Character Such as:

// MoveTo (int X, int y, objectspeed speed);

// Play (String Animation);

// this function make the character to play some animation

// the Possible Animations That The Character CAN Play IT Are

/ *******************

RESTPOSE, WAVE, DONTRECognize, Uncertain, Decline, Sad,

Stoplistening, GetAttention, GetAttentionReturn, Blink, Idle3_2,

Surprised, congratulate_2, reading, announce, read, readreturn, idle2_2, write, write, writereturn, congratulate, confused, suggest, moveright,

Moveleft, IDLE2_1, Moveup, Movedown,

StartListening, WriteContinued, Domagic1,

Domagic2, idle1_1, lookdown, lookdownblink, lookdownreturn, lookleft,

Lookleftblink, Lookleftreturn, Idle1_3, LookRight, LookrightBlink,

LOOKRIGHTRETURN, LOOKUP, LOOKUPBLINK, LOOKUPRETURN, IDLE1_2,

Readcontinued, PLLEASED, GetAtt1Continued, Process, Search,

Think, idle1_4, greet, idle3_1, gestureup, gestown, gestureleft,

Gestureright, Show, Hide, Hearing_4, Hearing_1, Hearing_2, Hearin,

Alert, Explain, Processing, Thinking, Searching, Acknowledge, ACKNOWEDGE

******************** /

The full code

Using system;

Using system.drawing;

Using system.collections;

Using system.componentmodel;

Using system.windows.forms;

Using system.data;

Using system.io;

Namespace WindowsApplication1

{

///

/// summary description for Form1.

///

Public Class Form1: System.Windows.Forms.form

{

PRIVATE AXAGENTOBJECTS.AXAGENT AXAGENT1;

Private AgentObjects.iagentctlcharacter Speaker;

Private system.windows.Forms.Button Speak;

Private system.windows.Forms.richtextbox talk;

///

/// Required Designer Variable.

///

Private system.componentmodel.Container Components = NULL;

Public Form1 ()

{

//

// Required for Windows Form Designer Support

//

InitializationComponent ();

//

// Todo: Add Any Constructionor Code After

// InitializeComponent Call

//

}

///

/// Clean Up Any Resources Being Used.

///

Protected Override Void Dispose (Bool Disposing)

{

IF (Disposing)

{

IF (Components! = NULL)

{

Components.dispose ();

}

}

Base.dispose (Disposing);

}

#Region Windows Form Designer Generated Code

///

/// Required Method for Designer Support - Do Not Modify

/// The contents of this method with the code editor.

///

Private vidinitiRizeComponent ()

{

System.Resources.ResourceManager Resources =

New System.Resources.ResourceManager (TypeOf (Form1));

THIS.AXAGENT1 = New axAgentObjects.axagent ();

This.Speak = new system.windows.Forms.Button ();

This.talk = new system.windows.forms.richtextbox ();

(System.comPonentModel.isupportInitialize)

(this.axagent1))). Begininit ();

THIS.SUSPENDLAYOUT ();

//

// axAgent1

//

THIS.AXAGENT1.ENABLED = TRUE;

this.axagent1.location = new system.drawing.point (0, 232);

THIS.AXAGENT1.NAME = "axAgent1";

this.axagent1.ocxState =

((System.Windows.Forms.Axhost.State)

(Resources.getObject ("AxAgent1.OCxState)))))

THIS.AXAGENT1.SIZE = New System.drawing.size (32, 32);

THIS.AXAGENT1.TABINDEX = 0;

//

// speak

//

This.Speak.location = new system.drawing.point (192, 176);

This.Speak.name = "speak";

This.Speak.size = new system.drawing.size (168, 48);

This.speak.tabindex = 1;

This.Speak.text = "speak";

this.speak.click =

New system.eventhandler (this.speak_click);

//

// Talk

//

this.talk.location = new system.drawing.point (24, 24);

THIS.TALK.NAME = "Talk";

this.talk.size = new system.drawing.size (328, 136);

THIS.TALK.TABINDEX = 2;

THIS.TALK.TEXT = "" "

//

// Form1

//

THIS.AUTOSCALEBASESIZE = New System.drawing.size (5, 13);

THIS.CLIENTSIZE = New System.drawing.size (376, 270);

This.Controls.addrange (new system.windows.forms.control [] {this.talk,

this.speak,

THIS.AXAGENT1});

THIS.NAME = "Form1";

THIS.TEXT = "Form1";

This.Load = New System.EventHandler (this.form1_load);

(System.comPonentModel.isupportInitialize)

(this.axagent1))). Endinit ();

This.ResumeLayout (false);

}

#ndregion

///

/// The main entry point for the application.

///

[Stathread]

Static void main ()

{

Application.run (New Form1 ());

}

Private Void Form1_Load (Object Sender, System.EventArgs E)

{

Try

{

THIS.AXAGENT1.CHARACTERS.LOAD ("Robby", "Robby.ACS");

// load the character in the axagent1 Object

// - Axagent1 Can Load More Than One Character

This.Speaker = this.axagent1.characters ["Robby"];

// give the speaker object the character to show it

this.Speaker.show (0);

}

Catch (filenotfoundexception) // if the charater NOT FOUND

// using io

{

MessageBox.show ("Invalid CharaTr location");

}

}

Private Void Speak_Click (Object Sender, System.EventArgs E)

{

IF (this.talk.text! = "")

This.Speaker.Speak (this.talk.text, null);

Else

This.Speaker.Speak ("What Should I Say", NULL);

}

}

}

TIP

You Should Download The TTS "Text-to-Speech" Engine on Your Computer To Make The Character Talk. To Download The Engine See

Www.microsoft.com/products/msAgent/downloads.htm

About Ahmed Jamil Kattan

Ahmed J. Kattan student in Jordan University of Science and Technology computer science department 4th level, I have written several applications and designed multiple algorithms. My favorite languages ​​are C and C # .see www.geocities.com/ahmed_gk to view Ahmed J. Kattan 's Online CV. Click Here to View Ahmed Jamil Kattan's Online Profile.other Popular C # programming Articles:

Importing and Extending ActiveX Controls in .NETImporting and extending ActiveX controls in .NET I / O Ports Uncensored Part 2 -. Controlling LCDs (Liquid Crystal Displays) and VFDs (Vacuum Fluorescent Displays) with Parallel PortControlling LCDs (Liquid Crystal Displays) and VFDs ( Vacuum Fluorescent Displays) with Parallel Port Run other programs from your .NET codeA .NET library and a sample application demonstrating simple use of the Process class. Reversi in C # The game of Reversi in C #.

转载请注明原文地址:https://www.9cbs.com/read-116120.html

New Post(0)