SpeechCore.h

Go to the documentation of this file.
00001 /* ========================================================================
00002  * Copyright (c) 2006,
00003  * Institute for Computer Graphics and Vision
00004  * Graz University of Technology
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are
00009  * met:
00010  *
00011  * Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the following disclaimer.
00013  *
00014  * Redistributions in binary form must reproduce the above copyright
00015  * notice, this list of conditions and the following disclaimer in the
00016  * documentation and/or other materials provided with the distribution.
00017  *
00018  * Neither the name of the Graz University of Technology nor the names of
00019  * its contributors may be used to endorse or promote products derived from
00020  * this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00023  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00024  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00025  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00026  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00027  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00028  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00029  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00030  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  * ========================================================================
00034  * PROJECT: OpenTracker
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         // protected static data members
00083     protected:
00084         static DWORD s_GrammarId;               
00085 
00086 
00087         // protected data members
00088     protected:
00089         bool m_Initialized;                     
00090 
00091         unsigned m_NextRuleId;                     
00092         std::vector<SpeechSetBase*> m_SpeechSets;  
00093 
00094 
00095         // protected init & destroy methods
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         // constructor & destructor
00119     public:
00120         SpeechCoreBase()
00121         {
00122             Initialize();
00123         }
00124 
00125         virtual ~SpeechCoreBase()
00126         {
00127             Destroy();
00128         }
00129 
00130 
00131         // public methods
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 } // namespace ot
00172 
00173 #ifdef USE_SAPISPEECH
00174 
00175 #include "SpeechInc.h"
00176 
00188 namespace ot {
00189 
00190     class CSpeechCore : public SpeechCoreBase
00191     {
00192         // protected static data members
00193     protected:
00194         static DWORD s_GrammarId;               
00195 
00196 
00197         // protected data members
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         // protected init & destroy methods
00210     protected:
00211         void Initialize();    
00212     public:
00213         void Destroy();       
00214 
00215 
00216         // constructor & destructor
00217     public:
00218         CSpeechCore()
00219         {
00220             Initialize();
00221         }
00222 
00223         virtual ~CSpeechCore()
00224         {
00225             Destroy();
00226         }
00227 
00228 
00229         // public methods
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 } // namespace ot
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  *   End of SpeechCore.h
00296  * ------------------------------------------------------------
00297  *   Automatic Emacs configuration follows.
00298  *   Local Variables:
00299  *   mode:c++
00300  *   c-basic-offset: 4
00301  *   eval: (c-set-offset 'substatement-open 0)
00302  *   eval: (c-set-offset 'case-label '+)
00303  *   eval: (c-set-offset 'statement 'c-lineup-runin-statements)
00304  *   eval: (setq indent-tabs-mode nil)
00305  *   End:
00306  * ------------------------------------------------------------ 
00307  */

Generated on Wed Feb 28 15:18:49 2007 for NaviTrack by  doxygen 1.4.6