关闭

VS2005下调用MS Speech API 5.1, 在添加“sphelper.h”头文件出现的问题,及解决方法

3136人阅读 评论(3) 收藏 举报

在利用微软的SAPI开发语音合成程序,当添加头文件#include "sphelper.h"时出现了类似下面的error和warning: 

 

1>c:/program files/microsoft speech sdk 5.1/include/spdebug.h(274) : warning C4996: 'wcscpy' was declared deprecated
1> c:/program files/microsoft visual studio 8/vc/include/string.h(250) : see declaration of 'wcscpy'
1> Message: 'This function or variable may be unsafe. Consider using wcscpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>c:/program files/microsoft speech sdk 5.1/include/sphelper.h(89) : warning C4267: 'initializing' : conversion from 'size_t' to 'ULONG', possible loss of data
1>c:/program files/microsoft speech sdk 5.1/include/sphelper.h(150) : warning C4267: 'return' : conversion from 'size_t' to 'unsigned int', possible loss of data
1>c:/program files/microsoft speech sdk 5.1/include/sphelper.h(169) : warning C4267: 'initializing' : conversion from 'size_t' to 'ULONG', possible loss of data
1>c:/program files/microsoft speech sdk 5.1/include/sphelper.h(226) : warning C4267: 'initializing' : conversion from 'size_t' to 'ULONG', possible loss of data
1>c:/program files/microsoft speech sdk 5.1/include/sphelper.h(227) : warning C4267: 'initializing' : conversion from 'size_t' to 'ULONG', possible loss of data
1>c:/program files/microsoft speech sdk 5.1/include/sphelper.h(334) : warning C4267: 'initializing' : conversion from 'size_t' to 'ULONG', possible loss of data
1>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
1>c:/program files/microsoft speech sdk 5.1/include/sphelper.h(769) : warning C4267: 'initializing' : conversion from 'size_t' to 'const int', possible loss of data
1>c:/program files/microsoft speech sdk 5.1/include/sphelper.h(772) : warning C4267: 'initializing' : conversion from 'size_t' to 'ULONG', possible loss of data
1>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
1>c:/program files/microsoft speech sdk 5.1/include/sphelper.h(2373) : error C2065: 'psz' : undeclared identifier
1>c:/program files/microsoft speech sdk 5.1/include/sphelper.h(2544) : warning C4267: '+=' : conversion from 'size_t' to 'ULONG', possible loss of data
1>c:/program files/microsoft speech sdk 5.1/include/sphelper.h(2559) : error C2440: 'initializing' : cannot convert from 'CSpDynamicString' to 'SPPHONEID *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>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 *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

 

一开始,始终觉得是自己程序的问题,可找了半天还是没有找到原因,在网上搜索了一下,发现有不少网友曾遇到此类问题,可始终没有找到很好的解决办法。有位网友提出在vc6下下做个dll,然后放到vs2005下去调用,此方法不失为一个好方法。可还是不甘心,觉得太麻烦!继续搜索,终于在MS的论坛上发现一篇帖子是针对这个问题的,其中有位名叫Pete Baron 的网友提出了解决办法,个人觉得此方法比较方便实用,在此提供,以方便其他好友参考:

I'm not sure if these steps 'fix' the errors, but they permit the code to compile (honestly, I couldn't be bothered to try and decode the awful code in that file so I just used best-guess to what was intended in each case).  I didn't test speech-to-text, but the text-to-speech will definitely work correctly.

1) line 2560
    SPPHONEID* pphoneId = (SPPHONEID*)((WCHAR *)dsPhoneId);

2) line 2634
    pphoneId += wcslen((const wchar_t *)pphoneId) + 1;

3) line 2372 and 2373
        const WCHAR *psz;
        for (psz = (const WCHAR *)lParam; *psz; psz++) {}

4) add to the top of the file to prevent all the other errors...
#pragma warning( disable : 4430 )

I also added another line to prevent a stream of 'deprecated function' warnings
#pragma warning( disable : 4996 )



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:16832次
    • 积分:274
    • 等级:
    • 排名:千里之外
    • 原创:6篇
    • 转载:22篇
    • 译文:0篇
    • 评论:5条