关于使用Speech SDK 5.1过程中遇到的问题

commanderwei 2012-04-14 10:36:41
如何使用SpeechLib 来完成一个语音识别的程序,我需要的是语音识别,而不是文字到语音转换,在网上看到了很多代码是这样写的:
public class SpRecognition
{
private static SpRecognition _Instance = null;
private SpeechLib.ISpeechRecoGrammar isrg;
//private SpSharedRecoContextClass ssrContex = null;
private SpSharedRecoContextClass ssrContex;
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);
}

}
但是程序出错:Error 1 Interop type 'SpeechLib.SpSharedRecoContextClass' cannot be embedded. Use the applicable interface instead. D:\C#学习\tryreco\tryreco\Form1.cs 48 21 tryreco

求大神解释,为什么出错了呢?怎么解决啊?
...全文
335 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
commanderwei 2012-05-05
  • 打赏
  • 举报
回复
成功了,谢了!
  • 打赏
  • 举报
回复
说错了,应该是选false
  • 打赏
  • 举报
回复
如果用的是visual studio 2010, 试试在solution explorer右击SpeechLib,点属性,Embed Interop Types一项选true

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