ms agent 中精灵小不懂听不懂我说话。。怎么办,是语言=引擎的...

在C#下用Microsoft Agent创建超酷语言精灵(附图)_老文章_赛迪网
在C#下用Microsoft Agent创建超酷语言精灵(附图)
在C#下用Microsoft Agent创建超酷语言精灵(附图)
发布时间: 17:46&&&&&&&&来源:&&&&&&&&作者:
【打印版本】&&【推荐给朋友】
在C#下用Microsoft Agent创建超酷语言精灵(附图)
C#作为Microsoft .Net战略下的新兴语言,有其不可比拟的强大功能。作为一种RAD语言,它有Visual Basic快速开发应用程序的优点,又不乏C++语言的面相对象的优良特性。
本文就通过介绍利用Microsoft Agent来创建一个超酷用户界面(就像office2000那种办公助手的界面,并有语音朗读功能)来向大家展示一下用C#进行Windows应用程序快速开发的优点。
微软的office2000中用到了一些被称为“办公助手”(office Assistance)的精灵来给用户提供帮助,这样做的效果是显而易见的,大家可以得到很有效的帮助并且使用户界面显得非常友好。现在,我们只要使用Microsoft Agent(基于COM),我们就可以在自己的程序中使用这种精灵来给程序增光添彩。用这种精灵,我们可以实现语音的朗读、表演动画甚至还可以实现语音识别呢!
(1)微软公司视窗2000服务器版或视窗 XP 版
(2).Net FrameWrok SDK Beta 2版
(3)Microsoft Agent核心组建
(4)Microsoft Agent的精灵:吉尼(Genie)、么林(Merlin)、罗比(Robby)和皮蒂(Peedy)
(5)至少有一个英语的Text-to-Speech引擎(现在还找不到中文的)
(6)微软运行时发音API4.0a
(如果还要实现语音识别功能的话,还要有微软的语音识别引擎)
所有这些都可以在/msagent/downloads.htm下载。另外,必须要***office2000(office97是不行的)。
三 实现方法
1.打开VS.Net,新建一个工程,不妨取名为CoolUI。图示如下:
2.创建用户界面。
选择菜单:工具-&自定义工具箱,并选择Microsoft Agent Control 2.0组件,图示
将Microsoft Agent Control控件添加到窗体上(在程序运行时是看不到窗体是的Microsoft Agent控件的,只有在设计界面时它才显示出来),并课设计窗体如下:
将主窗体的Text属性设置为“CoolUI”;将左边三个按钮的Text属性分别设置为“导入精灵”、“朗读文本”、“隐藏精灵”;将textBox的Text属性设置为“Type anything here for the character to read for you!(Only English)”,Multiline属性设置为True。
3.简单的用户界面已经完成,现在我们来进行代码部分的工作:
首先,添加using AgentO到代码的开始处。其次,在我们的类里添加私有数据成员:private IAgentCtlCharacterEx C(这就是我们要用到的精灵的对象)。修改构造函数如下:
public Form1()
// Required for Windows Form Designer support
InitializeComponent();
button2.Enabled=//先使下面的两个按钮无效
button3.Enabled=
// TODO: Add any constructor code after InitializeComponent call
接着,添加左边三个按钮的鼠标单击的消息相应函数:
private void button1_Click(object sender, System.EventArgs e)
private void button2_Click(object sender, System.EventArgs e)
private void button3_Click(object sender, System.EventArgs e)
代码如下:
private void button1_Click(object sender, System.EventArgs e)
axAgent1.Characters.Load(&Genie&, (object)&GENIE.ACS&);//导入吉尼这个精灵
Character = axAgent1.Characters[&Genie&];
Character.LanguageID = 0x409;//把语言设置为英语,这里不能是中文
Character.Show(null);//显示精灵
button1.Enabled=//重新设置按钮的有效性
button2.Enabled=
button3.Enabled=
private void button2_Click(object sender, System.EventArgs e)
if(textBox1.Text.Length == 0) //如果没有字符的话,就不读
Character.Speak(textBox1.Text, null);//让精灵朗读文本
private void button3_Click(object sender, System.EventArgs e)
Character.Play(&Wave&);
Character.Play(&Hide&);//隐藏精灵
所有完整的代码如下:
using System.D
using System.C
using System.Windows.F
using System.D
using AgentO
namespace CoolUI
/// &summary&
/// Summary description for Form1.
/// &/summary&
public class Form1 : System.Windows.Forms.Form
private AxAgentObjects.AxAgent axAgent1;
private IAgentCtlCharacterEx C
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
/// &summary&
/// Required designer variable.
/// &/summary&
ponentModel.Container components =
public Form1()
// Required for Windows Form Designer support
InitializeComponent();
button2.Enabled=//先使下面的两个按钮无效
button3.Enabled=
// TODO: Add any constructor code after InitializeComponent call
/// &summary&
/// Clean up any resources being used.
/// &/summary&
protected override void Dispose( bool disposing )
if( disposing )
if (components != null)
components.Dispose();
base.Dispose( disposing );
#region Windows Form Designer generated code
/// &summary&
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// &/summary&
private void InitializeComponent()
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.axAgent1 = new AxAgentObjects.AxAgent();
((ponentModel.ISupportInitialize)(this.axAgent1)).BeginInit();
this.SuspendLayout();
// textBox1
this.textBox1.Location = new System.Drawing.Point(112, 24);
this.textBox1.Multiline =
this.textBox1.Name = &textBox1&;
this.textBox1.Size = new System.Drawing.Size(224, 152);
this.textBox1.TabIndex = 2;
this.textBox1.Text = &Type anything here for the character to read for you!(Only English)&;
// button1
this.button1.Location = new System.Drawing.Point(16, 24);
this.button1.Name = &button1&;
this.button1.TabIndex = 1;
this.button1.Text = &导入精灵&;
this.button1.Click += new System.EventHandler(this.button1_Click);
// button2
this.button2.Location = new System.Drawing.Point(16, 80);
this.button2.Name = &button2&;
this.button2.TabIndex = 1;
this.button2.Text = &朗读文本&;
this.button2.Click += new System.EventHandler(this.button2_Click);
// button3
this.button3.Location = new System.Drawing.Point(16, 136);
this.button3.Name = &button3&;
this.button3.TabIndex = 1;
this.button3.Text = &隐藏精灵&;
this.button3.Click += new System.EventHandler(this.button3_Click);
// axAgent1
this.axAgent1.Enabled =
this.axAgent1.Location = new System.Drawing.Point(320, 176);
this.axAgent1.Name = &axAgent1&;
this.axAgent1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject(&axAgent1.OcxState&)));
this.axAgent1.Size = new System.Drawing.Size(32, 32);
this.axAgent1.TabIndex = 0;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(360, 213);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button3,
this.button2,
this.textBox1,
this.button1,
this.axAgent1});
this.Name = &Form1&;
this.Text = &CoolUI&;
((ponentModel.ISupportInitialize)(this.axAgent1)).EndInit();
this.ResumeLayout(false);
#endregion
/// &summary&
/// The main entry point for the application.
/// &/summary&
[STAThread]
static void Main()
Application.Run(new Form1());
private void button1_Click(object sender, System.EventArgs e)
axAgent1.Characters.Load(&Genie&, (object)&GENIE.ACS&);//导入吉尼这个精灵
Character = axAgent1.Characters[&Genie&];
Character.LanguageID = 0x409;//把语言设置为英语,这里不能是中文
Character.Show(null);//显示精灵
button1.Enabled=//重新设置按钮的有效性
button2.Enabled=
button3.Enabled=
private void button2_Click(object sender, System.EventArgs e)
if(textBox1.Text.Length == 0) //如果没有字符的话,就不读
Character.Speak(textBox1.Text, null);//让精灵朗读文本
private void button3_Click(object sender, System.EventArgs e)
Character.Play(&Wave&);
Character.Play(&Hide&);//隐藏精灵
4.好了,现在完成了所有的工作了,安Ctrl+F5试试效果吧!
关键词阅读:
1(共条评论)
2(共条评论)
3(共条评论)
4(共条评论)
5(共条评论)
降低上网资费迫在眉睫 企业应关注民心所向
日前,锐捷网络政府和交通行业部总经理肖广...
联系我们:
广告发布:
方案、案例展示:
京ICP000080号 网站-3
&&&&&&&&京公网安备45号Agent-skylar的喜欢 | LOFTER(乐乎) - 记录生活,发现同好
LOFTER for ipad ---- 记录生活,发现同好
Agent-skylar 的喜欢
  被喜欢
  被喜欢
{list posts as post}
{if post.type==1 || post.type == 5}
{if !!post.title}${post.title|escape}{/if}
{if !!post.digest}${post.digest}{/if}
{if post.type==2}
{if post.type == 3}
{if !!post.image}
{if post.type == 4}
{if !!post.image}
{if !!photo.labels && photo.labels.length>0}
{var wrapwidth = photo.ow < 500?photo.ow:500}
{list photo.labels as labs}
{var lbtxtwidth = Math.floor(wrapwidth*(labs.ort==1?labs.x:(100-labs.x))/100)-62}
{if lbtxtwidth>12}
{if !!labs.icon}
{list photos as photo}
{if photo_index==0}{break}{/if}
品牌${make||'-'}
型号${model||'-'}
焦距${focalLength||'-'}
光圈${apertureValue||'-'}
快门速度${exposureTime||'-'}
ISO${isoSpeedRatings||'-'}
曝光补偿${exposureBiasValue||'-'}
镜头${lens||'-'}
{if data.msgRank == 1}{/if}
{if data.askSetting == 1}{/if}
{if defined('posts')&&posts.length>0}
{list posts as post}
{if post_index < 3}
{if post.type == 1 || post.type == 5}
{if !!post.title}${post.title|escape}{/if}
{if !!post.digest}${post.digest}{/if}
{if post.type == 2}
{if post.type == 3}
{if post.type == 4}
{if post.type == 6}
{if drlist.length>0}
更多相似达人:
{list drlist as dr}{if drlist.length === 3 && dr_index === 0}、{/if}{if drlist.length === 3 && dr_index === 1}、{/if}{if drlist.length === 2 && dr_index === 0}、{/if}{/list}
暂无相似达人,
{if defined('posts')&&posts.length>0}
{list posts as post}
{if post.type == 2}
{if post.type == 3}
{if post.type == 4}
{if post.type == 6}
this.p={ dwrMethod:'queryLikePosts',fpost:'459cd1_2a51b28',userId:4505565,blogListLength:12};

参考资料

 

随机推荐