您的位置:程序门 -> .net技术 -> c#



请大侠帮助菜鸟修改一段c#代码,谢谢


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


请大侠帮助菜鸟修改一段c#代码,谢谢
发表于: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中添加按钮事件语句呢,谢谢大家.
发表于:2007-03-12 08:54:451楼 得分:0
请各位大侠帮助看看,给小弟个解决办法,谢谢.


快速检索

最新资讯
热门点击