基于SPEECH5.0的语音组件,需要相应开发包联合编译
// speechX.h : CspeechX 的声明
#pragma once
#include "resource.h" // 主符号
// IspeechX
[
object,
uuid("25246261-2CD8-4D9C-AC51-D5184D1572C4"),
dual, helpstring("IspeechX 接口"),
pointer_default(unique)
]
__interface IspeechX : IDispatch
{
[id(1), helpstring("方法Read")] HRESULT Read(BSTR text);
[propget, id(2), helpstring("属性 HearedWord")] HRESULT HearedWord([out, retval] BSTR* pVal);
[id(3), helpstring("方法StartH")] HRESULT StartH(void);
[propget, id(4), helpstring("属性 IsHearing")] HRESULT IsHearing([out, retval] BOOL* pVal);
};
// CspeechX
[
coclass,
threading("apartment"),
vi_progid("speech.speechX"),
progid("speech.speechX.1"),
version(1.0),
uuid("D72932F4-000C-4EF7-BAD4-FC5F616CD9E3"),
helpstring("speechX Class")
]
class ATL_NO_VTABLE CspeechX :
public IspeechX
{
private:
//朗读
CComPtr<ISpVoice> m_cpVoice;
//上下文
CComPtr<ISpRecoContext> cpRecoCtxt;
//语法分析
CComPtr<ISpRecoGrammar> cpGrammar;
//语音结果
CComPtr<ISpRecoResult> cpResult;
//听到的单词
_bstr_t m_hear;
//朗读的单词
_bstr_t m_text;
//退出接收标志
BOOL m_quitflag;
//结果
HRESULT &nbs