我想写一个用户对短信说的话。我可以在Microsoft语音平台上完成这个任务吗?也许我只是误解了它应该如何工作,以及它的目的用例是什么。
我现在有了这个控制台应用程序:
static void Main(string[] args)
{
Choices words = new Choices();
words.Add(new string[] { "test", "hello" ,"blah"});
GrammarBuilder gb = new GrammarBuilder();
gb.Append(words);
Grammar g = new Grammar(gb);
SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));
sre.LoadGrammar(g);
sre.SetInputToDefaultAudioDevice();
//add listeners
sre.Recognize();
Console.ReadLine();
}它似乎只输出了我在Choices中指定的单词。
如果我想匹配(大多数)用户会说的话,我需要添加一整本字典吗?
而且,它在匹配一个单词之后就停止了。如果我想捕捉整个句子呢?
我正在寻找解决方案,A)捕捉大量单词,B)一次捕获多个单词。
编辑:
我发现了这个:http://www.codeproject.com/Articles/483347/Speech-recognition-speech-to-text-text-to-speech-a#torecognizeallspeech
发布于 2014-12-16 22:50:59
正如在此页中所看到的,DictationGrammar类有一个基本的常用词汇库。
一次捕获了不止一个单词
sre.RecognizeAsync(RecognizeMode.Multiple);所以我现在的代码是:
public static SpeechRecognitionEngine sre;
static void Main(string[] args)
{
sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));
sre.LoadGrammar(new Grammar(new GrammarBuilder("exit")));
sre.LoadGrammar(new DictationGrammar());
sre.SetInputToDefaultAudioDevice();
sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
Console.ReadLine();
}
private static void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "exit")
{
sre.RecognizeAsyncStop();
}
Console.WriteLine("You said: " + e.Result.Text);
}https://stackoverflow.com/questions/27514989
复制相似问题