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

时间:2011-08-29 00:10:02

标签: visual-studio-2008 visual-c++ text-to-speech sapi

我从SAPI 5.1提供的头文件中收到了很多错误,但无法弄清楚如何解决这些问题。

以下是来自Microsoft’s How to Video Presentation的简单文字转语音程序。演示者说,如果你安装了最新的软件包,那么编译这个程序就没问题了。但他正在使用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 speech 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 speech sdk 5.1 \ include \ sphelper.h(769):   错误C4430:缺少类型说明符 - 假定为int。注意:C ++没有   支持default-int

     

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

     

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

     

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

     

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

1 个答案:

答案 0 :(得分:2)

请使用"\Program Files\Microsoft SDKs\Windows\v6.0A"或7.0或7.0A计算机上的最新版本。

SAPI DLL和libs +头文件在那里,与VS2008兼容

享受。

相关问题