Home arrow C# arrow Page 4 - Working With Speech Using the MSAgent in C#
C#

Working With Speech Using the MSAgent in C#


Did you know that you can use characters like the animated Microsoft Office paperclip in your own applications? In this article Gnana shows us how, using the MSAgent control and C#...

Author Info:
By: Gnana Arun Ganesh
Rating: 5 stars5 stars5 stars5 stars5 stars / 31
December 22, 2002
TABLE OF CONTENTS:
  1. · Working With Speech Using the MSAgent in C#
  2. · Introducing the Microsoft Agent
  3. · Microsoft Agent in C#
  4. · Speech Recognition
  5. · Conclusion

print this article
SEARCH DEVARTICLES

Working With Speech Using the MSAgent in C# - Speech Recognition
(Page 4 of 5 )

Overview of Speech Recognition
Speech recognition and text-to-speech use engines, which are the programs that do the actual work of recognizing speech or playing text. Most speech-recognition engines convert incoming audio data to engine-specific phonemes, which are then translated into text that an application can use.

Speech recognition is a bit more complex to categorize than text-to-speech.
Every speech recognition engine has three characteristics:
  1. Continuous vs. discrete: In continuous speech recognition, clients can speak to the system naturally. In discrete, clients are required to leave a gap between each word. Clearly, continuous recognition is desired over discrete recognition, but continuous recognition needs more processing power.
  2. Vocabulary size: Speech recognition can support a small or large vocabulary. Small-vocabulary recognition permits users to give simple commands to their computers. To dictate text, the system must have a large-vocabulary recognition.
  3. Speaker Dependence: Speaker-independent speech recognition works properly without any training, while speaker-dependent systems require that each user spend about 30 minutes training the system to his or her voice.
MSAgent uses "Command and Control" speech recognition, which is continuous, small vocabulary that is speaker independent. Users can create several hundred different commands or phrases. If a user says a command that is not in the list, the speech-recognition system will return either "not recognized," or will think it heard a similar-sounding command. Because users of command and control can only say specific phrases, the phrases must be either visible on the screen -- so intuitive that all users will know what to say -- or users must learn which phrases they can say.

The Commands Window
If an attuned speech engine is installed, Microsoft Agent supplies a special window called the commands window that shows the commands that have been voice-enabled for speech recognition. The commands window serves as a visual prompt for what can be spoken as input.

The Listening Tip
If speech is enabled, a special tool tip window appears when the user presses the push-to-talk key to begin voice input. The Listening Tip displays contextual information associated to the current input state.

Speech Recognition in C#
We need to add commands using some C# code. Continuing on from our previous example, we could do so like this:

Character.Commands.Add("Who is your Master?",
(object)"Who is your Master?",
(object)"(Your(Master| Administrator))",
(object)true,
(object)true);


Similarly, from the below code, we can see that we can make commands based on user input. For example, if we ask "Who is your Master?" to the character it responds to us with an answer. We can create any number of commands:

IAgentCtlUserInput ui;
ui = (IAgentCtlUserInput)e.p_userInput;
if(ui.Name == "Who is your Master?")
{

Character.Play ("Pleased");
Character.Speak((object)"My Master name is G.GNANA ARUN GANESH." +
" You can contact him through his mail ggarung@rediffmail.com.", null);

}


Here's a complete example that integrates speech recognition using C# and the MSAgent control:

using System;
using System.Drawing;
using System.WinForms;
using AgentObjects;

public class Speech : 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 Speech()
{
InitializeComponent();
}

public static void Main(string[] args)
{
Application.Run(new Speech());
}

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

AxAgent.Command += new
AxAgentObjects._AgentEvents_CommandEventHandler(AxAgent_Command);

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.Commands.Caption = "Sample Commands";

Character.Commands.Add("Who is your Master?",
(object)"Who is your Master?",
(object)"(Your(Master| Administrator))",
(object)true,
(object)true);

Character.Commands.Add("Exit",
(object)"Exit",
(object)"(exit | close | quit)",
(object)true,
(object)true);

Character.Play ("announce");
Character.Speak ("Welcome",null);

}

protected void AxAgent_Command(object sender, AxAgentObjects._AgentEvents_CommandEvent e)
{
IAgentCtlUserInput ui;
ui = (IAgentCtlUserInput)e.p_userInput;
if(ui.Name == "Who is your Master?")
{

Character.Play ("Pleased");
Character.Speak((object)"My Master name is G.GNANA ARUN GANESH." +
" You can contact him through his mail ggarung@rediffmail.com.", null);

}
if(ui.Name == "Exit")
{
Character.Speak((object)"Good bye", null);

Character.Play("Wave");
Character.Play("Hide");
}
}

}


The output from our sample application looks like this:

Output from our speech recognition app
blog comments powered by Disqus
C# ARTICLES

- Introduction to Objects and Classes in C#, P...
- Visual C#.NET, Part 1: Introduction to Progr...
- C# - An Introduction
- Hotmail Exposed: Access Hotmail using C#
- Razor Sharp C#
- Introduction to Objects and Classes in C#
- Making Your Code CLS Compliant
- Programming with MySQL and .NET Technologies
- Socket Programming in C# - Part II
- Socket Programming in C# - Part I
- Creational Patterns in C#
- Type Conversions
- Creating Custom Delegates and Events in C#
- Inheritance and Polymorphism
- Understanding Properties in C#

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials