| 发表于:2007-03-11 21:28:40 楼主 |
各位大侠,小弟刚学c#.net,装了vs2005. 在下面的页面,看到关于语音识别的代码: http://www.51cto.com/art/200509/4376_1.htm 于是,赶忙打开vs2005,新建一个工程,并添加了两个按钮button1和button2,还有一个textbox1. 把页面中的下列代码粘贴到工程中,并添加sapi.dll引用,using speechlib;如下: namespace windowsapplication1 { public class sprecognition { private static sprecognition _instance = null; private speechlib.ispeechrecogrammar isrg; private speechlib.spsharedrecocontextclass ssrcontex = null; private system.windows.forms.control cdisplay; private sprecognition() { ssrcontex = new spsharedrecocontextclass(); isrg = ssrcontex.creategrammar(1); speechlib._ispeechrecocontextevents_recognitioneventhandler rechandle = new _ispeechrecocontextevents_recognitioneventhandler(contexrecognition); ssrcontex.recognition += rechandle; } public void beginrec(control tbresult) { isrg.dictationsetstate(speechrulestate.sgdsactive); cdisplay = tbresult; } 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) { cdisplay.text += result.phraseinfo.gettext(0, -1, true); } } public partial class form1 : form { public form1() { initializecomponent(); } ... 编译通过,无错误.现在的问题是: 我应该如何做,才能使点击button1按钮后,开始语音输入. 并在textbox1.text属性中显示语音输入的结果文字. 点击button2按钮,停止当前语音输入. 请问:要把public class sprecognition...代码段粘贴在工程的那个位置. 同时,如何在button1和button2中添加按钮事件语句呢,谢谢大家. |
|
|
|
|