问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/7224902/how-to-fix-compiler-errors-in-sapi-5-1-header-files