我正在尝试使用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做到这一点?
答案 0 :(得分:0)
c.OAuth2("oauth2")
.Description("OAuth2 Implicit Grant")
.Flow("implicit")
.AuthorizationUrl(
string.Format("https://login.microsoftonline.com/{0}/oauth2/authorize",
ConfigurationManager.AppSettings["ida:Tenant"]))
.Scopes(scopes =>
{
scopes.Add("AdminAccess", "Admin access to protected resources");
scopes.Add("FullAccess", "Full access to protected resources");
scopes.Add("UpdateAccess", "Update access to protected resources");
scopes.Add("ReadAcces", "Read access to protected resources");
});
继承自ISpEventSource
,后者继承自ISpNotifySource
。
使用ISpEventSource::SetInterest()
方法注册所需的活动,例如ISpVoice
:
一个词开始合成。标记语言(XML)标记在边界和偏移中计算。
SPEI_WORD_BOUNDARY
是正在合成的当前输入流中的单词的字符长度。wParam
是正在合成的单词的当前文本输入流中的字符位置。
使用各种lParam
方法指定您希望如何从SAPI接收事件:
SetNotifySink()
通过您提供的ISpNotifySink
界面接收活动。
SetNotifyWindowMessage()
以ISpNotifySource::SetNotify...()
您选择的方式接收活动。
SetNotifyCallbackFunction()
接收您提供的回调函数中的事件。
SetNotifyCallbackInterface()
通过您提供的ISpNotifyCallback
界面接收活动。
SetNotifyWin32Event
创建一个事件对象,在新事件到达时发出信号。要等待活动,请使用ISpNotifySource::WaitForNotifyEvent()
或ISpNotifySource::GetNotifyEventHandle
标准Win32 wait functions,例如WaitForSingleObject()
。
当您收到新活动的通知时,如果需要,请使用ISpEventSource::GetEvents()
获取详细的活动信息。