[英]C++ : How to use SAPI with QT Creator?
我必須做一個項目,該項目包括創建一個包含文本到語音解決方案的網絡瀏覽器。 我使用了來自MSDN的示例( 在此處 ),但是當我嘗試編譯我的項目時,我遇到了很多錯誤,而且我還沒有找到任何解決方案...
我正在為此項目使用QT Creator。
這是我的project.pro:
#-------------------------------------------------
#
# Project created by QtCreator 2015-06-18T15:14:25
#
#-------------------------------------------------
QT += widgets webkitwidgets network multimedia
TARGET = Project
TEMPLATE = app
SOURCES += main.cpp \
browser.cpp
HEADERS += \
browser.h
unix|win32: LIBS += -lsapi
而我的main.cpp:
#include <sapi.h>
#include "sphelper.h"
int main(int argc, char *argv[])
{
ISpVoice *pVoice;
pVoice = NULL;
HRESULT hr = SpCreateBestObject(SPCAT_VOICES, L”Gender=Female”, NULL, &pVoice);
// --> I tried with HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);, that's the same result...
if( SUCCEEDED( hr ) )
{
hr = pVoice->Speak(L"Hello world", 0, NULL);
pVoice->Release();
pVoice = NULL;
}
return 0;
}
謝謝你的幫助!
這可能是我能想到的最簡單的示例,它將適用於MSVC。 我認為QT Creator不會有太大不同。
#include <sapi.h>
#include <sphelper.h>
#include <conio.h>
int main(int argc, char *argv[]){
HRESULT hr = S_OK;
CComPtr<ISpVoice> cpVoice;
::CoInitialize(NULL);
hr = cpVoice.CoCreateInstance(CLSID_SpVoice);
if(SUCCEEDED(hr)){
cpVoice->Speak(L"This is a test phrase.", SPF_DEFAULT, NULL);
cpVoice.Release();
}
puts("Press any key to continue...");
getch();
}
此代碼將獲取默認語音並開始講話。 在Windows 7中,該聲音將為MS Anna。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.