语音识别-如何在SAPI 5.4中使用c#在听写过程中获得替代的单个单词

本文关键字:过程中 单个单 SAPI 语音识别 | 更新日期: 2023-09-27 17:50:32

我正在进行语音识别和新技术的用户研究。在实验室测试期间,我需要使用我编写的界面显示所有指定的文本。

目前,我可以在c#中获得替代的完整句子,但我需要获得单个单词。例如,如果有人说"你好,我的名字是Andrew",我想要得到"Hello"、"my"、"name"、"is"answers"Andrew"的替代词,而不是完整句子的替代词。

下面是我使用的处理程序的代码片段:

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);
}

语音识别-如何在SAPI 5.4中使用c#在听写过程中获得替代的单个单词

您需要在Result中指定元素计数和索引。交替调用。

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);
    }
}