C#
  Home arrow C# arrow Page 3 - Working With Speech Using the MSAgent in C...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

Working With Speech Using the MSAgent in C#
By: Gnana Arun Ganesh
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 12
    2002-12-22

    Table of Contents:
  • Working With Speech Using the MSAgent in C#
  • Introducing the Microsoft Agent
  • Microsoft Agent in C#
  • Speech Recognition
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Working With Speech Using the MSAgent in C# - Microsoft Agent in C#


    (Page 3 of 5 )

    To use MSAgent in C#, we have to add two DLL files to our project: AxAgentObjects.dll and AgentObjects.dll. The code to actually create and load an MSAgent character 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);

    // Speak some text
    Character.Speak ("Hello, how are you?",null);


    Let's now look at a complete working example written in C#:

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

    }

    }


    The output from our simple MSAgent C# application looks like this:

    The output from our application

    More C# Articles
    More By Gnana Arun Ganesh


     

    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#






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT