我在c#中使用SpeechRecognizer。我想在语法生成器中使用正则表达式,这是我的code.This代码不工作。我想传递RE必须传递的任何句子示例'this is stackoverflow',或者任何句子。
Regex reg = new Regex(@"[a-z\-A-Z]*");
public Form1(){
InitializeComponent();
try{
SpeechRecognizer spec = new SpeechRecognizer();
Choices chose = new Choices();
chose.Add(reg.ToString());
GrammarBuilder gb = new GrammarBuilder();
gb.Append(chose);
Grammar gm = new Grammar(gb);
spec.LoadGrammar(gm);
spec.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs> (sre_SpeechRecognized);
spec.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(sre_SpeechRejected);
}发布于 2015-02-05 14:54:58
允许一个或多个单词。
Regex reg = new Regex(@"^[a-z-A-Z]+(?:\s[a-z-A-Z]+)*$");我假设单词包含字母或或-连字符。
或
Regex reg = new Regex(@"^\S+(?:\s\S+)*$");\S+匹配一个或多个非空格字符。
https://stackoverflow.com/questions/28337632
复制相似问题