Using MSAgent

来源:互联网 发布:通过网络传大文件 编辑:程序博客网 时间:2024/06/06 16:44

 

In this piece of writing let us see some intriguing characters which speak to us using synthesized speech, recorded audio, or text in a cartoon word balloon. It even support for speech recognition. Let us see in detail.


INTRODUCTION TO MICROSOFT AGENT:

The Microsoft Agent API affords services that support the display and animation of animated characters. Microsoft Agent consists of optional support for speech recognition as a result applications can respond to voice commands. Characters can react using synthesized speech, recorded audio, or text in a cartoon word balloon.

REQUIREMENTS:

To be proficient to use this technology, we must have:

  • The Microsoft Agent Core components.
  • The Microsoft Agent Characters Genie, Merlin, Robby, and Peedy.
  • The Microsoft Speech API 4.0a runtime.
  • he Microsoft Speech Recognition Engine.
  • The Lernout and Hauspie Text-to-Speech engines for at least US English.

All these components are available from

  • http://microsoft.com/products/msagent/downloads.htm.

SKETCH OF SPEECH TECHNOLOGIES:

Text-to-speech is the capability of a computer to translate text information into synthetic speech output. Speech recognition is the capability of a computer to recognize the spoken word for the purpose of receiving command and data input from the speaker.

Speech recognition and text-to-speech make use of engines, which are the programs that do the real work of recognizing speech or playing text. Nearly all speech-recognition engines translate incoming audio data to engine-specific phonemes, which are then interpreted into text that an application can use. (A phoneme is the smallest structural unit of sound that can be used to distinguish one utterance from another in a spoken language.)

TWO TYPES OF TEXT-TO-SPEECH:

  1. Synthesized text-to-speech
  2. Concatenated text-to-speech.

SYNTHESIZED TEXT-TO-SPEECH:

In Synthesized speech the words are examined and produce the phonetic pronunciations for the words. The phonemes are then moved into a complex algorithm that imitates the human vocal tract and produce the sound.

CONCATENATED TEXT-TO-SPEECH:

In Concatenated text-to-speech it studies the text and pulls recordings, words, and phrases out of a prerecorded library. The digital audio recordings are concatenated.

SPEECH APPLICATION PROGRAMMING INTERFACE:

The Microsoft Speech Application Programming Interface (API) uses the OLE Component Object Model (COM) architecture under Win32 (Windows 95 and Windows NT). Microsoft Agent's architecture uses Microsoft SAPI for synthesized speech output. Microsoft Agent uses the Microsoft Speech Application Programming Interface (SAPI) to support speech input (speech recognition, or SR) and speech output (text-to-speech, or TTS). Microsoft Agent describes interfaces that permit applications to access its services, enabling an application to control the animation of a character, support user input events, and specify output.

THE CHARACTER WINDOW:

In Microsoft Agent applications the animated characters are displayed in their individual windows that always appear at the top of the window z-order. A user can move a character's window by dragging the character with the left mouse button. The character image moves with the pointer.

THE WORD BALLOON:

In addition to spoken audio output, the character also supports textual captioning in the form of text output in cartoon-style word balloons. Words show in the balloon as they are spoken. The balloon hides from view when spoken output is completed.

MICROSOFT AGENT IN WEB PAGES:

To use the Microsoft Agent services in a Web page, use the HTML <OBJECT> tag within the <HEAD> or <BODY> element of the page, specifying the Microsoft CLSID (class identifier) for the control. In addition, use a CODEBASE parameter to specify the location of the Microsoft Agent installation file and its version number.

We can use Vbscript,JavaScript and JScript to program the Microsoft Agent in Web pages.

USING MICROSOFT AGENT WITH THE .NET FRAMEWORK:

Microsoft Agent is available as an ActiveX control DLL. To utilize it within .NET, you can use the AxImp.exe utility provided with the .NET Framework SDK.

AxImp -->> ActiveX Control to Win Forms Assembly Generator.
Syntax: AxImp [/? | [[/source] OCXName]]

Aximp agentctl.dll

The above command creates two files namely AxAgentObjects.dll and AgentObjects.dll. With the use of above two files we are now geared up to utilize Agent with .NET.

MICROSOFT AGENT IN C#:

To use Msagent in C# we have to add two DLL files AxAgentObjects.dll and AgentObjects.dll in our program. To load the character the code is simple.

AxAgent.Characters.Load("Genie",(object)"C:/Windows/Msagent/chars/GENIE.acs");
Character = AxAgent.Characters["Genie"];
//To set the language to US English.
Character.LanguageID = 0x409;
//This code displays the character.
Character.Show(null);

To speak some Text the code is as follows:

Character.Speak ("Welcome you sir VISIT www.onlinecsharpteach.netfirms.com", null);

Now let us see an example:

EXAMPLE:

AxAgent.Characters.Load("Genie",(object)"C:/Windows/Msagent/chars/GENIE.acs");
Character = AxAgent.Characters["Genie"];
//To set the language to US English.
Character.LanguageID = 0x409;
//This code displays the character.
Character.Show(null);

using
 System;
