28 from global_parameters
import GlobalParams
30 from rapp_exceptions
import RappError
31 from rapp_utilities
import RappUtilities
44 if not os.path.exists( self._globalParams._tmp_language_models_url ):
45 rospy.logwarn(
"Language temporary directory does not exist. Path: " + \
46 self._globalParams._tmp_language_models_url )
47 os.makedirs(self._globalParams._tmp_language_models_url)
51 dir = self._globalParams._tmp_language_models_url )
59 'jar_path' :
".:" + self._globalParams._sphinx_jar_files_url + \
60 "/" + self._globalParams._sphinx_jar_file +
":" \
61 + self._globalParams._sphinx_package_url +
"/src", \
62 'configuration_path' : self._globalParams._language_models_url + \
63 "/greekPack/default.config.xml", \
64 'acoustic_model' : self._globalParams._acoustic_models_url, \
65 'grammar_name' :
'', \
66 'grammar_folder' :
'', \
68 'language_model' :
'', \
69 'grammar_disabled' :
True
91 RappUtilities.rapp_print(
"Creating configuration files with parameters:" )
92 RappUtilities.rapp_print(
"Words: " + str(words) )
93 RappUtilities.rapp_print(
"Sentences: " + str(sentences) )
94 RappUtilities.rapp_print(
"Grammar: " + str(grammar) )
98 custom_dict = open(tmp_configuration[
'dictionary'],
'w')
101 for phoneme
in words[word]:
102 tmp_line +=
" " + phoneme.replace(
'-',
'').replace(
'_',
'')
103 custom_dict.write(tmp_line +
'\n')
107 if len(grammar) == 0:
108 tmp_configuration[
'grammar_disabled'] =
True
110 tmp_configuration[
'grammar_disabled'] =
False
111 tmp_configuration[
'grammar_name'] =
'custom'
113 custom_grammar = open(os.path.join( tmp_configuration[
'grammar_folder'], \
114 tmp_configuration[
'grammar_name']) +
'.gram',
'w')
115 custom_grammar.write(
'#JSGF V1.0;\n')
116 custom_grammar.write(
"grammar " + tmp_configuration[
'grammar_name'] +
';\n')
119 for i
in range(0, len(grammar)):
122 gram_words = gram.split(
" ")
123 for gw
in gram_words:
124 if gw
not in words
and gram
not in words:
125 raise RappError(
'Word ' + gw +
126 ' is not in words but exists in grammar')
128 custom_grammar.write(
"public <cmd" + str(counter) +
">=" +
"\"" + gram +
"\";\n")
135 custom_grammar.close()
143 if len(sentences) != 0:
144 for sent
in sentences:
146 sent_words = sent.split(
" ")
147 for sw
in sent_words:
148 if sw
not in words
and sent
not in words:
149 raise RappError(
'Word ' + sw +
150 ' is not in words but exists in a sentence')
152 custom_sentences.write(
"<s> " + sent +
" </s>\n")
155 custom_sentences.write(
"<s> " + word +
" </s>\n")
156 custom_sentences.close()
159 RappUtilities.rapp_print(
"Sphinx: Creating language model files\n" )
160 if self._globalParams._allow_sphinx_output ==
True:
161 bash_file = self._globalParams._language_models_url +
"/greekPack/run.sh"
165 bash_file = self._globalParams._language_models_url + \
166 "/greekPack/run_silent.sh"
170 os.system(bash_command)
172 return tmp_configuration
Creates temporary configuration files for the input limited vocabulary.
_languages_package
The temporary directory containing the configurations.
def createConfigurationFiles
Creates temporary configuration files for the input limited vocabulary.
def __init__
Performs initializations.
_globalParams
Contains global Sphinx parameters.
_sphinx_configuration
The default configuration.