Based on Speech 5.0-based voice components, the corresponding development package is required to compile // speechx.h: cspeechx declaration
#pragma overce # include "resource.h" // master symbol
// IspeechX [object, uuid ( "25246261-2CD8-4D9C-AC51-D5184D1572C4"), dual, helpstring ( "IspeechX Interface"), pointer_default (unique)] __ interface IspeechX: IDispatch {[id (1), helpstring ( " Method Read ")] HRESULT READ (BSTR text); [Propget, ID (2), Helpstring (" Properties Hearedword ")] HRESULT Hearedword ([OUT, RETVAL] BSTR * PVAL); [ID (3), Helpstring (" Method StartH ")] HRESULT STARTH (VOID);
[PropGet, ID (4), Helpstring ("Properties 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: // read CComPtr
}
Declare_protect_final_construct ()
HRESULT FinalConstruct () {return S_OK;} void FinalRelease () {m_cpVoice.Release (); cpRecoCtxt.Release (); cpGrammar.Release (); cpResult.Release ();} protected: inline HRESULT BlockForResult (ISpRecoContext * pRecoCtxt, ISpRecoResult ** ppResult);
PUBLIC:
STDMETHOD (READ); HRESULT READ (WCHAR * PATH); stdmethod (BSTR * PVAL); stdmethod (vers); stdmethod (BOOL * PVAL);}; --------------------------------------- // Speechx.cpp: cspeechx
#include "stdafx.h" #include "speechx.h" #include "sphelper.h"
// CSPEECHX
STDMETHODIMP CSPEECHX :: read (bstr text) {m_text = text; read (wchar *) m_text); // Release BSTR, misunderstanding sysfreestring (text) during debugging; returnif;}
STDMETHODIMP CspeechX :: StartH (void) {m_quitflag = true; hr = cpRecoCtxt.CoCreateInstance (CLSID_SpSharedRecoContext); // set the context if (cpRecoCtxt && SUCCEEDED (hr = cpRecoCtxt-> SetNotifyWin32Event ()) && SUCCEEDED (hr = cpRecoCtxt-> SetInterest (SPFEI (SPEI_RECOGNITION), SPFEI (SPEI_RECOGNITION))) && SUCCEEDED (hr = cpRecoCtxt-> SetAudioOptions (SPAO_RETAIN_AUDIO, NULL, NULL)) && SUCCEEDED (hr = cpRecoCtxt-> CreateGrammar (0, & cpGrammar)) && SUCCEEDED (hr = cpGrammar -> LoadDictation (NULL, SPLO_STATIC)) && SUCCEEDED (hr = cpGrammar-> SetDictationState (SPRS_ACTIVE))) {if (SUCCEEDED (hr = BlockForResult (cpRecoCtxt, & cpResult))) {cpGrammar-> SetDictationState (SPRS_INACTIVE); WCHAR * dstrText ;
if (SUCCEEDED (cpResult-> GetText (SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, TRUE, & dstrText, NULL))) {m_hear = dstrText; cpResult.Release ();} cpGrammar-> SetDictationState (SPRS_ACTIVE);
} Cprecockxt.release (); cpgrammar.release (); cpresult.release ();
m_quitflag = false; return s_ok;}
HRESULT CSPEECHX :: Read (Wchar * PATH) {
HR = m_cpvoice.coCreateInstance (CLSID_SPVoice); m_cpvoice-> speak (path, 0, null); m_cpvoice.release ();
Return S_OK;
// Receive the information interface stdmethodimp cspeechx :: get_hearedword (bstr * pval) {* pval = m_hear;
Return S_OK;
// Pack the context into the result inline hResult cspeechx :: blockforResult (isprecocontext * presidex) {hResult hr = s_ok; cspevent eve;
While (ac = event.getfrom (preside)) && hr == s_false) {hr = presideXT-> WaitforNotifyEvent (Infinite);
* ppResult = event.recoresult (); if (* ppResult) {(* ppResult) -> addref ();
Return hr;}
STDMETHODIMP CSPEECHX:: GET_ISHEARING (BOOL * PVAL) {* pval = m_quitflag;
Return S_OK;