Exemplo n.º 1
0
  public static void main(String args[]) {
    InterServer intertest;

    Properties kv = new Properties();
    kv.setProperty("data_file", "db.txt");
    kv.setProperty("common_words", "common.txt");
    kv.setProperty("specs_file", "db.spec");
    kv.setProperty("questions_file", "db.quest");
    kv.setProperty("recognizer", "sphinx");
    kv.setProperty("interpreter", "inter");
    kv.setProperty("synthesizer", "festival");

    Log log = new Log();
    log.setLevelByName("info");

    try {
      File currentDir = new File(".");
      String path = currentDir.getCanonicalPath();
      String dir = path + "/";
      // Command cmd = new Command ();
      SqliteCommand cmd = new SqliteCommand();
      intertest = new InterServer("inter", port, dir, kv, cmd);
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      while (true) {
        String line = in.readLine();
        if (line.startsWith("connect1")) line = connect1;
        else if (line.startsWith("connect2")) line = connect2;
        else if (line.endsWith("who1")) line = line.replaceAll("who1", who1);
        else if (line.endsWith("who2")) line = line.replaceAll("who2", who2);
        intertest.execute(line);
        sleep(waitTime);
        log.info("Executed: " + line);
        if (line.equals("terminate")) {
          Log.info("Ending test program");
          System.exit(1);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  public static void main(String args[]) {
    SphinxServer Recognizer;
    Log log = new Log();
    log.setLevelByName("PATlog_level");
    try {
      Recognizer = new SphinxServer("PATrecognizer", PATport_recognizer);
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

      Log.info("Waiting to connect to PATinterpreter");
      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 PATinterpreter");
        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 PATinterpreter");
        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();
    }
  }