//Microsoft Speech SDK Version 5.1
#endregion
private SpeechLib.SpSharedRecoContext objRecoContext = null;
#region ISpeechRecoGrammar说明
//The ISpeechRecoGrammar automation interface enables applications to manage the words and phrases for the SR engine.
//为语音识别引擎自动管理应用程序单词和短语
/*
属性
Id Property Returns the Id assigned to the grammar when it was created.
RecoContext Property Returns the RecoContext object that created this grammar.
Rules Property Returns the collection of grammar rules in the RecoGrammar.
State Property Gets and sets the operational status of the speech grammar.
方法
CmdLoadFromFile Method Loads a command and control grammar from the specified file.
CmdLoadFromMemory Method Loads a compiled speech grammar from memory.
CmdLoadFromObject Method Loads a speech grammar from a COM object.
CmdLoadFromProprietaryGrammar Method Loads a proprietary speech grammar.
CmdLoadFromResource Method Loads a command and control grammar from a Win32 resource.
CmdSetRuleIdState Method Activates or deactivates a rule by its rule ID.
CmdSetRuleState Method Activates or deactivates a rule by its rule name.
DictationLoad Method Loads a dictation topic into the grammar.
DictationSetState Method Sets the dictation topic state.
DictationUnload Method Unloads the active dictation topic from the grammar.
IsPronounceable Method Determines if a word has a pronunciation.
Reset Method Clears all grammar rules and resets the grammar's language to NewLanguage.
SetTextSelection Method Sets the range of text selection information in a word sequence data buffer.
SetWordSequenceData Method Defines a word sequence data buffer for use by the SR engine.
*/
#endregion
private SpeechLib.ISpeechRecoGrammar grammar = null;
#region ISpeechGrammarRule说明
//The ISpeechGrammarRule automation interface defines the properties and methods of a speech grammar rule
//自动定义语音属性和方法的接口
/*
属性
Attributes Property Returns information about the attributes of a speech grammar rule.
Id Property Specifies the ID of the speech grammar rule.
InitialState Property Specifies the initial state of the speech grammar rule.
Name Property Specifies the name of the speech grammar rule.
方法
AddResource Method Adds a string to a speech rule.
AddState Method Adds a state to a speech rule.
Clear Method Clears a rule, leaving only its initial state.
*/
#endregion
private SpeechLib.ISpeechGrammarRule menuRule = null;
#endregion
private void cmdEnable_Click(object sender, System.EventArgs e)
{
// 得到一个RecoContext实例.
objRecoContext = new SpeechLib.SpSharedRecoContext();
// 指派一个事件给Hypothesis Event(中间层暂定的识别,即,初级的,临时的识别).
objRecoContext.Hypothesis += new _ISpeechRecoContextEvents_HypothesisEventHandler(Hypo_Event);
// 指派一个事件给语音识别.
objRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(Reco_Event);
//创建grammer实例.
grammar = objRecoContext.CreateGrammar(0);
label3.Text = "Speak Out one of the follwoing./r/n1. New 2. Open 3. Close 4. Exit/r/n5. Cut 6. Copy 7. Paste 8. Delete";
//激活菜单命令.
menuRule = grammar.Rules.Add("MenuCommands",SpeechRuleAttributes.SRATopLevel|SpeechRuleAttributes.SRADynamic,1);
object PropValue = "";
menuRule.InitialState.AddWordTransition(null,"New"," ",SpeechGrammarWordType.SGLexical,"New", 1, ref PropValue, 1.0F );
menuRule.InitialState.AddWordTransition(null,"Open"," ",SpeechGrammarWordType.SGLexical,"Open", 2, ref PropValue, 1.0F );
menuRule.InitialState.AddWordTransition(null,"Close"," ",SpeechGrammarWordType.SGLexical,"Close",3, ref PropValue, 1.0F );
menuRule.InitialState.AddWordTransition(null,"Exit"," ",SpeechGrammarWordType.SGLexical,"Exit",4, ref PropValue, 1.0F );
menuRule.InitialState.AddWordTransition(null,"Cut"," ",SpeechGrammarWordType.SGLexical,"Cut",5, ref PropValue, 1.0F );
menuRule.InitialState.AddWordTransition(null,"Copy"," ",SpeechGrammarWordType.SGLexical,"Copy",6, ref PropValue, 1.0F );
menuRule.InitialState.AddWordTransition(null,"Paste"," ",SpeechGrammarWordType.SGLexical,"Paste",7, ref PropValue, 1.0F );
menuRule.InitialState.AddWordTransition(null,"Delete"," ",SpeechGrammarWordType.SGLexical,"Delete",8, ref PropValue, 1.0F );
grammar.Rules.Commit();
grammar.CmdSetRuleState("MenuCommands", SpeechRuleState.SGDSActive);
}
#region 初级和正式的语音识别事件处理
private void Reco_Event(int StreamNumber, object StreamPosition,SpeechRecognitionType RecognitionType,ISpeechRecoResult Result)
{
txtReco.Text = Result.PhraseInfo.GetText(0, -1, true);
}
private void Hypo_Event(int StreamNumber, object StreamPosition, ISpeechRecoResult Result)
{
txtHyp.Text = Result.PhraseInfo.GetText(0, -1, true);
}
#endregion
#region 清空控件和使关闭语音识别
private void cmdDiable_Click(object sender, System.EventArgs e)
{
ClearControls(label3, objRecoContext);
}
#endregion
#region 自定义函数
/// <summary>
/// 清空数据
/// </summary>
/// <param name="args">需要清空的变量及控件</param>
public void ClearControls(params object[] args)
{
foreach (object obj in args)
{
if (obj is TextBox)
{
TextBox t = (TextBox)obj;
t.Text = "";
}
if (obj is ListBox)
{
ListBox l = (ListBox)obj;
l.Items.Clear();
}
if (obj is Label)
{
Label l = (Label)obj;
l.Text = "";
}
if (obj is SpeechLib.SpSharedRecoContext)
{
SpeechLib.SpSharedRecoContext s = (SpeechLib.SpSharedRecoContext)obj;
s = null;
}
}
}
#endregion
}
}
分享到:
相关推荐
很有参考价值 1、Speech SDK 5.1 2、Speech SDK 5.1 中文语言包 3、先安装Speech SDK5.1 再安装Speech SDK5.1 中文语言包。完成安装后,解压后有详细安装文档。可以参考一下
TTS(从文本到语音(TextToSpeech))技术,使用C#实现语音朗读功能时需要的多个语音库SDK Microsoft Speech SDK 5.1.msi
编程环境: windows 2012 server vs.net2015 C# 声音组件 Microsoft Speech SDK 5.1
Microsoft Speech SDK 5.1
编程环境: windows 2003 server vs.net2005 C# 声音组件 Microsoft Speech SDK 5.1 -------------------------------- 请下载功能比较全的中文朗读C#示例源码: http://download.csdn.net/source/544239
c#语音识别及朗读系统_(基于speechSDK开发)(Winform) IDE vs2015
由于Speech SDK 没有提供中文男声 ,所以可以采用NeoSpeech的中文男声来弥补。文档中给两个总能进行了综合。说的比较概括,不过有实现代码和相关配置,以及相关软件的下载链接。
http://download.microsoft.com/download/speechSDK/SDK/5.1/WXP/EN-US/speechsdk51LangPack.exe 1、安装speechsdk51.exe 2、安装speechsdk51LangPack.exe 3、启动Delphi 4、安装了sdk5.1后,在Delphi里面Project...
使用C++在海康网络设备SDK的基础上进行进一步的封装,然后使用C#开发界面进行调用。
配置字词,有限的进行语音识别,增加准确率!
基于微软TTS语音合成,中文女声版。请看代码。请先安装:微软TTS5.1语音引擎_中文.msi
基于c# 的speech sdk的应用小例子
C#开发的海康SDK,内涵开发手册,可预览,布防,车牌识别获取,等等
结合C#对巴斯勒相机的SDK进行二次开发
使用speech sdk编写的简单的语音合成程序. 程序简单,播放和停止语音报读,生成语音文件等。 运行环境 vs2008 c#
海康威视摄像头开发,C#示例。基于海康SDK。
C#基于雄迈Sdk的对画面视频监控源码
集成C#、JAVA海康威视SDK各语言开发包,直接修改配置文件可用。
实现功能:相机连接、采集图像(单帧采集、连续采集),软触发,曝光&增益设置、读取,图像缩放功能
用C_开发基于MicrosoftSpeechSDK的语音应用程序 PDF文件