微軟Agent API能夠提供卡通角色的顯示,另外,它還可以支持語音識別,因此應(yīng)用軟件可以對語音ming令作出反應(yīng),而卡通角色可以通過合成的語音、錄制好的音頻信號或文字對ming令作出反應(yīng)。
使用微軟AGENT的要求
要使用該技術(shù),必須使用組件:微軟Agent核心組件、微軟Agent中的卡通角色(Genie、Merlin、Robby和Peedy)、微軟Speech API 4.0a運(yùn)行時(shí)間庫、微軟語音識別引擎和Lernout和Hauspie文字-語音引擎,這些組件可到http://microsoft.com/products/msagent/downloads.htm下載。
語音技術(shù)簡介
文字-語音轉(zhuǎn)換指的是計(jì)算機(jī)將文字信息轉(zhuǎn)換為合成語音進(jìn)行輸出,語音識別是指計(jì)算機(jī)能夠識別出說話者所說的話,接受說話者的ming令和輸入的數(shù)據(jù)。
語音識別和文字-語音轉(zhuǎn)換都需要用到相關(guān)的引擎,幾乎所有的語音識別引擎都是將輸入的語音數(shù)據(jù)轉(zhuǎn)換為與特定引擎相關(guān)的音素,然后這些音素被轉(zhuǎn)換為應(yīng)用程序能夠使用的文字。
文本-語音轉(zhuǎn)換的二種方式:
1、合成文本-語音轉(zhuǎn)換
2、連續(xù)文本-語音轉(zhuǎn)換
合成文本-語音轉(zhuǎn)換方式:
在合成的發(fā)音方式中,引擎處理每個(gè)單詞,并產(chǎn)生該單詞的發(fā)音音素,然后這些音素被轉(zhuǎn)入一個(gè)復(fù)雜的算法中,模仿人類的發(fā)聲方式,生成語音。
連續(xù)文本-語音轉(zhuǎn)換方式:
在連續(xù)文本-語音轉(zhuǎn)換方式中,引擎對文本信息進(jìn)行處理,從一個(gè)預(yù)先錄制好的語音庫中找出句子、單詞和短語,在這種方式中,生成的語音是連續(xù)的。
語音應(yīng)用程序的編程接口
微軟語音應(yīng)用程序編程接口在Win32(Windows 95、Windows NT)下使用了OLE組件對象模式(COM)架構(gòu),微軟的Agent架構(gòu)在合成語音輸出中使用了微軟語音應(yīng)用程序編程接口(SAPI),還使用SAPI支持語音輸入(語音識別SR或文本-語音轉(zhuǎn)換TTS)。微軟的Agent定義了讓應(yīng)用程序訪問其服務(wù)的接口,使得應(yīng)用程序能夠控制角色動畫、支持用戶輸入事件,指定輸出方式。
角色窗口
在微軟Agent應(yīng)用程序中,卡通角色是在它們各自的窗口中被顯示的,這些窗口總是出現(xiàn)在Z軸順序的最頂端。用戶可以通過鼠標(biāo)左鍵拖動角色移動角色所在的窗口,角色的圖像隨著指針而移動。
說話汽球圈
除了語音輸出外,動畫角色還支持以卡通類型說話汽球圈形式的文字字幕,角色說話時(shí),所說的文字就出現(xiàn)在汽球圈兒中,當(dāng)說完時(shí),汽球圈也就不見了。在互聯(lián)網(wǎng)網(wǎng)頁中使用微軟AGENT
要在互聯(lián)網(wǎng)網(wǎng)頁中使用微軟Agent服務(wù),可以在網(wǎng)頁中的或元素中使用HTML標(biāo)記,指定控制的CLSID(類標(biāo)識符),另外,還需要使用CODEBASE參數(shù)指定微軟Agent的安裝文件的位置和版本號。
我們可以使用Vbscript、Javascript和Jscript在互聯(lián)網(wǎng)網(wǎng)頁中使用微軟Agent。

