次のコードを見てください
main.cpp
#define _ATL_APARTMENT_THREADED
#include <atlbase.h>
//You may derive a class from CComModule and use it if you want to override something,
//but do not change the name of _Module
extern CComModule _Module;
#include <atlcom.h>
#include <sapi.h>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
cout << "Hello" << endl;
ISpVoice * pVoice = NULL;
if (FAILED(::CoInitialize(NULL)))
return FALSE;
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
if( SUCCEEDED( hr ) )
{
cout << "Succeeded" << endl;
hr = pVoice->Speak(L"Hello world", 0, NULL);
pVoice->Release();
pVoice = NULL;
}
else
{
cout << "Not succeeded" << endl;
}
::CoUninitialize();
return TRUE;
}
このコードを実行すると、ウィンドウが開き、「Hello」メッセージが出力されます。なのに音が出ない!「Hello World」と話すはずです!どうしてこれなの?
以下は、必要な場合の QT .pro 設定です。
以下はQT .proの設定です
#-------------------------------------------------
#
# Project created by QtCreator 2013-05-03T14:31:00
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = Speech
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += "C:/Program Files/Microsoft Speech SDK 5.1/Bin"
INCLUDEPATH += "C:/Program Files/Microsoft Speech SDK 5.1/Include"
LIBS += "C:/Program Files/Microsoft Speech SDK 5.1/Lib/i386/sapi.lib"
LIBS += "C:/Program Files/Microsoft SDKs/Windows/v7.0A/Lib/User32.lib"