cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mtsCMUSphinx4.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Martin Kelly, Anton Deguet
7  Created on: 2011-02-15
8 
9  (C) Copyright 2011 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 */
20 
21 #ifndef _mtsCMUSphinx4_h
22 #define _mtsCMUSphinx4_h
23 
24 #include <map>
25 #include <string>
26 #include <sawCMUSphinx4/mtsCMUSphinx4Config.h>
27 
29 
30 // Always include last!
32 
33 // forward declaration of class containing all Java members
34 struct mtsCMUSphinx4Java;
35 class mtsCMUSphinx4;
36 
38 {
40 
41 
42 
43  public:
44  // forward declaration for context
45  class Context;
46 
48  {
50  friend class mtsCMUSphinx4::Context;
51 
52  bool IsTransition;
53  std::string EndContext;
54 
55  public:
56  WordActions(void);
57  WordActions(const std::string & endContext);
58 
59  bool PerformActions(mtsCMUSphinx4 * sphinx4) const;
60  };
61 
62 
64  {
66 
67  friend class mtsCMUSphinx4; // to allow speech to command to set pointer to itself
68 
69  mtsCMUSphinx4 * CMUSphinx4Wrapper;
71  WordMap Words;
72  std::string Name;
73  bool OutOfGrammarFiltering;
74 
75  bool AddWordWithActions(const std::string & word, WordActions * wordActions);
76 
77  Context(const std::string & name);
78  bool PerformActionsForWord(const std::string & word);
79 
80  public:
81  bool AddWord(const std::string & word);
82  bool AddWordWithTransition(const std::string & word, const std::string & endContext);
83  const std::string & GetName(void) const;
84  std::vector<std::string> GetVocabulary(void);
85  bool FilteringEnabled(void);
86  void SetFiltering(bool filter);
87  };
88 
89 
90 
91  friend void mtsCMUSphinx4JavaWordRecognizedCallback(mtsCMUSphinx4 * sphinx4Wrapper,
92  const std::string & word);
93 
97  unsigned int MicrophoneNumber;
98  std::string ModelFile;
99  std::string ModelTopDir;
100  std::string SphinxFile;
101  std::string TemplateFile;
102  std::string ConfigName;
103  std::string SphinxWrapperDir;
104 
108 
111 
112  mtsCMUSphinx4Java * JavaData;
113 
114  // method called by Java when a word has been recognized
115  void WordRecognizedCallback(const std::string & word);
116  // method to actually process the word, called periodically by Run
117  void HandleWord(const mtsStdString & word);
118 
119  bool ReplaceAll(std::string & base, const std::string & s, const std::string & t);
120  bool StartJava(void);
121  void PrintAudioDevices(void);
122 
123 public:
124  mtsCMUSphinx4(const std::string & componentName);
125 
126  Context * AddContext(const std::string & contextName);
127  bool SetCurrentContext(const std::string & name);
128  bool SetCurrentContext(const Context * context);
129  void GetContexts(stdStringVec & placeHolder) const;
130  void GetContextWords(const mtsStdString & contextName,
131  stdStringVec & placeHolder) const;
132  void WordTriggeredFromUI(const mtsStdString & word);
133 
134  unsigned int GetMicrophoneNumber(void) const;
135  void SetMicrophoneNumber(unsigned int microphoneNumber);
136 
137  // methods required for all tasks
138  void Configure(void);
139  void Startup(void);
140  void Run(void);
141  void Cleanup(void);
142 };
143 
147 
148 #endif // _mtsCMUSphinx4_h
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
void WordTriggeredFromUI(const mtsStdString &word)
Definition: mtsCMUSphinx4.h:37
std::string TemplateFile
Definition: mtsCMUSphinx4.h:101
Definition: mtsCMUSphinx4.h:63
void Cleanup(void)
mtsStdString LastWordRecognized
Definition: mtsCMUSphinx4.h:110
void Startup(void)
std::string SphinxFile
Definition: mtsCMUSphinx4.h:100
bool SetCurrentContext(const std::string &name)
Macros to export the symbols of cisstSpeechToCommands (in a DLL).
cmnNamedMap< Context > ContextMap
Definition: mtsCMUSphinx4.h:95
void GetContextWords(const mtsStdString &contextName, stdStringVec &placeHolder) const
std::vector< std::string > stdStringVec
Definition: mtsGenericObjectProxy.h:39
mtsMulticastCommandWriteBase * WordRecognizedTrigger
Definition: mtsCMUSphinx4.h:105
Base class for high level objects.
Definition: cmnGenericObject.h:51
std::string SphinxWrapperDir
Definition: mtsCMUSphinx4.h:103
Defines a continuously executing task.
CMN_DECLARE_SERVICES_INSTANTIATION(mtsCMUSphinx4::Context)
bool StartJava(void)
void Run(void)
unsigned int MicrophoneNumber
Definition: mtsCMUSphinx4.h:97
const std::string & GetName(void) const
Definition: mtsMulticastCommandVoid.h:46
Context * CurrentContext
Definition: mtsCMUSphinx4.h:94
mtsFunctionWrite ContextChangedTrigger
Definition: mtsCMUSphinx4.h:107
std::string Name
Definition: mtsComponent.h:160
std::string ModelFile
Definition: mtsCMUSphinx4.h:98
void PrintAudioDevices(void)
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition: cmnClassRegisterMacros.h:116
Definition: mtsMulticastCommandWriteBase.h:43
void Configure(void)
bool ReplaceAll(std::string &base, const std::string &s, const std::string &t)
mtsCMUSphinx4(const std::string &componentName)
bool NewWordRecognized
Definition: mtsCMUSphinx4.h:109
mtsMulticastCommandVoid * NoWordRecognizedTrigger
Definition: mtsCMUSphinx4.h:106
void HandleWord(const mtsStdString &word)
mtsCMUSphinx4Java * JavaData
Definition: mtsCMUSphinx4.h:112
friend void mtsCMUSphinx4JavaWordRecognizedCallback(mtsCMUSphinx4 *sphinx4Wrapper, const std::string &word)
Definition: mtsFunctionWrite.h:37
Definition: mtsTaskContinuous.h:77
std::string ConfigName
Definition: mtsCMUSphinx4.h:102
Definition: mtsCMUSphinx4.h:47
const int CMN_NO_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:328
Context * AddContext(const std::string &contextName)
void WordRecognizedCallback(const std::string &word)
std::string ModelTopDir
Definition: mtsCMUSphinx4.h:99
ContextMap Contexts
Definition: mtsCMUSphinx4.h:96
unsigned int GetMicrophoneNumber(void) const
#define CMN_LOG_ALLOW_DEFAULT
Definition: cmnLogLoD.h:76
void SetMicrophoneNumber(unsigned int microphoneNumber)
void GetContexts(stdStringVec &placeHolder) const