Wednesday, July 10, 2013

Using Microsoft Agent in Windows 7

By default, Microsoft no longer supports Microsoft Agent in Windows 7. However, i managed to find the following open source alternative

http://doubleagent.sourceforge.net/

C# developer can ask the user to install this software to have the microsoft agents running on Window 7 and to have their winforms application invoke them. As this alternative is also based on ActiveX control, it is important to check the availability of the control on the user's computer within the coding to ensure that the application won't crash on the user's computer. To use this, declare the following variable in the winform:

private DoubleAgent.Control.Control msDoubleAgent = null;

In the winform's Load event, try to perform the initialization:

  try
            {
                msDoubleAgent=new DoubleAgent.Control.Control();
                msDoubleAgent.Characters.Load("Genie", Path.Combine(Application.StartupPath, "Genie.acs")));
}
            catch (Exception ex)
            {
                log.Error(ex.ToString());
            }


Now can define methods such as a the following that invokes the agent to speak or perform animation:

  public void ShowExplanation(string message)
        {
                try
                {
                    if (msDoubleAgent != null && msDoubleAgent.Characters["genie"] != null)
                    {
                        DoubleAgent.Control.Character agent = msDoubleAgent.Characters["genie"];
                        agent.Speak(message);
                    }
                    else
                    {
                        MessageBox.Show(message);
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.ToString());
                }
        }

 private void PlayAgentAnimation(string animation)
        {
                try
                {
                    if (msDoubleAgent != null && msDoubleAgent.Characters["genie"] != null)
                    {
                        DoubleAgent.Control.Character agent = msDoubleAgent.Characters["genie"];
                        agent.StopAll();
                        agent.Play(animation);
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.ToString());
                }
        }

Note that the above code will always be degradable (that is, if the microsoft agent or double agent does not install on the user's computer, the application software will still function correctly).

No comments:

Post a Comment