在.NET架構(gòu)中使用微軟AGENT
微軟Agent不是以ActiveX控制DLL的形式提供的。要在.NET中使用它,可以使用由.NET框架SDK提供的AxImp.exe工具:
AxImp -->> ActiveX控制-Win窗體組合體生成器
Syntax: AxImp [/? | [[/source] OCXName]]
Aximp agentctl.dll
上面的ming令生成二個(gè)文件:AxAgentObjects.dll和AgentObjects.dll。通過使用這二個(gè)文件,我們就可以在.NET中使用Agent了。
C#中的微軟Agent:
要在C#中使用微軟Agent,我們必須在程序中添加二個(gè)DLL文件:AxAgentObjects.dll和AgentObjects.dll。加載動畫角色的代碼是相當(dāng)簡單的:
AxAgent.Characters.Load("Genie",(object)"C:/Windows/Msagent/chars/GENIE.acs");
Character = AxAgent.Characters["Genie"];
file://將語言設(shè)置為美國英語
Character.LanguageID = 0x409;
file://該行代碼顯示角色
Character.Show(null);
讓角色說話的代碼如下所示:
Character.Speak ("Welcome you sir VISIT www.onlinecsharpteach.netfirms.com ",null);
下面我們來看一個(gè)例子:
The Example:
using System;
using System.Drawing;
using System.WinForms;
using AgentObjects;
public class Hello: Form
{
private System.ComponentModel.Container components;
private System.WinForms.Button button2;
private System.WinForms.Button button1;
private System.WinForms.TextBox textBox1;
private AxAgentObjects.AxAgent AxAgent;
private IAgentCtlCharacterEx Character;
public Hello()
{
InitializeComponent();
}
public static void Main(string[] args)
{
Application.Run(new Hello());
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.button1 = new System.WinForms.Button();
this.button2 = new System.WinForms.Button();
this.textBox1 = new System.WinForms.TextBox();
this.AxAgent = new AxAgentObjects.AxAgent();
AxAgent.BeginInit();
button2.Click += new System.EventHandler(button2_Click);
button1.Location = new System.Drawing.Point(88, 208);
button1.BackColor =
(System.Drawing.Color)System.Drawing.Color.FromARGB((byte)255, (byte)128, (byte)128);
button1.Size = new System.Drawing.Size(152, 32);
button1.TabIndex = 1;
button1.Text = "Load character";
button2.Location = new System.Drawing.Point(120, 240);
button2.BackColor =
(System.Drawing.Color)System.Drawing.Color.FromARGB((byte)255, (byte)128, (byte)128);
button2.Size = new System.Drawing.Size(96, 24);
button2.TabIndex = 2;
button2.Text = "SPEAK";
textBox1.Location = new System.Drawing.Point(48, 8);
textBox1.Text = " ";
textBox1.Multiline = true;
textBox1.TabIndex = 0;
textBox1.Size = new System.Drawing.Size(248, 200);
textBox1.BackColor =
(System.Drawing.Color)System.Drawing.Color.FromARGB((byte)255, (byte)128, (byte)128);
this.Text = "MSAGENT DEMO";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.WindowState = System.WinForms.FormWindowState.Maximized;
this.BackColor =
(System.Drawing.Color)System.Drawing.Color.FromARGB((byte)255, (byte)192, (byte)192);
this.ClientSize = new System.Drawing.Size(344, 301);
this.Controls.Add(button2);
this.Controls.Add(button1);
this.Controls.Add(textBox1);
this.Controls.Add(AxAgent);
button1.Click += new System.EventHandler(button1_Click);
AxAgent.EndInit();
}
protected void button2_Click(object sender, System.EventArgs e)
{
if(textBox1.Text.Length == 0)
return;
Character.Speak(textBox1.Text, null);
}
protected void button1_Click(object sender, System.EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.AddExtension = true;
openFileDialog.Filter = "Microsoft Agent Characters (*.acs)|*.acs";
openFileDialog.FilterIndex = 1 ;
openFileDialog.RestoreDirectory = true ;
if(openFileDialog.ShowDialog() != DialogResult.OK)
return;
try { AxAgent.Characters.Unload("CharacterID"); }
catch { }
AxAgent.Characters.Load("CharacterID", (object)openFileDialog.FileName);
Character = AxAgent.Characters["CharacterID"];
Character.LanguageID = 0x409;
Character.Show(null);
Character.Play ("announce");
Character.Speak ("welcome you sir",null);
} }
輸出:

圖2

結(jié)束語:
微軟的Agent API提供了支持動畫角色顯示的服務(wù),被配置為OLE Automation(COM)服務(wù)器時(shí),它能夠使多個(gè)被稱為客戶或客戶端應(yīng)用軟件的應(yīng)用程序同時(shí)托管或使用其動畫、輸入、輸出服務(wù)。
新聞熱點(diǎn)
疑難解答
圖片精選