20 import edu.cmu.sphinx.api.Configuration;
21 import edu.cmu.sphinx.api.Context;
22 import edu.cmu.sphinx.api.SpeechResult;
23 import edu.cmu.sphinx.api.StreamSpeechRecognizer;
24 import edu.cmu.sphinx.linguist.flat.FlatLinguist;
25 import edu.cmu.sphinx.recognizer.Recognizer;
26 import edu.cmu.sphinx.util.props.ConfigurationManager;
27 import java.io.BufferedReader;
28 import java.io.BufferedWriter;
29 import java.io.OutputStreamWriter;
31 import java.io.FileInputStream;
32 import java.io.IOException;
33 import java.io.InputStreamReader;
34 import java.io.PrintWriter;
36 import java.net.URLClassLoader;
37 import java.net.Socket;
38 import java.util.HashMap;
69 public static ConfigurationManager
cm;
80 boolean new_info =
false;
117 if(new_info ==
true){
121 catch (IOException e) {
123 bufferWrite.println(
"CatchedException " + e);
134 public static void main(String[] args)
throws IOException {
139 if (args.length == 1)
141 socketPort = Integer.parseInt(args[0]);
142 System.err.println(
"Socket port: " + socketPort);
143 sphinxSocket =
new Socket(
"127.0.0.1", socketPort );
145 bufferRead =
new BufferedReader(
new InputStreamReader(sphinxSocket.getInputStream()));
146 bufferWrite =
new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(sphinxSocket.getOutputStream())),
true);
150 System.err.println(
"CatchedException");
160 configuration.setUseGrammar(
false);
161 String s = bufferRead.readLine();
164 if(tmp[0].contains(
"dictionary")){
165 test_file =
new File(tmp[1]);
166 if(!test_file.exists())
168 bufferWrite.println(
"Fatal error, dictionary file does not exist");
173 bufferWrite.println(
"Dictionary set");
177 else if(tmp[0].contains(
"languageModel")){
178 test_file =
new File(tmp[1]);
179 if(!test_file.exists())
181 bufferWrite.println(
"Fatal error, language file does not exist");
186 bufferWrite.println(
"Language model set");
190 else if(tmp[0].contains(
"acousticModel")){
191 configuration.setAcousticModelPath(tmp[1]);
192 bufferWrite.println(
"Acoustic model set");
195 else if(tmp[0].contains(
"grammarName")){
198 bufferWrite.println(
"Grammar model set");
201 else if(tmp[0].contains(
"configurationPath")){
202 test_file =
new File(tmp[1]);
203 if(!test_file.exists())
205 bufferWrite.println(
"Fatal error, configuration file does not exist");
210 bufferWrite.println(
"Configuration path set");
214 else if(tmp[0].contains(
"forceConfiguration")){
216 bufferWrite.println(
"Configuration performed");
220 else if(tmp[0].contains(
"enableGrammar")){
222 bufferWrite.println(
"Grammar enabled");
225 else if(tmp[0].contains(
"disableGrammar")){
227 bufferWrite.println(
"Grammar disabled");
230 else if (tmp[0].contains(
"audioInput")) {
232 test_file =
new File(tmp[1]);
234 if(!test_file.exists())
236 bufferWrite.println(
"Fatal error, audio file does not exist");
237 temp = bufferRead.readLine();
241 recognizer.startRecognition(
new FileInputStream(tmp[1]));
243 while ((result =
recognizer.getResult()) != null) {
244 bufferWrite.println(
"#" + result.getHypothesis());
245 temp = bufferRead.readLine();
247 recognizer.stopRecognition();
248 bufferWrite.println(
"stopPython");
249 temp = bufferRead.readLine();
253 catch (IOException | RuntimeException e) {
257 bufferWrite.println(
"CatchedException " + e);
static boolean grammar_enabled
static boolean grammar_enabled_prev
static String configuration_model_path
static String acoustic_model_path_prev
static String grammar_model_folder_path
static StreamSpeechRecognizer recognizer
static PrintWriter bufferWrite
static String grammar_model_file_path_prev
static String grammar_model_file_path
static String language_path_prev
Performs speech recognition employing Sphinx.
static String language_path
static String dictionary_path
static ConfigurationManager cm
static void main(String[] args)
The main function.
static String configuration_model_path_prev
static String acoustic_model_path
static void updateConfiguration()
Updates the Sphinx configuration.
static String grammar_model_folder_path_prev
static Configuration configuration
static BufferedReader bufferRead
static String dictionary_path_prev