请大侠帮助菜鸟修改一段C#代码,谢谢 ( 积分: 50 )

  • 主题发起人 主题发起人 zqssoft
  • 开始时间 开始时间
Z

zqssoft

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠,小弟刚学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中添加按钮事件语句呢,谢谢大家.
 
后退
顶部