How to mix Grammar (Rules) & Dictation (Free speech) with SpeechRecognizer in C#

后端 未结 2 1968
再見小時候
再見小時候 2020-12-13 22:11

I really like Microsofts latest speech recognition (and SpeechSynthesis) offerings.

http://msdn.microsoft.com/en-us/library/ms554855.aspx

http://estellasays.

相关标签:
2条回答
  • 2020-12-13 22:30

    You have two choices:

    1. You can use the dictation node for free-text using GrammarBuilder::AppendDictation. The problem is that since the recognizer doesn't have any context, the recognitions aren't the highest quality.
    2. You can use a textbuffer node and provide a set of items using GrammarBuilder::Append(String, SubsetMatchingMode). This will give the recognizer enough context to get good quality recognitions without having to rebuild the entire grammar tree every time.
    0 讨论(0)
  • 2020-12-13 22:35

    You could try something like this... It specifies a list of known commands.. but also lets you use open dictation afterwards. It expects there to be a command given before the open dictation.. but you could reverse this... and append th However, by adding in a blank in the command type (" ") it will also let you get straight to the dictation part.

    Choices commandtype = new Choices();
    commandtype.Add("search");
    commandtype.Add("print");
    commandtype.Add("open");
    commandtype.Add("locate");
    
    SemanticResultKey srkComtype = new SemanticResultKey("comtype",commandtype.ToGrammarBuilder());
    
     GrammarBuilder gb = new GrammarBuilder();
     gb.Culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB");
     gb.Append(srkComtype);
     gb.AppendDictation();
    
     Grammar gr = new Grammar(gb);
    

    then on your recognizer just use the result text etc

    private void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        System.Console.WriteLine(e.Result.Text);
    
    }
    

    You can add more choice options, and SemanticResultKeys to the structure to make more complex patterns if you wish. Also a wildcard (e.g. gb.AppendWildcard(); ).

    0 讨论(0)
提交回复
热议问题