【问题标题】:Speak Progress Event in SAPI在 SAPI 中说出进度事件
【发布时间】:2017-06-19 19:32:50
【问题描述】:

我正在尝试使用 Microsoft SAPI 编写文本转语音程序。为此,我有以下代码:

ISpVoice * pVoice = NULL;

int main(int argc, char* argv[])
{

    if (FAILED(::CoInitialize(NULL)))
        return FALSE;

    HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
    if (SUCCEEDED(hr))
    {
        hr = pVoice->Speak(L"Anyone who reads Old and Middle English literary texts will be familiar with the mid-brown volumes of the EETS, with the symbol of Alfred's jewel embossed on the front cover. Most of the works attributed to King Alfred or to Aelfric, along with some of those by bishop Wulfstan and much anonymous prose and verse from the pre-Conquest period, are to be found within the Society's three series; all of the surviving medieval drama, most of the Middle English romances, much religious and secular prose and verse including the English works of John Gower, Thomas Hoccleve and most of Caxton's prints all find their place in the publications. Without EETS editions, study of medieval English texts would hardly be possible.", SPF_IS_XML, NULL);
        pVoice->Release();
        pVoice = NULL;
    }
    ::CoUninitialize();
    return TRUE;
}

我想将说话进度打印到屏幕上,在说出每个单词时打印它。类似System.Speech.Synthesis

synth.SpeakProgress += new EventHandler<SpeakProgressEventArgs>(synth_SpeakProgress);

更多详情:Use Speech Synthesis Events

那么,我怎样才能使用 SAPI 做到这一点?

【问题讨论】:

    标签: c++ text-to-speech sapi


    【解决方案1】:

    ISpVoice 继承自 ISpEventSource,后者又继承自 ISpNotifySource

    使用ISpEventSource::SetInterest()方法注册想要的事件,比如SPEI_WORD_BOUNDARY

    一个词开始合成。标记语言 (XML) 标记计入边界和偏移量。 wParam 是当前正在合成的输入流中单词的字符长度。 lParam 是正在合成的单词在当前文本输入流中的字符位置。

    使用各种 ISpNotifySource::SetNotify...() 方法来指定您希望如何从 SAPI 接收事件:

    当您收到新活动的通知时,如果需要,请使用ISpEventSource::GetEvents() 获取详细的活动信息。

    【讨论】:

      猜你喜欢
      • 2016-07-22
      • 1970-01-01
      • 1970-01-01
      • 2017-05-17
      • 1970-01-01
      • 2012-06-28
      • 1970-01-01
      • 2017-01-21
      • 1970-01-01
      相关资源
      最近更新 更多