import processing.serial.*; Serial myPort; // The serial port static int LF = 10; static boolean doprint = false; import voce.*; void setup() { size(200,200); background(0); if(doprint) // start printer setupPrinter(); // setup speech voce.SpeechInterface.init("/Users/rtwomey/processing/libraries/voce/library", true, true, dataPath(""), "test"); System.out.println("[Robert] Ready to go:"); } void setupPrinter() { // serial init println(Serial.list()); // I know that the first port in the serial list on my mac // is always my Keyspan adapter, so I open Serial.list()[0]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[0], 4800); //init receipt printer myPort.write(ESC); myPort.write("@"); // fast feed myPort.write(ESC); myPort.write('d'); myPort.write(8); // line feed myPort.write(LF); // cut paper myPort.write(ESC); myPort.write('i'); delay(1000); } void draw() { stroke(255); while (voce.SpeechInterface.getRecognizerQueueSize() > 0) { // read string String s = voce.SpeechInterface.popRecognizedString(); // echo to screen println(millis()+": "+s); // send to printer if(doprint) { myPort.write(s); myPort.write(LF); } // check for stop command if((s.indexOf("quit") >= 0) || (s.indexOf("exit") >= 0) || (s.indexOf("stop") >= 0)) { if(doprint) { // fast feed myPort.write(ESC); myPort.write('d'); myPort.write(8); // feed this many lines // cut paper myPort.write(ESC); myPort.write('i'); } exit(); } // voce.SpeechInterface.synthesize(s); } }