How to get alternate single words during dictation

2019-06-05 04:58发布

I am running a user study with speech recognition and new technologies. During the laboratory tests, I need to display all the dictated text using an interface that I programmed.

Currently, I can get the alternate whole sentences in C# but I need to get the single words. For example, if someone says "Hello, my name is Andrew", I want to get an alternate word for "Hello", "my", "name", "is" and "Andrew", instead of an alternate for the complete sentence.

Here is a code snippet of the handler I'm using.

public void OnSpeechRecognition(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
{
    int NUM_OF_ALTERNATES = 5; // Number of alternates sentences to be read
    string recognizedSentence = Result.PhraseInfo.GetText(0, -1, true);

    // Get alternate sentences
    ISpeechPhraseAlternates phraseAlternates = Result.Alternates(NUM_OF_ALTERNATES);
}

Any ideas are appreciated.

1条回答
【Aperson】
2楼-- · 2019-06-05 05:24

You need to specify the element count and index in the Result.Alternates call.

E.g.,

public void OnSpeechRecognition(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
{
    int NUM_OF_ALTERNATES = 5; // Number of alternates sentences to be read
    string recognizedSentence = Result.PhraseInfo.GetText(0, -1, true);

    // Get alternate sentences
    int elementCount = Result.PhraseInfo.Elements.Count();
    for (int i = 0; i < elementCount; ++i)
    {
          ISpeechPhraseAlternates phraseAlternates = Result.Alternates(NUM_OF_ALTERNATES, i, 1);
    }
}
查看更多
登录 后发表回答