Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 使用Microsoft SAPI 5.4进行语音识别:如何获取字长?_Windows_Exception_Speech Recognition_Sapi - Fatal编程技术网

Windows 使用Microsoft SAPI 5.4进行语音识别:如何获取字长?

Windows 使用Microsoft SAPI 5.4进行语音识别:如何获取字长?,windows,exception,speech-recognition,sapi,Windows,Exception,Speech Recognition,Sapi,我正在用C#语言用微软SAPI 5.4开发一个语音识别应用程序。我正在Windows 7下使用VS 2012 Express 我想获取音频文件中已识别单词的持续时间。 我使用以下代码迭代识别的单词: void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { if (e.Result != null) { foreach (RecognizedWordUnit wo

我正在用C#语言用微软SAPI 5.4开发一个语音识别应用程序。我正在Windows 7下使用VS 2012 Express

我想获取音频文件中已识别单词的持续时间。 我使用以下代码迭代识别的单词:

    void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) {
        if (e.Result != null) {
            foreach (RecognizedWordUnit word in e.Result.Words) {
                try {
                    RecognizedAudio audio = e.Result.GetAudioForWordRange(word, word);
                    TimeSpan wordDuration = audio.Duration;
                    Console.WriteLine(word.Text + ": "  + wordDuration.ToString(@"s\.ff");
                } catch (Exception ex) {
                    Console.WriteLine(ex.ToString());
                }
            }

        }
    } 
它在某种程度上是有效的,但我只知道每个句子的前几个单词的持续时间。另一个在System.Speech.dll中生成System.ArgumentOutOfRangeException

但是,如果我查看调试器中的单词(private)members,它们的持续时间都是正确的


出什么事了?

嗯,听起来像个虫子。我假设在代码循环时数据在变化。使用调试器的优点是,它将冻结应用程序,不允许进行更多的识别。请在Winforms应用程序中尝试此操作,以便线程具有正确的单元状态,这对于像这样的COM api来说总是很重要的。您可以在connect.microsoft.com上提交错误报告,不要期待奇迹发生。@Hans我提到的代码已经在Winform中了。