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

本文介绍在使用微软SAPI进行语音合成开发时遇到的编译错误及警告,并提供了解决这些问题的具体步骤和代码修改建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在利用微软的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 )



评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值