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

巧了我就是萌 提交于 2019-11-30 22:00:17

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<string> 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);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!