在 C#.NET 中使用 Microsoft Agent 的播报器






4.42/5 (17投票s)
2003年6月12日
2分钟阅读

167993

4507
一个用于播报消息、唱歌和讲笑话的工具。
图片 1. 我是 Genie(精灵)
图片 2. 我是 Merlin(梅林)
图片 3. 我是 Peedy(皮迪)
图片 4. 我是 Robby(罗比)
概述
Microsoft® Agent 是一种软件技术,它可以实现一种更丰富的用户交互方式,从而使使用和学习使用计算机变得更容易和更自然。 Microsoft® Agent 是一组可编程的软件服务,支持在 Microsoft Windows® 界面中呈现交互式动画角色。我正在使用 Microsoft® Agent 来开发这个播报器。我在这里使用了四种类型的播报员。它们是 Genie、Merlin、Peedy 和 Robby。 更多信息.. http://www.microsoft.com/msagent/default.asp。
此类演示了以下命名空间的使用。
using System.Runtime.InteropServices
using System.Reflection
AgentServerObjects
AgentObjects
需要的东西,在哪里获取以及如何安装
- 您必须添加引用 AgentObjects.dll 和 AgentServerObjects.dll。您可以从 F:\Program Files\Microsoft Visual Studio .NET\ FrameworkSDK\Samples\Technologies\Interop\Applications\MSAgent\AgentExplorer 获取这两个 DLL。请记住,您已将 .NET 安装在 F: 中。
或者直接转到 F:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Samples\Technologies\Interop\Applications\MSAgent\Hello1 并查看 me.htm 文件,了解如何获取这些 DLL。您只需输入
nmake all
。此命令将在 hello1 文件夹中创建 AgentObjects.dll 和 AgentServerObjects.dll。或者直接使用此安装程序中的那些 DLL。我已经将这些 DLL 与此安装程序绑定在一起。
确保 bin 调试/发布文件夹中有这 2 个 DLL,并在您的项目中添加到解决方案资源管理器中。
- 我们必须将 .acs 放在调试或发布文件夹中。如果 .acs 文件不存在,播报器将显示错误。您可以从以下位置获取四个 .acs 文件
http://www.microsoft.com/msagent/downloads/user.asp。在那里您可以获得 Genie、Merlin、Peedy 和 Robby,Microsoft agent 角色文件 (.acs)
并放入 release 或 debug 文件夹中。
- 只需下载并打开 MicrosoftAgentApplication.sln 文件即可使用它。
在运行此程序之前,您必须安装文本到语音引擎。 从此处下载文本到语音引擎 tv_enua.exe 美国英语 - 1 MB http://www.microsoft.com/msagent/downloads/user.asp。 由于大小限制,我无法将其添加到我的演示设置中。
只需单击 tv_enua.exe 进行安装。 然后播报器就可以播报任何内容、唱歌和讲笑话了。
源代码
我提供了示例代码来使用它。
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel;
using System.Runtime.InteropServices;
using AgentObjects;
using AgentServerObjects;
在我们制作一个函数来创建错误文件之前,我们必须声明一些将在我们的函数中使用的变量。 这是一个变量声明的示例,主函数是 ErrorRoutine
。
AgentServer Srv = new AgentServer(); //Create a agent server
//If unable to create show the error
if (Srv == null)
{
MessageBox.Show("ERROR: Agent Server couldn't be started!");
}
IAgentEx SrvEx;
// The following cast does the QueryInterface to
//fetch IAgentEx interface from the IAgent interface,
//directly supported by the object
SrvEx = (IAgentEx) Srv;
// First try to load the default character
int dwCharID=0, dwReqID=0;
try
{
// null is used where VT_EMPTY variant is expected by the COM object
String strAgentCharacterFile = null;
//Check microsoft agent character filename(.acs) is empty
if (!strFileName.Equals(string.Empty))
{
//Get the acs path
strAgentCharacterFile = strPath + strFileName;
}
else
{
MessageBox.Show("Select Style");
return;
}
if (!TxtSpeakInput.Text.Equals(string.Empty))
{
//load the acs file
SrvEx.Load(strAgentCharacterFile, out dwCharID, out dwReqID);
}
else
{
MessageBox.Show("Enter Text");
return;
}
}
catch (Exception)
{
MessageBox.Show("Failed to load Agent character! Exception details:");
}
IAgentCharacterEx CharacterEx=null;
SrvEx.GetCharacterEx(dwCharID, out CharacterEx);
//CharacterEx.SetLanguageID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
// Show the character. The first parameter tells Microsoft
// Agent to show the character by playing an animation.
CharacterEx.Show(0, out dwReqID);
// Make the character speak
// Second parameter will be transferred to the COM object as NULL
CharacterEx.Speak(TxtSpeakInput.Text, null, out dwReqID);
}
在这里,我们可以选择不同的播报员并输入不同的文本来朗读。 试试看。 它很简单易用。
我们可以创建我们自己的角色文件。 只需访问 http://www.microsoft.com/msagent/downloads/user.asp 以探索更多信息..