简体   繁体   English

C#语音识别-将句子转换为数字

[英]C# Speech Recognition - convert sentence into numbers

I'm learning C# through a calculator project, and am trying to add a cool feature that can recognize voice as calculator input. 我正在通过一个计算器项目学习C#,并试图添加一个很酷的功能,可以将语音识别为计算器输入。 The System.Speech.Recognition library has allowed me to easily add grammar choices for numbers 0-9 with some basic if statement code. System.Speech.Recognition库使我可以使用一些基本的if语句代码轻松地为数字0-9添加语法选择。 However, I want it to be able to recognize all possible combinations of numbers that a user could say...what's the best approach for this without having to hand code every possible combination of numbers as a sentence/string (eg "five hundred thirty seven thousand four hundred twenty two")? 但是,我希望它能够识别出用户可以说的所有可能的数字组合...对此最好的方法是什么,而不必将每个可能的数字组合都编码为句子/字符串(例如“ 530七千四百二十二“)?

Here's what I have so far: 这是我到目前为止的内容:

private void buttonListen_Click(object sender, EventArgs e)
 {
    SpeechRecognitionEngine speechRecognize = new SpeechRecognitionEngine();

    Choices ones = new Choices();
    ones.Add(new string[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" });

    Grammar calculatorGrammerOnes = new Grammar(new GrammarBuilder(ones));

    try
        {
            speechRecognize.RequestRecognizerUpdate();
            speechRecognize.LoadGrammar(calculatorGrammerOnes);
            speechRecognize.SpeechRecognized += speechRecognize_SpeechRecognized;
            speechRecognize.SetInputToDefaultAudioDevice();
            speechRecognize.RecognizeAsync(RecognizeMode.Multiple);
        }
    catch
        {
            return;
        }
 }

private void speechRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
 {
    if (e.Result.Text == "one")
    {
      //Insert "1" as the operand
    }
    else if (e.Result.Text == "two")
    {
      //Insert "2" as the operand
    }
etc...
 }

That would be much complex 那会很复杂

eg "five hundred thirty seven thousand four hundred twenty two", 例如“五十三万七千四百二十二”,

If in the same scenario one provide input speech as : 如果在相同的情况下,请提供以下输入语音:

"five hundred and thirty seven thousand four hundred twenty two" “五十三万七千四百二十二”

your algorithm cannot find the result. 您的算法找不到结果。

It would be much easier if inputs are like : 如果输入像这样会容易得多:

eg. 例如。 "five three seven zero ..etc " “五三七零..etc”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM