Using MS Agent in C#-Part-I(Text To Speech)


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

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.

Up Next
    Ebook Download
    View all
    Learn
    View all