关于语音识别,在WINDOWS FORM中可以成功语音转成文字,但转换成WEB形式后失败了,请指教
请看这下边代码:##################################################################
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SpeechLib;
namespace tryreco
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
SpRecognition cc = new SpRecognition();
cc.MessageBegin();
cc.BeginRec(textBox1); //Fan:把内容输入textbox1
}
private void button2_Click(object sender, EventArgs e)
{
SpRecognition cc = new SpRecognition();
cc.MessageEnd();
cc.CloseRec();
}
public class SpRecognition
{
private static SpRecognition _Instance = null;
private SpeechLib.ISpeechRecoGrammar isrg;
private SpeechLib.SpSharedRecoContextClass ssrContex = null;
private System.Windows.Forms.Control cDisplay; //fan:用来显示语音转化后的文本
public System.Windows.Forms.TextBox textbox; //fan:增加textbox在SpRecognition 类
public 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;
//cDisplay.Text = "dddddddddd"; 测试,可以成功在textbox1那里显示出来
}
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 void MessageBegin()
{
textbox =new TextBox() ;
textbox.Text = "Notice :this time ,it Begin recoginse";
MessageBox.Show(textbox.Text);
}
public void MessageEnd()
{
textbox = new TextBox();
textbox.Text = "Notice :this time ,it End recoginse";
MessageBox.Show(textbox.Text);
}
}
}
}
#########################################################
以上代码,可以成功的把麦克风传入的语音,在TEXTBOX中输出出来,但,我想把其做成WEB形式的,在System.Web.UI.Controls却找不到相关的Textbox类,private System.Web.UI.WebControls.TextBox TextBoxdisplay,也
试过了,还是不行,,这个该怎么转换呢?请指教
#########################################################
我的WEB代码:
#########################################################
using SpeechLib;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public class SpRecognition
{
private static SpRecognition _Instance = null;
private SpeechLib.ISpeechRecoGrammar isrg;
private SpeechLib.SpSharedRecoContextClass ssrContex = null;
private System.Web.UI.WebControls.TextBox FansTextBoxdisplay;
//应该就是这里出了问题的了,
public SpRecognition()
{
ssrContex = new SpSharedRecoContextClass();
isrg = ssrContex.CreateGrammar(1);
SpeechLib._ISpeechRecoContextEvents_RecognitionEventHandler recHandle =
new _ISpeechRecoContextEvents_RecognitionEventHandler(ContexRecognition);
ssrContex.Recognition += recHandle;
}
public void BeginRec(TextBox TextBoxA)
{
isrg.DictationSetState(SpeechRuleState.SGDSActive);
FansTextBoxdisplay = TextBoxA;
// FansTextBoxdisplay.Text = "dddddd";----可以成功在textbox1那里显示出来
}
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)
{
FansTextBoxdisplay.Text += result.PhraseInfo.GetText(0, -1, true);
}
}
public void MessageBegin()
{
Label1.Text = "Notice :this time ,it Begin recoginse";
}
public void MessageEnd()
{
Label1.Text = "Notice :this time ,it End recoginse";
}
protected void Button1_Click(object sender, EventArgs e)
{
SpRecognition cc = new SpRecognition();
MessageBegin();
cc.BeginRec(TextBox1); //,,fan:把内容输入textbox1
}
protected void Button2_Click(object sender, EventArgs e)
{
SpRecognition cc = new SpRecognition();
MessageEnd();
cc.CloseRec();
}
}
###############################################################
很久没有编程了,,很多都不明白了,呵呵,,,请大家多多帮忙,先谢谢大家了,
--------------------编程问答-------------------- private System.Web.UI.WebControls.TextBox FansTextBoxdisplay;
这句语法应该没有问题吧 --------------------编程问答-------------------- 语法是没问题的,,但就是在输入语音的时候,在TEXTBOX里显示不出来,,, --------------------编程问答-------------------- 或者是用另外的来代替这个private System.Web.UI.WebControls.TextBox FansTextBoxdisplay;??? --------------------编程问答-------------------- Up Up ,,,继续Up,,, --------------------编程问答-------------------- 请问你现在这个问题解决了没有,解决了的话也帮我一下
补充:.NET技术 , ASP.NET