在C#中使用SpVoice / SpFileStream时如何触发/运行事件

时间:2016-01-14 08:53:25

标签: c#

我正在使用SpVoice使用SpFileStream生成音频文件。 我需要几个关于文本的信息,这些信息是spooken,f.ex字边界。 我尝试在单词结束时添加一些事件来执行。 但是eventHandler没有按预期运行。

我尝试按照指定的here SpVoice (Events) Interface (SAPI 5.3)

进行操作

代码:

    public void SpeakToFile(String toSpeak, string id)
    {
        SpVoice voiceNew = new SpVoice();
        voiceNew.EventInterests = SpeechVoiceEvents.SVEWordBoundary;
        voiceNew.Word +=VoiceNewOnWord;

        SpFileStream outStream = new SpFileStream();

        string wavPath = _fileHelper.GetTempFileNameWav(id);
        outStream.Open(wavPath, SpeechStreamFileMode.SSFMCreateForWrite, DoEvents:true);        

        voiceNew.AudioOutputStream = outStream;
        voiceNew.Speak(toSpeak);
        outStream.Close();
    }

    private void VoiceNewOnWord(int streamNumber, object streamPosition, int characterPosition, int length)
    {
        Boundary boundary = new Boundary();
        boundary.StreamPosition = streamPosition.ConvertTo<long>();
        boundary.CharacterPosition = characterPosition;
        boundary.Length = length;
        log.Info("word_boundary2: - strPos : " + boundary.StreamPosition + " - charPos : " + boundary.CharacterPosition + " - length : " + boundary.Length);
    }

任何?

0 个答案:

没有答案