How to train a user who is using my code which imp

2019-02-14 18:37发布

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 user through a training of the words or phrases that are important for the app I have written.

I have just seen and read this How to train SAPI I understand that this example uses the unmanaged API (this api exposes a little more) but is exactly the same as far as the engine is concerned.

So if I now set up a form and follow the instruction from the link to initiate training. Can i have my own text on the form and ask the user to read this text. Then conclude the training as indicated in the link. This procedure will train my speech engine that I have already coded with the System.Speech.Recognition namespace.

If I am incorrect is the next best, that I get a user to open their system panel, start the speech recognizer and get them to dictate into maybe Notepad my special phrases until it gets them right most of the time.

Or can i only suggest to them to do the general training?

Conclusion and a few other things The C/C++ speech developers reference has many more things in it than the Automation reference. When you see here in this forum or others posts from especially Eric Brown and his blog he is more than likely referring to the C/C++ methods.

Using the below code on a Win 7 x64 bit machine for the first time caused me to get a "Class not registered" exception and Google did not help me to solve the problem. I needed to target at least "anycpu".

Otherwise the below is perfect, it basically starts the Training part of the UI that you would otherwise get from the Speech Recognizer interface in Control Panel, except you have your own words. This is perfect.

1条回答
一纸荒年 Trace。
2楼-- · 2019-02-14 19:11

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);
}
查看更多
登录 后发表回答