gpt4 book ai didi

C++ : How to use SAPI with QT Creator?

转载 作者:行者123 更新时间:2023-11-30 05:41:56 27 4
gpt4 key购买 nike

我必须做一个项目,包括创建一个包含文本到语音解决方案的网络浏览器。我使用了 MSDN ( here ) 中的示例,但是当我尝试编译我的项目时,出现了很多错误,而且我还没有找到任何解决方案...

我正在为这个项目使用 QT Creator。

The console output

这是我的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。

关于C++ : How to use SAPI with QT Creator?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30941605/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com