如何修复 SAPI 5.1 头文件中的编译器错误

发布于 2024-12-01 17:39:48 字数 2570 浏览 2 评论 0原文

我从 SAPI 5.1 提供的头文件中得到了很多错误,并且不知道如何解决这些问题。

以下是来自Microsoft 的如何视频演示的简单文本转语音程序。演示者说,如果你安装了最新的软件包,那么编译这个程序就没有问题。但他使用的是 Video Studio 2005;显然,“最新”指的是几年前进行演示时的情况。

我认为这些错误是由于版本不匹配造成的。我使用的是Windows XP SP3。我有 Visual Studio 2008 SP1、Visual Studio 2008 SDK 1.1、Windows SDK v6.0A(VS2008 附带)、Windows SDK v7.0 和 SAPI 5.1。有人可以帮我解决这些问题吗?

TTSdemo.cpp

#include <windows.h>
#include <atlbase.h>
#include <sapi.h>
#include <sphelper.h>
#include <string>
#include <iostream>

int wmain(int argc, wchar_t **argv)
{
    int i;
    ULONG n;
    HRESULT hr;
    std::wstring args;
    CComPtr<ISpObjecToken> token;
    CComPtr<ISpVoice> tts;
    CoInitialize(0);

    for (i = 1, args = L""; i < argc; i++ )
    {
        args.append( argv[i] );
        args.append( L" " );
    }

    tts.CoCreateInstance(CLSID_SpVoice);
    hr = SpGetDefaultTokenFromCategoryId(SPCAT_VOICES, &token, FALSE);
    hr = tts->SetVoice(token);

    if (args.length() == 0 )
        std::wcout << L"Enter @<text file name> or <text to speak>" << STD::endl;
    else if ( args(0) == L'@' )
        tts->Speak(args.c_str() + 1, SPF_IS_FILENAME | SPF_ASYNC, &n);
    else
        tts->Speak(args.c_str(), SPF_IS_XML | SPF_ASYNC, &n);

    tts->WaitUntilDone(-1);

    tts.Release();
    token.Release();

    CoUninitialize();

    return 0;
}

编译器错误

c:\program files\microsoft 语音 sdk 5.1\include\spdebug.h(274) : 警告 C4996:“wcscpy”:此函数或变量可能不安全。 考虑使用 wcscpy_s 代替。要禁用弃用,请使用 _CRT_SECURE_NO_WARNINGS。有关详细信息,请参阅联机帮助。

c:\program files\microsoft Visual Studio 9.0\vc\include\string.h(252) :参见“wcscpy”的声明

c:\program files\microsoft 语音 sdk 5.1\include\sphelper.h(769) : 错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 没有 支持默认int

c:\program files\microsoft voice sdk 5.1\include\sphelper.h(1419): 错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 没有 支持默认int

c:\program files\microsoft 语音 sdk 5.1\include\sphelper.h(2373) : 错误 C2065:'psz':未声明的标识符

c:\program files\microsoft voice sdk 5.1\include\sphelper.h(2559): 错误 C2440:“初始化”:无法从“CSpDynamicString”转换 到 'SPPHONEID *' 没有可用的用户定义转换运算符 可以执行此转换,否则无法调用该运算符

c:\program files\microsoft voice sdk 5.1\include\sphelper.h(2633): 错误 C2664:“wcslen”:无法从“SPPHONEID *”转换参数 1 到“const wchar_t *” 指向的类型不相关;转换需要reinterpret_cast、C 风格转换或函数风格转换

I got a lot of errors from SAPI 5.1 provided header files and cannot figure out how to fix those problems.

Following is a simple Text to Speech program from Microsoft’s How to Video Presentation. The presenter said, if you have installed the most updated packages, you will have no problem compile this program. But he is using Video Studio 2005; apparently the “most updated” refers a few years ago when the presentation was given.

I think these errors are caused version miss match. I am using Windows XP SP3. I have Visual Studio 2008 SP1, Visual Studio 2008 SDK 1.1, Windows SDK v6.0A(come with VS2008), Windows SDK v7.0 and SAPI 5.1. Can someone help me figure out these problems?

TTSdemo.cpp

#include <windows.h>
#include <atlbase.h>
#include <sapi.h>
#include <sphelper.h>
#include <string>
#include <iostream>

int wmain(int argc, wchar_t **argv)
{
    int i;
    ULONG n;
    HRESULT hr;
    std::wstring args;
    CComPtr<ISpObjecToken> token;
    CComPtr<ISpVoice> tts;
    CoInitialize(0);

    for (i = 1, args = L""; i < argc; i++ )
    {
        args.append( argv[i] );
        args.append( L" " );
    }

    tts.CoCreateInstance(CLSID_SpVoice);
    hr = SpGetDefaultTokenFromCategoryId(SPCAT_VOICES, &token, FALSE);
    hr = tts->SetVoice(token);

    if (args.length() == 0 )
        std::wcout << L"Enter @<text file name> or <text to speak>" << STD::endl;
    else if ( args(0) == L'@' )
        tts->Speak(args.c_str() + 1, SPF_IS_FILENAME | SPF_ASYNC, &n);
    else
        tts->Speak(args.c_str(), SPF_IS_XML | SPF_ASYNC, &n);

    tts->WaitUntilDone(-1);

    tts.Release();
    token.Release();

    CoUninitialize();

    return 0;
}

Compiler errors

c:\program files\microsoft speech sdk 5.1\include\spdebug.h(274) :
warning C4996: 'wcscpy': This function or variable may be unsafe.
Consider using wcscpy_s instead. To disable deprecation, use
_CRT_SECURE_NO_WARNINGS. See online help for details.

c:\program files\microsoft visual studio 9.0\vc\include\string.h(252)
: see declaration of 'wcscpy'

c:\program files\microsoft speech sdk 5.1\include\sphelper.h(769) :
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int

c:\program files\microsoft speech sdk 5.1\include\sphelper.h(1419) :
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int

c:\program files\microsoft speech sdk 5.1\include\sphelper.h(2373) :
error C2065: 'psz' : undeclared identifier

c:\program files\microsoft speech sdk 5.1\include\sphelper.h(2559) :
error C2440: 'initializing' : cannot convert from 'CSpDynamicString'
to 'SPPHONEID *' No user-defined-conversion operator available that
can perform this conversion, or the operator cannot be called

c:\program files\microsoft speech sdk 5.1\include\sphelper.h(2633) :
error C2664: 'wcslen' : cannot convert parameter 1 from 'SPPHONEID *'
to 'const wchar_t *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分分钟 2024-12-08 17:39:48

请使用 "\Program Files\Microsoft SDKs\Windows\v6.0A" 或 7.0 或 7.0A(无论您的计算机上有什么最新版本)。

SAPI DLL 和库 + 头文件都在那里,与 VS2008

Enjoy 兼容。

Please use "\Program Files\Microsoft SDKs\Windows\v6.0A" or 7.0 or 7.0A whatever latest available on your computer.

The SAPI DLL's and libs + header files are there, compatible for VS2008

Enjoy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文