问题描述
大家好,祝贺这个伟大的网站!我正在构建一个将执行语音识别和数字识别的应用程序。我需要让我的程序理解数字在
0.0 - 10范围内以及0-99范围内的数字。
例如,如果我对计算机说34,52我需要在一个文本框中写下这个数字。
我知道如何让一个程序理解语音,我知道如何制作语法,但我不知道怎么做到了解十进制数....如果你能给出任何想法或任何建议我将不胜感激!
Hello guys and congrats for the great site! I am building an application that will perform speech recognition and number recognition . I need to make my program understand numbers in the range of
0.0 - 10 and also numbers in the range of 0-99.
for example if i say to the computer 34,52 i need to write the number in a text box.
I know how to make a program understand speech , i know how to make grammars , but i don't know how to make it to understand decimal numbers.... if you can give any ideas or any suggestions i would be grateful!
推荐答案
string[] phrases = new string[] { "10", "11", "12", "Quit", /*...*/ };
// of course, in real code create array of strings with those number strings
// using the loop
//...
Choices choiceSet = new Choices(phrases);
GrammarBuilder grammarBuilder = new GrammarBuilder(choiceSet);
SpeechRecognitionEngine engine = new SpeechRecognitionEngine();
//...
engine.SpeechRecognized += (source, eventInfo) => {
string recognizedText = eventInfo.Result.Text;
int numericCommand;
if (int.TryParse(recognizedText, out numericCommand)) {
// numericCommand contains text recognized as number
} else {
// something else
}
//...
};
请记住,此识别器类型需要 [System.MTAThread]
当 System.Speech.Recognition.SpeechRecognizer
需要[System.STAThread]。
我没有打扰到尝试 System.Speech.Recognition.SpeechRecognizer
。我认为它将支持我刚才描述的功能。您可以自己试试。
Remember that this recognizer type requires [System.MTAThread]
while System.Speech.Recognition.SpeechRecognizer
requires [System.STAThread].
I did not bother to try System.Speech.Recognition.SpeechRecognizer
. I think it will support the functionality I just described. You can try it yourself.
这篇关于语音识别,包括带c#的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!