Using Microsoft Agent's TTS in C #

Source: Internet
Author: User
Tags html tags ole sapi client
Introduction to Microsoft Microsoft Agent

The Microsoft Agent API can provide a display of cartoon characters, and it can also support speech recognition, so applications can respond to voice commands, and cartoon characters can respond to commands through synthesized speech, recorded audio signals, or text.

Requirements for using the Microsoft Agent

To use this technique, we must have the following components:

• Microsoft Agent Core Components

• Cartoon characters in Microsoft Agent ━━genie, Merlin, Robby and Peedy

• Microsoft speech API 4.0a run Time Library

• Microsoft speech recognition engine

· Lernout and Hauspie text-speech engine

All of the above components can be downloaded from the http://microsoft.com/products/msagent/downloads.htm.

Introduction to Speech technology

Text-Speech conversion refers to the computer to convert text information into synthetic speech for output, speech recognition refers to the computer can recognize the speaker said, accept the speaker's command and input data.

Both speech recognition and text-speech conversion require an associated engine, and almost all speech recognition engines convert incoming speech data into phonemes related to a particular engine, and these phonemes are converted to text that the application can use.

Text-speech conversion in two ways:

1, synthetic text-speech conversion

2, continuous text-speech conversion

Synthetic text-Speech conversion:

In the synthesized method of pronunciation, the engine processes each word and produces the phonetic phoneme of the word, and then these phonemes are transferred into a complex algorithm that mimics the human voice and generates speech.

Continuous text-Speech conversion Mode:

In continuous text-speech conversion, the engine processes text information and finds sentences, words, and phrases from a pre-recorded voice library, in which the generated speech is continuous.

programming interfaces for voice applications

The Microsoft Voice Application programming interface uses the OLE Component Object mode (COM) architecture under WIN32 (Windows 95, Windows NT), and Microsoft's agent architecture uses the Microsoft Voice Application programming Interface (SAPI) in the synthesized speech output. Also uses SAPI to support speech input (speech recognition SR or text-to-speech TTS). The Microsoft Agent defines the interfaces that allow applications to access their services, allowing applications to control role animations, support user input events, and specify the output mode.

Role window

In the Microsoft Agent application, the cartoon characters are displayed in their respective windows, which always appear at the top of the z-order. The user can drag the role's window through the left mouse button, and the image of the role moves with the pointer.

Talking Balloon Ring

In addition to the voice output, the animated character also supports the type of speech in the form of a cartoon, the characters speak, the words appear in the balloon, when the end of the balloon circle is gone.

Using Microsoft Agent on Internet Web pages



To use the Microsoft Agent service on Internet Web pages, you can use HTML tags in web pages or elements, specify the control CLSID (class identifier), and also use the CODEBASE parameter to specify the location and version number of the Microsoft Agent's installation files.

We can use VBScript, JavaScript, and JScript to use Microsoft Agents on Internet Web pages.

Using the Microsoft Agent in the. NET Architecture

The Microsoft Agent is not provided in the form of an ActiveX control DLL. To be in. NET, you can use it by using the. NET Framework SDK provides AxImp.exe tools:

AxImp-->> ActiveX control-win form Assembly builder

Syntax:aximp [/? | [[/source] ocxname]]

AxImp Agentctl.dll

The above command generates two files: AxAgentObjects.dll and AgentObjects.dll. By using these two files, we can use the. NET, using the agent.


Microsoft Agent in C #:

To use Microsoft Agent in C #, we must add two DLL files to the program: AxAgentObjects.dll and AgentObjects.dll. The code that loads the animation role is fairly straightforward:

AxAgent.Characters.Load ("Genie", (object) "C:/windows/msagent/chars/genie.acs");

Character = axagent.characters["Genie"];

file://sets the language to American English

Character.languageid = 0x409;

file://the line code to display the role

Character.show (NULL);


The code that lets the character speak is as follows:

Character.speak ("Welcome You sir VISIT www.onlinecsharpteach.netfirms.com", null);

Let's take a look at the following example:

The Example:




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), (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:

Conclusion:

The Microsoft Agent API provides services that support animated role display, and when configured as an OLE Automation (COM) server, it enables multiple applications called client or client applications to host or use their animation, input, and output services.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.