Question

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.

Was it helpful?

Solution

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);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top