语音识别的两个方法_语音识别的应用有哪些

语音识别的两个方法 通过微软的sapi,不仅仅可以实现语音合成tts,同样可以实现语音识别sr。下面我们就介绍并贴出相关代码。主要有两种方式:
1、使用com组件技术,不管是c++,c#,delphi都能玩的转,开发出来的东西在xp和win7都能跑。(注意要引入系统组件speechlib,xp要安装识别引擎)
2、使用win7的windows api,其实最终还是调用了sapi,所以开发出来的东西就只能在win7上面跑。
其实不管是哪一种,都是调用sapi,可能后一种代码比较简单。
使用第一种方式,需要注意在com选项卡里面的microsoft speech object library引用
c#代码 public class sprecognition
{
private static sprecognition _instance = null;
private speechlib.ispeechrecogrammar isrg;
private speechlib.spsharedrecocontextclass ssrcontex = null;
public delegate void stringevent(string str);
public stringevent setmessage;
private sprecognition()
{
ssrcontex = new spsharedrecocontextclass();
isrg = ssrcontex.creategrammar(1);
speechlib._ispeechrecocontextevents_recognitioneventhandler rechandle =
new _ispeechrecocontextevents_recognitioneventhandler(contexrecognition);
ssrcontex.recognition += rechandle;
}
public void beginrec()
{
isrg.dictationsetstate(speechrulestate.sgdsactive);
}
public static sprecognition instance()
{
if (_instance == null)
_instance = new sprecognition();
return _instance;
}
public void closerec()
{
isrg.dictationsetstate(speechrulestate.sgdsinactive);
}
private void contexrecognition(int iindex, object obj, speechlib.speechrecognitiontype type, speechlib.ispeechrecoresult result)
{
if (setmessage != null)
{
setmessage(result.phraseinfo.gettext(0, -1, true));
}
}
}
第二种同样需要引入,不过引入的是win7中的.net3.5类库
c# 代码
using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.speech;
using system.speech.recognition;
using system.globalization;
using system.windows.forms;
namespace studybeta
{
public class srecognition
{
public speechrecognitionengine recognizer = null;//语音识别引擎
public dictationgrammar dictationgrammar = null; //自然语法
public system.windows.forms.control cdisplay; //显示控件
public srecognition(string[] fg) //创建关键词语列表
{
cultureinfo myciintl = new cultureinfo(“en-us”);
foreach (recognizerinfo config in speechrecognitionengine. installedrecognizers())//获取所有语音引擎
{
if (config.culture.equals(myciintl) && config.id == “ms-1033-80-desk” )
{
recognizer = new speechrecognitionengine(config);
break;
}//选择美国英语的识别引擎
}
if (recognizer != null)
{
initializespeechrecognitionengine(fg);//初始化语音识别引擎
dictationgrammar = new dictationgrammar();
}
else
{
messagebox.show(“创建语音识别失败”);
}
}
private void initializespeechrecognitionengine(string[] fg)
{
recognizer.setinputtodefaultaudiodevice();//选择默认的音频输入设备
grammar customgrammar = createcustomgrammar(fg);
//根据关键字数组建立语法
recognizer.unloadallgrammars();
recognizer.loadgrammar(customgrammar);
//加载语法
recognizer.speechrecognized += new eventhandler 《speechrecognizedeventargs》(recognizer_speechrecognized);
recognizer.speechhypothesized += new eventhandler 《speechhypothesizedeventargs》(recognizer_speechhypothesized);
}
public void beginrec(control tbresult)//关联窗口控件
{
turnspeechrecognitionon();
turndictationon();
cdisplay = tbresult;
}
public void over()//停止语音识别引擎
{
turnspeechrecognitionoff();
}
public virtual grammar createcustomgrammar(string[] fg) //创造自定义语法
{
grammarbuilder grammarbuilder = new grammarbuilder();
grammarbuilder.append(new choices(fg));
return new grammar(grammarbuilder);
}
private void turnspeechrecognitionon()//启动语音识别函数
{
if (recognizer != null)
{
recognizer.recognizeasync(recognizemode.multiple);
//识别模式为连续识别
}
else
{
messagebox.show(“创建语音识别失败”);
}
}
private void turnspeechrecognitionoff()//关闭语音识别函数
{
if (recognizer != null)
{
recognizer.recognizeasyncstop();
turndictationoff();
}
else
{
messagebox.show(“创建语音识别失败”);
}
}
private void recognizer_speechrecognized(object sender, speechrecognized eventargs e)
{
//识别出结果完成的动作,通常把识别结果传给某一个控件
string text = e.result.text;
cdisplay.text = text;
}
private void turndictationon()
{
if (recognizer != null)
{
recognizer.loadgrammar(dictationgrammar);
//加载自然语法
}
else
{
messagebox.show(“创建语音识别失败”);
}
}
private void turndictationoff()
{
if (dictationgrammar != null)
{
recognizer.unloadgrammar(dictationgrammar);
//卸载自然语法
}
else
{
messagebox.show(“创建语音识别失败”);
}
}
}
}
语音识别的应用有哪些 语音识别技术应用有哪些?语音识别技术有着非常广泛的应用领域和市场前景。在语音输入控制系统中,它使得人们可以甩掉键盘,通过识别语音中的要求、请求、命令或询问来作出正确的响应,这样既可以克服人工键盘输入速度慢,极易出差错的缺点,又有利于缩短系统的反应时间,使人机交流变得简便易行,比如用于声控语音拨号系统、声控智能玩具、智能家电等领域。
在智能对话查询系统中,人们通过语音命令,可以方便地从远端的数据库系统中查询与提取有关信息,享受自然、友好的数据库检索服务,例如信息网络查询、医疗服务、银行服务等。语音识别技术还可以应用于自动口语翻译,即通过将口语识别技术、机器翻译技术、语音合成技术等相结合,可将一种语言的语音输入翻译为另一种语言的语音输出,实现跨语言交流。
语音识别技术在军事斗争领域里也有着极为重要的应用价值和极广阔的应用空间。一些语音识别技术就是着眼于军事活动而研发,并在军事领域首先应用、首获成效的,军事应用对语音识别系统的识别精度、响应时间、恶劣环境下的顽健性都提出了更高的要求。
目前,语音识别技术已在军事指挥和控制自动化方面得以应用。比如,将语音识别技术应用于航空飞行控制,可快速提高作战效率和减轻飞行员的工作负担,飞行员利用语音输人来代替传统的手动操作和控制各种开关和设备,以及重新改编或排列显示器上的显示信息等,可使飞行员把时间和精力集中于对攻击目标的判断和完成别的操作上来,以便更快获得信息来发挥战术优势。
更多精彩阅读: 语音识别的优缺点_语音识别功能介绍 语音识别算法有哪些_语音识别特征提取方法 怎么实现语音识别_手机语音识别怎么设置 语音识别设置能删除吗_语音识别系统工作流程
如何正确认识AI伦理?人类对AI的偏见
吐槽智能手机上那些不爽的事
UI设计新起之秀Pixso斩获MVX年度创新金奖
谷歌 Pixel 6 拆解,FD-SOI首次被用于5G毫米波
东海实验室海洋传感器技术与装备研究所正式成立
语音识别的两个方法_语音识别的应用有哪些
苹果已修复macOS中关于应用认证的隐私问题
vivo X30系列有哪些亮点
手机出货量出货量下滑,到底怎么样才能挽救衰落的智能手机市场?
开关和传感器推动工厂自动化技术发展
【功率放大器应用】超声导波的衰减特性
麒麟820 AI跑分公布 仅次于麒麟990 5G
变电站防雷接地故障的判断和处理方法
国有车企被逼着由内而外进行变革,国有车企们该何去何从?
电信运营商放弃发展SD-WAN将可能会失去服务收入和客户
高性能有源电子扫描阵列(AESA)火控雷达——Raven ES-05
华为将在2020年投入2亿美元来推动鲲鹏计算产业的发展
全球量子互联网的关键:新型量子中继器
浅谈FPC软板的基本测试标准
智能健康传感器可以为我们带来什么