00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00042
00043
00044
00045
00046 #if !defined(__SPEECHCORE_H)
00047 #define __SPEECHCORE_H
00048
00049 #include "../OpenTracker.h"
00050
00051 #include "SpeechDef.h"
00052 #include "SpeechSet.h"
00053
00075 #ifndef OT_NO_SPEECH_SUPPORT
00076
00077
00078 namespace ot {
00079
00080 class SpeechCoreBase
00081 {
00082
00083 protected:
00084 static DWORD s_GrammarId;
00085
00086
00087
00088 protected:
00089 bool m_Initialized;
00090
00091 unsigned m_NextRuleId;
00092 std::vector<SpeechSetBase*> m_SpeechSets;
00093
00094
00095
00096 protected:
00098 virtual void Initialize(void)
00099 {
00100 m_Initialized = false;
00101 m_NextRuleId = 1;
00102 };
00103
00104 public:
00106 virtual void Destroy(void)
00107 {
00108 try
00109 {
00110 for(int i = m_SpeechSets.size() - 1; i >= 0; --i)
00111 delete(m_SpeechSets[i]);
00112 m_SpeechSets.clear();
00113 }
00114 catch(...) {}
00115 m_Initialized = false;
00116 };
00117
00118
00119 public:
00120 SpeechCoreBase()
00121 {
00122 Initialize();
00123 }
00124
00125 virtual ~SpeechCoreBase()
00126 {
00127 Destroy();
00128 }
00129
00130
00131
00132 public:
00134 virtual void Init(void)
00135 {
00136 Destroy();
00137 Initialize();
00138 m_Initialized = true;
00139 };
00140
00141
00143 virtual SpeechSetBase * GetSpeechSet(const char *p_Name, bool p_Create = true);
00144
00146 virtual SpeechSetBase* GetSpeechSet(DWORD p_Id);
00147
00148
00150 virtual void RemoveSpeechSet(const char *p_Name);
00151
00153 virtual void RemoveSpeechSet(DWORD p_Id);
00154
00155
00157 virtual SpeechSetBase* FindSpeechSet(const char *p_Command, bool p_Active = true);
00158
00160 virtual SpeechSetBase* FindSpeechSet(DWORD p_CommandId, bool p_Active = true);
00161
00163 virtual bool ProcessRecognitionPoll()
00164 {
00165 return false;
00166 };
00167
00168 friend class SpeechSetBase;
00169 };
00170
00171 }
00172
00173 #ifdef USE_SAPISPEECH
00174
00175 #include "SpeechInc.h"
00176
00188 namespace ot {
00189
00190 class CSpeechCore : public SpeechCoreBase
00191 {
00192
00193 protected:
00194 static DWORD s_GrammarId;
00195
00196
00197
00198 protected:
00199 bool m_Initialized;
00200
00201 CComPtr<ISpRecognizer> m_RecoEngine;
00202 CComPtr<ISpRecoContext> m_RecoCtxt;
00203 CComPtr<ISpRecoGrammar> m_CmdGrammar;
00204
00205 DWORD m_NextRuleId;
00206 std::vector<CSpeechSet*> m_SpeechSets;
00207
00208
00209
00210 protected:
00211 void Initialize();
00212 public:
00213 void Destroy();
00214
00215
00216
00217 public:
00218 CSpeechCore()
00219 {
00220 Initialize();
00221 }
00222
00223 virtual ~CSpeechCore()
00224 {
00225 Destroy();
00226 }
00227
00228
00229
00230 public:
00231
00232 void Init(void)
00233 {
00234 Init(MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT));
00235 };
00236
00238 void Init(LANGID p_LanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT));
00239
00240
00242 SpeechSetBase* GetSpeechSet(const char *p_Name, bool p_Create = true);
00243
00245 SpeechSetBase* GetSpeechSet(DWORD p_Id);
00246
00247
00249 void RemoveSpeechSet(const char *p_Name);
00250
00252 void RemoveSpeechSet(DWORD p_Id);
00253
00254
00256 SpeechSetBase* FindSpeechSet(const char *p_Command, bool p_Active = true);
00257
00259 SpeechSetBase* FindSpeechSet(DWORD p_CommandId, bool p_Active = true);
00260
00261
00263 void NotifyWindowMessage(HWND p_hWnd, UINT p_Msg = WM_USER+1, WPARAM p_wParam = 0, LPARAM p_lParam = 0);
00264
00266 bool ProcessRecognitionPoll();
00267
00269 bool GetReco(std::string &p_Result, std::string &p_SpeechSet);
00270
00271
00272 public:
00274 static void StrToWide(const char *p_String, std::wstring &p_WideString);
00276 static void WideToStr(const WCHAR *p_WideString, std::string &p_String);
00277
00278
00279
00280 friend class CSpeechSet;
00281 };
00282
00283 }
00284
00285 #endif //#ifdef USE_SAPISPEECH
00286
00287
00288 #endif // OT_NO_SPEECH_SUPPORT
00289
00290
00291 #endif //#if !defined(__SPEECHCORE_H)
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307