public static void main(String args[]) { WebAsrServer Recognizer; Log log = new Log(); log.setLevelByName("PATlog_level"); try { Recognizer = new WebAsrServer("PATnamerecognizer", PATport_recognizer); Log.info("Waiting to connect to PATnameinterpreter"); boolean connected = false; int waiting = 0; while (!connected && waiting < 1000) { sleep(waitTime); String result = Recognizer.executeReply(connect1); if (result.startsWith("OK:")) { connected = true; break; } else { waiting++; System.out.println("Waiting ... " + waiting); continue; } } if (!connected) { Log.severe("Waiting for too long, terminating ..."); return; } else { Log.info("Connected to PATnameinterpreter"); Log.info("Waiting to establish who credentials"); } sleep(waitTime * 4); boolean established = false; waiting = 0; while (!established && waiting < 100) { sleep(waitTime); String result = Recognizer.executeReply(who1); if (result.startsWith("OK:")) { established = true; break; } else { waiting++; Log.info("Establishing credentials ... " + waiting); continue; } } if (!established) { Log.severe("Establishing did not work, terminating ..."); return; } else { Log.info("Established credentials with PATnameinterpreter"); Log.info("Processing recognition results"); } sleep(waitTime * 4); // loop in SpeechInput processSpeech(Recognizer); System.out.println("Terminating ..."); System.exit(1); } catch (Exception e) { e.printStackTrace(); } }
static void processSpeech(WebAsrServer server) { try { // you can read in a file containing the actual // text of each recording in recorded [] and print // out the original recordings along with what is // recognized. if (recorded.length == 0) { System.out.println("Please edit PATbatchMultiWeb.java to include information"); System.out.println("on recordings to be used by the recognizer."); return; } SpeechInput recognizer = new SpeechInput("PATgoogleapikey"); for (int i = 0; i < recorded.length; i++) { StringBuffer sb = new StringBuffer(); sb.append(audiodir); sb.append(recorded[i]); if (!recorded[i].endsWith(".flac")) sb.append(".flac"); String filename = new String(sb); System.out.println(filename); String result = recognizer.recognize(filename, lang); System.out.println("Recognized: " + result); if (result != null) { String message = work1 + "\"" + result + "\"}"; server.execute(message); } } } catch (Exception e) { e.printStackTrace(); } }