如何使用C#在SAPI 5.4的听写中获得备用单个单词?

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

目前,我可以在C#中获得备用整句,但我需要得到单个单词。 例如,如果有人说“你好,我的名字是安德鲁”,我想得到“你好”,“我的”,“名字”,“是”和“安德鲁”的替代词,而不是完整的替代词。句子。

这是我正在使用的处理程序的代码片段。

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

任何想法都表示赞赏。

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

例如,

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