Click here to Skip to main content
15,885,914 members
Articles / Programming Languages / Visual Basic
Article

The Usage of Microsoft Agent Control in VB.NET Applications

Rate me:
Please Sign up or sign in to vote.
4.29/5 (15 votes)
5 Oct 20053 min read 80K   2.2K   42   3
How to use Microsoft Agent Control in your VB.NET applications to make them more interactive.

Image 1

Introduction

Microsoft Agent is a technology used to add interactive animated characters to Windows applications.

When you use the Microsoft Agent control, you can access four predefined characters which are Genie, Merlin, Peedy, and Robby. Each character has a different set of animations.

The Microsoft Agent control uses a text-to-speech engine and speech recognition engines. When the user speaks, the control uses a speech recognition engine and translates the input sound into computer understandable form. In the mean time, the control uses a text-to-speech engine to generate the characters to speak the words which are typed in by the user.

Background

In this article, the character "Peedy" and a text-to-speech engine are used. Because of that, you will need to download the necessary files from the Microsoft web site to run this sample application. Moreover, if you are thinking of developing Windows applications using this control, you will need these files. You can download these files from the link below:

You need to download the "Microsoft Agent character file" (if you need to run the sample in this article alone, you only need "Peedy.exe", but you can download the other character files for future application development), "Text-to-Speech engine file", and also you might need the "SAPI 4.0 runtime file".

If you want to use the speech recognition feature of the control in your future application development, you will need the "Speech recognition engine file" as well.

You can find all these downloadable files from the link above.

Implementation

In this section, I have tried to give a brief description of the procedures which are used in the sample application.

The code for Form Load

In this procedure, we are loading the character "Peedy" and filling the combo box with its animation types. Because, we will select the animation type from the combo box and animate the character while we are running the sample program. Note that if you would like to use another character, you should change the parameter "Peedy" to "Genie"/"Merlin"/"Robby" in this procedure. Moreover, you will need one more change. It is for the content of the text box that shows the location of an agent control file in your hard drive. For example, if you use the character "Genie", the program will need "Genie.acs" file and you should change the content of the text box to "C:\WINDOWS\msagent\chars\Genie.acs". That's all you for this!

VB
Private Sub Form1_Load(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles MyBase.Load

    AxAgent1.Characters.Load("Peedy", TextBox2.Text)
    'Set current character to Peedy and show it
    mSpk = AxAgent1.Characters("Peedy")

    Dim Enume As IEnumerator = _
      AxAgent1.Characters.Character(mSpk.Name).AnimationNames.GetEnumerator()

    While Enume.MoveNext
        ComboBox1.Items.Add(Enume.Current)
    End While

    'To show the first event name instead of the text "Combobox1"
    ComboBox1.Text = ComboBox1.Items.Item(0)
End Sub

The code for "Show" button

VB
Private Sub Button1_Click(ByVal sender As System.Object, _
          ByVal e As System.EventArgs) Handles Button1.Click
    mSpk.Show(0)
End Sub

The code for "Hide" button

VB
Private Sub Button4_Click(ByVal sender As System.Object, _
           ByVal e As System.EventArgs) Handles Button4.Click
    mSpk.Hide()
End Sub

The code for "Exit" button

VB
Private Sub Button5_Click(ByVal sender As System.Object, _
           ByVal e As System.EventArgs) Handles Button5.Click
    End
End Sub

The code for "Animate" button

In this procedure, the program makes the character to play selected animations in the combo box.

VB
Private Sub Button2_Click(ByVal sender As System.Object, _
               ByVal e As System.EventArgs) Handles Button2.Click
    'Stop the previous action to start new one
    mSpk.Stop()
    'Play the new action
    mSpk.Play(ComboBox1.Text)
    'Turn to rest position
    mSpk.Play("RestPose")
End Sub

The code for "Talk" button

In this procedure, the program makes the character to speak typed words in the text box. Note that you can change the text while the program is running.

VB
Private Sub Button3_Click(ByVal sender As System.Object, _
                ByVal e As System.EventArgs) Handles Button3.Click
    'Stop the previous action to start new one
    mSpk.Stop()
    'Speak the text
    mSpk.Speak(TextBox1.Text)
End Sub

The code for "MOVE HERE" button

In this procedure, the program makes the character to move to the position of the current mouse pointer.

VB
Private Sub Button6_Click(ByVal sender As System.Object, _
             ByVal e As System.EventArgs) Handles Button6.Click
    'Stop the previous action to start new one
    mSpk.Stop()
    'Let the character to move to the position of current mouse pointer
    mSpk.MoveTo(Convert.ToInt16(Cursor.Position.X - 60), _
                Convert.ToInt16(Cursor.Position.Y - 60))
End Sub

Do not forget, these characters' speech are sensitive to punctuation marks such as ",", "?", "!",...etc. Try and enjoy!..

Important Points

  • Before you run the sample application or develop your own application, you should install the necessary files which are described in the Background section.
  • Before you start to write your own code, you should add "Microsoft Agent control 2.0" into your toolbox and then to your form.

Last Words!

In your applications, you can use your creativity and features of these characters to make more interactive applications.

Have a nice day!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Instructor / Trainer
Turkey Turkey
Asst. Prof. in Eastern Mediterranean University.

Comments and Discussions

 
Questionmultilanguage support how? Pin
29181195-Mar-09 1:57
29181195-Mar-09 1:57 
Questionhow to keep the caracter inside a child form or a label Pin
jathoo20-Oct-07 5:41
jathoo20-Oct-07 5:41 
QuestionMs agent speech recognition [modified] Pin
amitairos21-Aug-06 23:47
amitairos21-Aug-06 23:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.