26 from rapp_utilities
import RappUtilities
27 from rapp_exceptions
import RappError
29 from greek_support
import *
30 from english_support
import *
31 from greek_english_support
import *
32 from sphinx4_wrapper
import *
33 from sphinx4_configuration_params
import *
34 from global_parameters
import GlobalParams
36 from rapp_platform_ros_communications.srv
import (
37 SpeechRecognitionSphinx4Srv,
38 SpeechRecognitionSphinx4SrvResponse,
39 SpeechRecognitionSphinx4SrvRequest,
40 SpeechRecognitionSphinx4ConfigureSrv,
41 SpeechRecognitionSphinx4ConfigureSrvResponse,
42 SpeechRecognitionSphinx4ConfigureSrvRequest,
43 SpeechRecognitionSphinx4TotalSrv,
44 SpeechRecognitionSphinx4TotalSrvResponse
47 from rapp_platform_ros_communications.msg
import (
51 from std_msgs.msg
import (
91 if configurationName !=
None:
104 return self._configuration_params.getHash()
113 RappUtilities.rapp_print(
"Creating preconfiguration: " + configurationName )
116 req = SpeechRecognitionSphinx4ConfigureSrvRequest()
117 req.language = tempConf._language
118 req.words = tempConf._words
119 req.grammar = tempConf._grammar
120 req.sentences = tempConf._sentences
130 total_res = SpeechRecognitionSphinx4TotalSrvResponse()
132 RappUtilities.rapp_print(
'Configuring Sphinx')
133 conf_res = SpeechRecognitionSphinx4ConfigureSrvResponse()
135 total_res.error = conf_res.error
136 if conf_res.error !=
'':
137 total_res.error = total_res.error +
'\n' + conf_res.error
138 RappUtilities.rapp_print(total_res.error,
'ERROR')
141 RappUtilities.rapp_print(
'Performing recognition')
143 total_res.words = spee_res.words
144 total_res.error = spee_res.error
145 RappUtilities.rapp_print(total_res.words)
153 res = SpeechRecognitionSphinx4SrvResponse()
154 words = self._sphinx4.performSpeechRecognition(req.path, req.audio_source, req.user)
155 RappUtilities.rapp_print (words)
157 if len(words) == 1
and "Error:" in words[0]:
163 RappUtilities.rapp_print (
"Word: #" + word +
"#")
164 if word ==
"" or word ==
'<unk>':
176 if self._configuration_params._language ==
'en':
177 RappUtilities.rapp_print (
"Language set to English")
179 elif self._configuration_params._language ==
'el':
180 RappUtilities.rapp_print (
"Language set to Greek")
183 raise RappError(
"Wrong Language")
190 res = SpeechRecognitionSphinx4ConfigureSrvResponse()
195 if self._configuration_params.equalsRequest(req):
197 self._configuration_params.makeEqualToRequest(req)
199 if reconfigure ==
False:
200 RappUtilities.rapp_print(
'Skipping Configuration')
202 RappUtilities.rapp_print(
'Recognition Configuration')
206 except RappError
as e:
212 except RappError
as e:
217 RappUtilities.rapp_print(
"Configuration: \n")
218 RappUtilities.rapp_print(conf)
219 self._sphinx4.configureSphinx(conf)
231 if len(self._configuration_params._words) == 0:
232 RappUtilities.rapp_print (
"Generic model used")
235 conf = support.getGenericConfiguration()
236 except RappError
as e:
237 raise RappError( e.value )
240 RappUtilities.rapp_print (
"Limited model used")
243 [conf, mapping] = support.getLimitedVocebularyConfiguration(\
244 self._configuration_params._words, \
245 self._configuration_params._grammar, \
246 self._configuration_params._sentences)
247 except RappError
as e:
248 raise RappError( e.value )
259 if __name__ ==
"__main__":
260 rospy.init_node(
'SpeechRecognitionSphinx4')
_english_support
English creates necessary files for english speech recognition.
def _createSupportConfiguration
Get Sphinx configuration paths from Language Support.
def __init__
Constructor performing initializations.
def _selectLanguageSupport
Choose the language support based on the request language.
_sphinx4
The sphinx wrapper communicates with the actual Sphinx.java process.
def speechRecognitionBatch
Performs Sphinx4 configuration and speech recognition.
Contains the Sphinx subprocess and is responsible for configuring Sphinx and performing the recogniti...
Contains the parameters required for the Sphinx configuration.
def _configureSpeechRecognition
Performs Sphinx4 configuration.
_globalParams
Contains global Sphinx parameters.
def _speechRecognition
Performs Sphinx4 speech recognition.
_word_mapping
A dictionary to transform the englified greek words to actual greek words.
_greek_support
Greek_support creates necessary files for Greek speech recognition.
Provides a complete Rapp Sphinx Entity.
def getConfigurationHash
Requests the configuration's sha1 hash.
Allows the creation of configuration files for English Sphinx speech recognition. ...
def _createPreconfiguration
Create the requested preconfiguration.
_configuration_params
The Sphinx configuration parameters.