1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| #include <sapi.h> #include <sphelper.h>
bool isCreatWavFile = false;
int main() { ISpVoice* pVoice = NULL; if (FAILED(::CoInitialize(NULL))) return FALSE; HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void**)&pVoice); if (SUCCEEDED(hr)) { if (isCreatWavFile) { CComPtr <ISpStream> cpWavStream; CComPtr <ISpStreamFormat> cpOldStream; CSpStreamFormat originalFmt; pVoice->GetOutputStream(&cpOldStream); originalFmt.AssignFormat(cpOldStream); hr = SPBindToFile(L"d:\\output.wav", SPFM_CREATE_ALWAYS, &cpWavStream, &originalFmt.FormatId(), originalFmt.WaveFormatExPtr()); if (SUCCEEDED(hr)) { pVoice->SetOutput(cpWavStream, TRUE); WCHAR WTX[] = L"凡事何必都看淡,自己理解就很好,决定我们一生的,是我们的选择。我们时刻都在失去,我们努力的想去拥有更多的精彩,可惜只有两只手,所以必须学会选择,学会放弃。要清楚哪些是我们不需要的,如果心的欲望太大,什么都想抓,可能最后什么知足心灵。只平淡命运无奈"; pVoice->Speak(WTX, SPF_IS_XML, NULL); pVoice->Release(); pVoice = NULL; } } else { hr = pVoice->Speak(L"Hello World", 0, NULL); pVoice->Release(); pVoice = NULL; } }
::CoUninitialize(); return TRUE; }
|
如果运行过程中出现error C4996:’GetVersionExW’:被声明为已否决的错误,请请右键-项目-属性-C/C++-常规-SDL检查-否(/sdl)就可解决。
转自:https://blog.csdn.net/wuquanl/article/details/79525314