2005-01-28 16:19:00 PST
At first, I believed that to run mbrola with freetts under windows, getMbrolaBinary() in MbrolaVoice.java must be revised to include ".exe" in the binany name. And I did so in my project. However, I found the above solution occasionally yesterday. With the code attached here, I find something very interesting.
Firstly, rename an executable program (e.g. mbrola.exe) to remove its extension, i.e. "mbrola" in this case. Then "mbrola" under DOS prompt returns an error. And "java run mbrola" will return the following exception:
java.io.IOException: CreateProcess: mbrola error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Unknown Source)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at run.main(run.java:9)
However, if an absolute or relative path (even ".\") is included, "java run [path]mbrola" will be executed correctly.
After reading the document of msdn, I find that it is a feature of the windows api, CreateProcess(). Visit
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocess.asp for details. And according to the document, "java run [path]mbrola" is also ok. It is true.
import java.io.*;
public class run {
public static void main(String[] args) {
if (args.length == 0)
System.out.println("Usage: java run application parameters");
else {
try {
Process process = Runtime.getRuntime().exec(args);
byte[] buf = new byte[1024];
BufferedInputStream fromProcess
= new BufferedInputStream(process.getInputStream());
int nread = 0;
while ((nread = fromProcess.read(buf)) != -1) {
System.out.write(buf, 0, nread);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}