-1

I am trying to run festival.exe through java. I tried running the following code but apparently it is not working. Where is it going wrong?

    String [] cmdArray= {"C://Festival//festival.exe","(SayText \"Hello\")"};
    Runtime rt = Runtime.getRuntime();
    rt.exec(cmdArray);

I have even tried:

    Process process = new ProcessBuilder("C:\\festival\\festival.exe","(SayText \"Hello\")").start();
    InputStream is = process.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line;

    System.out.printf("Output of running %s is:", Arrays.toString(args));

    while ((line = br.readLine()) != null) {
      System.out.println(line);
    }

This is also giving blank output and not working.

Savreen
  • 49
  • 11
  • 1
    Possible duplicate of [Execute external program in java](https://stackoverflow.com/questions/13991007/execute-external-program-in-java) – Ashu Mar 14 '19 at 12:14
  • 1
    Use a [`ProcessBuilder`](https://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html) – deHaar Mar 14 '19 at 12:14
  • use https://docs.oracle.com/javase/1.5.0/docs/api/java/lang/ProcessBuilder.html – Vishwa Ratna Mar 14 '19 at 12:19
  • I tried processbuilder but it is also not executing and giving blank output!! – Savreen Mar 14 '19 at 12:24
  • As said ProcessBuilder. It might be the argument containing both space and double quotes (`"(SayText", "\"Hello\")"`. Maybe that could be given on the command line (PrintStream), or such. – Joop Eggen Mar 14 '19 at 12:31
  • @JoopEggen it does not work!! – Savreen Mar 14 '19 at 12:38

1 Answers1

1

Instead of calling command line process, it's best to use on of APIs provided by Festival.

Sample Java client can be found here: https://github.com/festvox/festival/blob/master/src/modules/java/cstr/festival/Client.java

greenmarker
  • 1,599
  • 1
  • 21
  • 29
  • I already saw this! But could not get on how to use it. Could you provide some sample code on how to use it? – Savreen Mar 14 '19 at 12:28
  • Before running Client.java, please start festival.exe --server. If you run both server and client on the same machine, no further configuration is needed. More info about switches: http://www.festvox.org/docs/manual-2.4.0/festival_7.html. – greenmarker Mar 16 '19 at 14:59