1

I'm trying to use the Java Runtime.getRuntime().exec(String) command to run Festival, then use OutputStreamWriter to write some commands to the outpustream of the process.

This works great, and I'm able to do something like this:

Process p = Runtime.getRuntime().exec("festival");
Writer w = new OutputStreamWriter(p.getOutputStream());
w.append("(SayText \"Hello World\")");
w.flush();

Obviously the way I can tell this works is that it speaks the text through the speakers.

What I am having a real hard time doing is getting the text output from what I would see in the terminal. I'm trying to run some other commands (such as (voice.list)) which output text, presumably to stdout.

For example, I've tried using a BufferedReader in the following way:

BufferedReader reader = new BufferedReader (new InputStreamReader(p.getInputStream()));
w.append("(voice.list)");
w.flush();

String output = "";
String line = reader.readLine();
System.out.println(line);

while ((line = reader.readLine()) != null)
{
  System.out.println("Reading: " + line);
  output += line;
}

(The System.out.println's is just for debugging, I would do the entire thing in a cleaner way if I was able to get it to work.)

No matter what code I try, I'm never able to get any output from Festival. I can get output from other commands. E.G. I have tried this code as well http://en.allexperts.com/q/Java-1046/2008/2/Runtime-getRuntime-exec-cmd.htm and it works with many other commands (like ls) but not Festival.

Does anything have any idea how I would be able to get this to work?

Thanks.

joshhendo
  • 1,964
  • 1
  • 21
  • 28

1 Answers1

0

Festival may output it's text on stderr instead of stdout. Try replacing

p.getInputStream()

with

p.getErrorStream()
Peter Elliott
  • 3,273
  • 16
  • 30