TTS using Microsoft Agent in C #

Source: Internet
Author: User
Tags sapi

Introduction to Microsoft Agent

The Microsoft Agent API can display cartoon roles. In addition, it can also support speech recognition. Therefore, application software can respond to voice commands, the cartoon character can respond to commands through the synthesized speech, recorded audio signal, or text.

Requirements for using Microsoft Agent

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

· Microsoft Agent Core Components

· Cartoon roles including zookeeper genie, Merlin, Roby, and peedy in Microsoft Agent

· Microsoft Speech API 4.0a Runtime Library

· Microsoft Speech Recognition Engine

· Lernout and Hauspie text-Speech Engine

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

Introduction to speech technology

Text-speech conversion refers to the computer's ability to convert text information into synthetic speech for output. Speech Recognition refers to the computer's ability to recognize what the speaker says and accept the speaker's commands and input data.

Speech recognition and text-to-speech conversion require related engines. Almost all speech recognition engines convert input speech data to phoneme related to specific engines, the phoneme is then converted into text that can be used by the application.

Text-speech conversion methods:

1. Synthesize text-speech conversion

2. Continuous text-speech conversion

Text synthesis-speech conversion method:

In the speech synthesis mode, the engine processes each word and generates the phoneme of the word. Then these phoneme are transferred into a complex algorithm to mimic the human voice mode and generate a speech.

Continuous text-speech conversion method:

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

Voice Application Programming Interface

Microsoft Speech Application Programming Interface uses the OLE Component Object Mode (COM) architecture in Win32 (Windows 95, Windows NT, microsoft's agent architecture uses the Microsoft Speech Application Programming Interface (SAPI) in the synthesis speech output, and also uses SAPI to support speech input (Speech Recognition Sr or text-speech conversion TTS ). Microsoft's agent defines an interface for applications to access their services, so that applications can control role animation, support user input events, and specify the output mode.

Role window

In Microsoft Agent applications, cartoon roles are displayed in their respective windows, which always appear at the top of the Z axis order. You can move the role's window by clicking the left mouse button. The role's image moves with the pointer.

Talking balloon sphere

In addition to voice output, an animated role also supports text subtitles in the form of a cartoon balloon. When the role speaks, the words are displayed in the balloon, the balloon ring will disappear.

Use Microsoft Agent in Internet webpages

To use the Microsoft Agent service on an Internet webpage, you can use the HTML tag in the webpage or element to specify the controlled CLSID (Class Identifier). In addition, you also need to use the codebase parameter to specify the location and version number of the Microsoft Agent installation file.

We can use VBscript, JavaScript, and JScript to use Microsoft Agent on Internet webpages.

Use Microsoft Agent in. Net Architecture

Microsoft Agent is not provided in the form of ActiveX Control DLL. You can use the aximp.exe tool of the .netframework sdk.pdf to use the Plugin in .net:

Aximp --> ActiveX Control-win form combination Generator

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

Aximp agentctl. dll

The preceding command generates two files: axagentobjects. dll and agentobjects. dll. By using these two files, we can use the agent in. net.


Microsoft Agent in C #:

To use Microsoft Agent in C #, we must add two DLL files in the program: axagentobjects. dll and agentobjects. dll. The code for loading an animation role is quite simple:

Axagent. characters. Load ("Genie", (object) "C:/Windows/msagent/chars/genie. ACS ");

Character = axagent. characters ["Genie"];

File: // set the language to American English

Character. languageid = 0x409;

File: // This line of code displays the role

Character. Show (null );

The code for the role to speak is as follows:

Character. Speak ("Welcome you Sir visit www.onlinecsharpteach.netfirms.com", null );

Here is an 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;

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. Fig. 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. Fig. 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 (button#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 button#click (Object sender, system. eventargs E)

{

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:

Microsoft's agent API provides a service that supports displaying animated roles. When configured as an OLE Automation (COM) server, it enables multiple applications called client or client applications to simultaneously host or use their animation, input, and output services.
 

Related Article

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.