//import lejos.nxt.LCD; import lejos.pc.comm.*; import edu.cmu.sphinx.recognizer.Recognizer; import edu.cmu.sphinx.result.Result; import edu.cmu.sphinx.util.props.ConfigurationManager; import edu.cmu.sphinx.frontend.util.Microphone; import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import javax.sound.sampled.*; import sun.audio.*; public class BTsend { /** * @param args * @throws NXTCommException * @throws InterruptedException * @throws Exception */ public static void main(String[] args) throws NXTCommException, InterruptedException, Exception { ConfigurationManager cm; cm = new ConfigurationManager(BTsend.class.getResource("roila.config.xml"));//Name of your Sphinx XML Config File NXTInfo[] nxtInfo = new NXTInfo[1]; //HARD CODE INFO ABOUT YOUR NXT nxtInfo[0]=new NXTInfo(); int device_flag = 2; if(device_flag==1) { nxtInfo[0].deviceAddress="00:16:53:06:18:CC"; nxtInfo[0].name="NXT"; } else { //001653048CCB nxtInfo[0].deviceAddress="00:16:53:04:8C:CB"; nxtInfo[0].name="Carl"; } //nxtInfo[0] = new NXTInfo(0, "NXT","00:16:53:06:18:CC"); System.out.println("Adr: " + nxtInfo[0].deviceAddress); System.out.println("Connecting to " + nxtInfo[0].name); NXTConnector conn = new NXTConnector(); boolean opened = false; opened = conn.connectTo(nxtInfo[0].name, nxtInfo[0].deviceAddress, NXTCommFactory.BLUETOOTH); if (!opened) { System.out.println("Failed to open " + nxtInfo[0].name); System.exit(1); } System.out.println("Connected to " + nxtInfo[0].name); DataOutputStream dos = conn.getDataOut(); DataInputStream dis = conn.getDataIn(); System.out.println("Loading Recognizer..."); Recognizer recognizer = (Recognizer) cm.lookup("recognizer"); recognizer.allocate(); // start the microphone or exit if the programm if this is not possible Microphone microphone = (Microphone) cm.lookup("microphone"); if (!microphone.startRecording()) { System.out.println("Cannot start microphone."); recognizer.deallocate(); System.exit(1); } try { int end = 0; while (true) { System.out.println("Start speaking.\n"); Result result = recognizer.recognize(); if (result != null) { String resultText = result.getBestResultNoFiller(); System.out.println("You said: " + resultText + "\n"); if(!resultText.equals("")) { dos.writeBytes(resultText); dos.flush(); System.out.println("Data Sent"); int n = dis.readInt(); System.out.println("Ready For Next Command"); } else { System.out.println("I can't hear what you said.\n"); } } else { System.out.println("I can't hear what you said.\n"); dos.writeBytes("Goodbye"); dos.flush(); break; } } } catch (IOException ioe) { System.out.println("IOException closing connection:"); System.out.println(ioe.getMessage()); } dos.close(); conn.close(); } }