using System.Drawing;
using System.WinForms;
using AgentObjects;
public class Hello: Form
{
private System.ComponentModel.Container components;
private System.WinForms.Button button2;
private System.WinForms.Button button1;
private System.WinForms.TextBox textBox1;
private AxAgentObjects.AxAgent AxAgent;
private IAgentCtlCharacterEx Character;
public Hello()
{
InitializeComponent();
}
public static void Main(string[] args)
{
Application.Run(
new Hello());
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.button1 = new System.WinForms.Button();
this.button2 = new System.WinForms.Button();
this.textBox1 = new System.WinForms.TextBox();
this.AxAgent = new AxAgentObjects.AxAgent();
AxAgent.BeginInit();
button2.Click += 
new System.EventHandler(button2_Click);
button1.Location = 
new System.Drawing.Point(88, 208);
button1.BackColor = (System.Drawing.Color)System.Drawing.Color.FromARGB((
byte)255, (byte)128,
(
byte)128);
button1.Size = 
new System.Drawing.Size(152, 32);
button1.TabIndex = 1;
button1.Text = "Load character";
button2.Location = 
new System.Drawing.Point(120, 240);
button2.BackColor = (System.Drawing.Color)System.Drawing.Color.FromARGB((
byte)255, (byte)128,
(
byte)128);
button2.Size = 
new System.Drawing.Size(96, 24);
button2.TabIndex = 2;
button2.Text = "SPEAK";
textBox1.Location = 
new System.Drawing.Point(48, 8);
textBox1.Text = " ";
textBox1.Multiline = 
true;
textBox1.TabIndex = 0;
textBox1.Size = 
new System.Drawing.Size(248, 200);
textBox1.BackColor = (System.Drawing.Color)System.Drawing.Color.FromARGB((
byte)255, (byte)128,
(
byte)128);
this.Text = "MSAGENT DEMO";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.WindowState = System.WinForms.FormWindowState.Maximized;
this.BackColor = (System.Drawing.Color)System.Drawing.Color.FromARGB((byte)255, (byte)192,
(
byte)192);
this.ClientSize = new System.Drawing.Size(344, 301);
this.Controls.Add(button2);
this.Controls.Add(button1);
this.Controls.Add(textBox1);
this.Controls.Add(AxAgent);
button1.Click += 
new System.EventHandler(button1_Click);
AxAgent.EndInit();
}
protected void button2_Click(object sender, System.EventArgs e)
{
if(textBox1.Text.Length == 0)
return;
Character.Speak(textBox1.Text, 
null);
}
protected void button1_Click(object sender, System.EventArgs e)
{
OpenFileDialog openFileDialog = 
new OpenFileDialog();
openFileDialog.AddExtension = 
true;
openFileDialog.Filter = "Microsoft Agent Characters (*.acs)|*.acs";
openFileDialog.FilterIndex = 1 ;
openFileDialog.RestoreDirectory = 
true ;
if(openFileDialog.ShowDialog() != DialogResult.OK)
return;
try { AxAgent.Characters.Unload("CharacterID"); }
catch { }
AxAgent.Characters.Load("CharacterID", (
object)openFileDialog.FileName);
Character = AxAgent.Characters["CharacterID"];
Character.LanguageID = 0x409;
Character.Show(
null);
Character.Play ("announce");
Character.Speak ("welcome you sir",
null);
}
}

OUTPUT:




CONCLUSUON:

The Microsoft Agent API offers services that support the display and animation of animated characters. Implemented as an OLE Automation (Component Object Model [COM]) server, Microsoft Agent facilitates multiple applications, called clients or client applications, to host and access its animation, input, and output services at the same time.

 

 

 

 

 

 

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 userAfter 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 NewProject. 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

 Collapse
namespace WindowsApplication1{    /// <summary>    /// Summary description for Form1.    /// </summary>    public class Form1 : System.Windows.Forms.Form    {           private AxAgentObjects.AxAgent axAgent1;           /// <summary>           /// Required designer variable.           /// </summary>           private System.ComponentModel.Container components = null;            public Form1()           {                   //                   // Required for Windows Form Designer support                   //                   InitializeComponent();                    //                   // TODO: Add any constructor code                    // after InitializeComponent call                   //           }

Now create object of type AgentObjects.IAgentCtlCharacter and name this object speaker ,now at the load function write the following

 Collapse
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 charater location");                   }           }

In the speak button click function write the following code

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

 Collapse
//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  ,Writing ,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, Pleased, GetAttentionContinued, Process, Search, Think,Idle1_4,Greet,Idle3_1,GestureUp,GestureDown,GestureLeft,GestureRight,Show,Hide,Hearing_4,Hearing_1,Hearing_2,Hearin,Alert,Explain,Processing,Thinking,Searching,Acknowledge*********************/

The full code

 Collapse
using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.IO; namespace WindowsApplication1{    /// <summary>    /// Summary description for Form1.    /// </summary>    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;           /// <summary>           /// Required designer variable.           /// </summary>        private System.ComponentModel.Container components = null;            public Form1()           {                   //                   // Required for Windows Form Designer support                   //                   InitializeComponent();                    //                   // TODO: Add any constructor code after                    // InitializeComponent call                   //           }         /// <summary>           /// Clean up any resources being used.           /// </summary>           protected override void Dispose( bool disposing )           {                   if( disposing )                   {                           if (components != null)                            {                                  components.Dispose();                           }                   }                   base.Dispose( disposing );           }            #region Windows Form Designer generated code           /// <summary>           /// Required method for Designer support - do not modify           /// the contents of this method with the code editor.           /// </summary>           private void InitializeComponent()           {                   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);            }           #endregion            /// <summary>           /// The main entry point for the application.           /// </summary>           [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 charater 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

 

 

From:

http://www.c-sharpcorner.com/UploadFile/ggaganesh/UsingMSAgentinCSharpPartITextToSpeech11232005003127AM/UsingMSAgentinCSharpPartITextToSpeech.aspx

http://www.codeproject.com/KB/cs/usemsagentcsharp.aspx

 

原创粉丝点击