public void processSpeech(ArrayList<String> speech) {

    nlu.getCommand(speech);

    selectedLine = nlu.getSelectedLine();

    if (selectedLine != null) {

      System.out.println(selectedLine);
      // sleepTimer.cancel();

      if (state == IDLE) {
        currentCmd = nlu.getCmd();

        if (currentCmd != null) {

          System.out.println("Command <" + currentCmd + "> heard");

          // a command was detected and the current state is
          state = BUSY;

        } else {
          // the system does not understand what was said
          // <<Buzz

        }
      }

      // These commands can be called any time
      if (Constants.CMD_CANCEL.equalsIgnoreCase(nlu.getCmd())) {
        cancelCmd();
      } else if (Constants.CMD_REPEAT.equalsIgnoreCase(nlu.getCmd())) {
        runCmd("repeat");
      }

      if (state == CONFIRM) {
        // check if it is an allowed answer Y or N
        answer = selectedLine;
      } else if (state == OPTION) {
        // check if best result is a digit
        if (digitPattern.matcher(selectedLine).matches()) {
          option = Integer.valueOf(selectedLine);
        } else {
          // not number from 1 to 4
          toSay = "Please say a number between 1 and 4";
        }
      }

    } else {
      // nothing was selected from the speech engine results
      toSay = "I didn't understand what you say";
    }

    nextStates();

    lastUtterance = toSay;
  }
  private void runCmd(String currentCmd) {
    // TODO Auto-generated method stub
    if (Constants.CMD_CALL.equalsIgnoreCase(currentCmd)) {
      toSay = "calling " + contact;

    } else if (Constants.CMD_SMS.equalsIgnoreCase(currentCmd)) {
      toSay = "sending " + message + " to " + contact;

    } else if (Constants.CMD_REPEAT.equalsIgnoreCase(currentCmd)) {
      toSay = lastUtterance;

    } else if (Constants.CMD_TIME.equalsIgnoreCase(currentCmd)) {
      // toSay = "telling the the time";
      toSay = mUtil.getTime();
    } else if ("close".equalsIgnoreCase(currentCmd)) {
      toSay = "closing the application";

    } else if (Constants.CMD_NAME.equalsIgnoreCase(currentCmd)) {
      toSay = "my name is mimic";

    } else if (Constants.CMD_DATE.equalsIgnoreCase(currentCmd)) {

      // toSay = "telling the date ";
      toSay = mUtil.getDate();
    } else if (Constants.CMD_WEATHER.equalsIgnoreCase(currentCmd)) {

      toSay = "telling the weather ";

    } else if (Constants.CMD_LOCATION.equalsIgnoreCase(currentCmd)) {

      toSay = "telling the location ";

    } else if (Constants.CMD_MAP.equalsIgnoreCase(currentCmd)) {

      toSay = "showing the map ";

    } else if (Constants.CMD_WAKEUP.equalsIgnoreCase(currentCmd)) {

      toSay = "what can I do for you? ";
    }
    initialise();
  }