How to train a user who is using my code which implements system.speech and SpeechRecognitionEngine

前端 未结 1 489
日久生厌
日久生厌 2021-01-06 10:47

I have already coded using the System.Speech.Recognition namespace and use a XML SRGS file for grammer and the SpeechRecognitionEngine.

I want to be able to lead the

1条回答
  •  离开以前
    2021-01-06 11:32

    A simpler alternative is to run the existing training UI with your own training text. The automation-compatible APIs (Microsoft Speech Object Library, aka SpeechLib) expose IspRecognizer::DisplayUI, and you can call that with your own training text.

    The training text needs to be a double-null terminated string, also known as a multistring. Here's some code that converts a string array to a multistring:

    static string StringArrayToMultiString(
        ICollection stringArray
        )
    {
        StringBuilder multiString = new StringBuilder();
    
    
        if (stringArray != null)
        {
            foreach (string s in stringArray)
            {
                multiString.Append(s);
                multiString.Append('\0');
            }
        }
    
        return multiString.ToString();
    }
    

    Then, to actually call DisplayUI, you would do something like this:

    static void RunTraining(string[] TrainingText)
    {
        SpSharedRecoContext RC = new SpSharedRecoContext();
        string Title = "My App's Additional Training";
        ISpeechRecognizer spRecog = RC.Recognizer;
        spRecog.DisplayUI(hWnd, Title, SpeechLib.SpeechUserTraining, StringArrayToMultiString(TrainingText);
    }
    

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