bool TextToSpeech::say(string wordToSay)
{
	//convert string to wstring to use with speech function
	wstring wstr(wordToSay.begin(), wordToSay.end());

	ISpVoice * pVoice = NULL;

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

	HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
	if (SUCCEEDED(hr))
	{
		long rate = -5;
		pVoice->SetRate(rate);
		hr = pVoice->Speak(wstr.c_str(), 0, NULL);
		pVoice->Release();
		pVoice = NULL;
	}

	::CoUninitialize();
	return TRUE;
}
示例#2
0
文件: main.cpp 项目: df32/TTS
	HRESULT SetRate(long RateAdjust)	//设置语速(同上)
	{
		return VoiceObj->SetRate(RateAdjust);
	}