C# Microsoft Speech Agent

    With millions of Web sites out there on the Internet, you’re going to have to think up some pretty innovative ways for your Web site to be noteworthy. And let’s face it, without a Web site that stands out, users won’t stick around and spend much time, or even come back.

   You’re looking for more than just a pretty Web site?there are more important things than just luring people in. A lot of people just plain have trouble reading. And if your Web applications are speech enabled, users won’t have to do too much reading to benefit from the contents. Or how about users who might be seriously visually impaired or blind? By speech-enabling your Web site, even these people can benefit from the contents.

   One more very powerful argument for using these Microsoft Agent technologies in your Web site is that they can provide not only speech, but also animation and interactivity. With them, your Web site visitors can get a guided tour of your site’s products and services. They can ask questions and get answers. They can point to the rise in sales for your company’s chart, which will be much more powerful than a plain graph.

The technology is actually built on ActiveX. Two ActiveX controls provide the Microsoft Agent character, animation, and speech capabilities. These controls are not server-side components, but they are embedded into the HTML and are invoked just as any other ActiveX controls would be in an HTML page.

You need to be aware of a few things before you use the Microsoft Agent components. The first is that the core components must be installed on the client computer before a speech-enabled Web site will work properly. The second thing you must make sure of is that the agent characters have been installed on the computer. And the third thing you must be sure about is that the speech module, which lets the Microsoft Agent components speak through your sound system, is installed.

You can download all the agent requirements from Microsoft Agent home Page:
http://www.microsoft.com/msagent/default.asp

Note: if you have Windows Xp ,or Windows 2000, Microsoft has already being installed on your Computer, You can find it in: C:Windows msagent

You need to Download:
1.Agents, you can download the from :
http://www.microsoft.com/msagent/downloads/user.asp there are 4 characters from Microsoft (Merlin the wizard ,Genie the Genie ,Robby the Robot, Peedy the bird)
Note: that each agent has its own animations ,but there are certain common animation between them, I have included only a sample animations in the project .

and you can download more agents from :
http://www.msagentring.org/ and http://www.agentry.net/

2. Speech engine, you can download the from :
http://www.microsoft.com/msagent/downloads/user.asp#tts

Now let us look at some samples and the code to work with the Microsoft Agent:

Agent Can speak!!!!

  Agent can play an animation!!!

Agent can move!!!

   Now for the code, as you have seen above, these controls (the agent and the speech) are not server-.side components, but they are embedded into the HTML, so you need to write a script to run it.

   What I did here is that I wrote a class Called AgentClass.cs (you will find it with the project attached), which encapsulates the Agent functionality, and here are all the methods used in the class with their functionality

Description  Code Module

Method Name

Causes the Agent character to hide from view.  AgentClass.cs Hide()
Causes the Agent character to show itself.  AgentClass.cs Show()
Uses special values such as AgentCenterX and AgentBottomY to move to screen-relative locations.  AgentClass.cs MoveToSpecial()
Causes the Agent character to speak. AgentClass.cs Speak()
Causes the Agent character to gesture from some predefined gestures. AgentClass.cs Gesture()
Causes the Agent character to go through thinking motions. AgentClass.cs Think()
Causes the Agent character to play an animation.  AgentClass.cs Play()
This is a property. It allows the selection of the Agent character, such as Genie or Merlin.  AgentClass.cs Character()
This causes the Agent class to render the JavaScript to the HttpResponse. AgentClass.cs Render()
This method calls OutputAgentControl() and OutputSpeechControl() so that the objects are emitted into the HTML stream. AgentClass.cs OutputObjects()
This method outputs the Agent control object into the HTML stream.  AgentClass.cs OutputAgentControl()
This method outputs the speech control object into the HTML stream.  AgentClass.cs OutputSpeechControl()
This method calls a number of methods, which in turn emit the JavaScript code for the agent control.  AgentClass.cs OutputScript()
This method emits the script start tag.  AgentClass.cs StartScript()
 This method emits the JavaScript variables.  AgentClass.cs OutputVariables()
This method emits the method that gets the special screen positions that can be used to center the Agent character. AgentClass.cs OutputGetPositions()
This method emits the method that is called when the window loads.   AgentClass.cs OutputOnLoad()
This method emits the method that loads the Agent character.   AgentClass.cs OutputLoadAgent()
This method emits the method that sets the character.  AgentClass.cs OutputSetCharObj()
This method emits the method that checks the load status.  AgentClass.cs OutputCheckLoadStatus()
This method emits the method that shows a load error.  AgentClass.cs OutputLoadError()
This method outputs the method that contains all of the Agent commands.  AgentClass.cs OutputCommands()
This method emits the script end tag.  AgentClass.cs EndScript()

The OutputAgentControl() method simply emits the HTML code that embeds the Agent control ActiveX into the HTML document
You can also see the OutputSpeechControl() method,is the speech object that is emitted into the HTML document that embeds the speech ActiveX controls.

There are a number of methods that a consumer of the Agent class will make. These methods do things such as make the Agent character hide itself, make the Agent character show itself, and move the Agent character around on the screen. Essentially, what happens when these methods are called is that the appropriate Agent JavaScript command is added to the list of commands. The list of commands is contained in a class member variable named m_ScriptList. This object is a StringCollection that is iterated through during the Render process, when the JavaScript is emitted into the HTML stream.
Just to show you how easy it is to use the AgentClass class to create an Agent script, let’s take a look at a simple code snippet. The following example shows how to substantiate an Agent class, make the Agent character show itself, and have the Agent character say something:

Just add the AgentClass.cs to your project and write this code in the page

Note: By default  I  have used Merlin(the wizard) ,if you want to use another one,just add this line of code: ag.setChar( Agent Name); as a string e.g.

ag.setChar( “Genie”);

Example 1:

C#
Agent ag = new Agent();
ag.Show();
ag.Speak( “Hi there!” );
agent.Render(Response);

 

Example 2:

Agent ag = new Agent();
ag.Show();
agent.Play(“Search”);
agent.Render(Response);

You will find more examples in the project attached

Summary – C# MS Speech Agent:

Microsoft Agent characters are a great way to speech-enable your applications and make them come alive. Your applications can become interactive and hold the attention of your users.
Not only will the Agent characters add a lot of spice to your Web site, but they also can add functionality for people with reading and vision problems. This chapter has shown you a class that makes it easy to programmatically add Microsoft Agent characters to your Web site. The class is easy to use, and with it you won’t have any problem taking your application to the next step.

Attachments:

Project File: Speech.zip