gpt4 book ai didi

c++ - 在 SAPI 中说出进度事件

转载 作者:行者123 更新时间:2023-12-03 12:49:23 28 4
gpt4 key购买 nike

我正在尝试使用 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 来做到这一点?

最佳答案

ISpVoice 继承自 ISpEventSource ,它又继承自 ISpNotifySource .

使用ISpEventSource::SetInterest()注册所需事件的方法,例如 SPEI_WORD_BOUNDARY:

A word is beginning to synthesize. Markup language (XML) markers are counted in the boundaries and offsets. wParam is the character length of the word in the current input stream being synthesized. lParam is the character position within the current text input stream of the word being synthesized.

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

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

关于c++ - 在 SAPI 中说出进度事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44638514/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com