import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.UnsupportedAudioFileException; // We're aiming for: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 16000 Hz // as per http://cmusphinx.sourceforge.net/wiki/tutorialsphinx4 static void convertWAVForSphinx(File inputFile, File outputFile) ctex { AudioFormat outputFormat = sphinxAudioFormat(); AudioFileFormat inputFileFormat = AudioSystem.getAudioFileFormat(inputFile); AudioFormat inputFormat = inputFileFormat.getFormat(); AudioInputStream sourceStream = AudioSystem.getAudioInputStream(inputFile); AudioInputStream stream = AudioSystem.getAudioInputStream(outputFormat, sourceStream); int nWrittenBytes = AudioSystem.write(stream, AudioFileFormat.Type.WAVE, outputFile); sourceStream.close(); stream.close(); }