1

I am trying to run SoX command from java code but having some difficulties. SoX (SOund eXchange) software is installed, but rather than run the program from command prompt, I want to run the program and get results through my java code. The command I want to run is:

Sox -m sounda.wav soundb.wav final.wav

Here is a sample code that I am using to test:

package soxcmd;
import java.io.IOException;

public class SoxCmd {
public static void main(String[] args) throws IOException {
    String path = "c:\\sox";
    String[] mystring = {path + "\\sox -m", path + "\\fdir\\sounda.wav", path + "\\fdir\\soundb.wav", path + "\\bdfiles\\final.wav"};
    Runtime.getRuntime().exec(mystring); 
}

}

I'll appreciate your help on this. Thanks.

bdfios
  • 657
  • 6
  • 17
  • 29

2 Answers2

1

I found solution to this problem, with inspiration from http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/

I called sox absolutely using "c:\sox\sox.exe" I also used absolute path as it seems relative path didn't work, and I sent the entire string as I would at the command line. Therefore I have

Process pr;  
pr = rt.exec("c:\\sox\\sox.exe c:\\sox\\files\\filea.wav c:\\sox\\files\\fileb.wav c:\\sox\\files\\filec.wav");
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));

It's working now. Thanks.

bdfios
  • 657
  • 6
  • 17
  • 29
0

I have written a small wrapper application around sox. It is freely available on Github. See, maybe it will satisfy your needs. The project is still in an early state, but maybe you will find it useful.

Java wrapper around soundeXchange available on GitHub

SaWo
  • 1,515
  • 2
  • 14
  • 32