日期:2014-05-19 浏览次数:20801 次
public class Test { static float sampleRate = 6000.0F; // 每秒的样本数 static int sampleSizeInBits = 4; // 每个样本中的位数 static int channels = 1; // 声道数(单声道 1 个,立体声 2 个) static boolean signed = true; // 指示数据是有符号的,还是无符号的 static boolean bigEndian = false; // 指示是否以 big-endian 字节顺序存储单个样本中的数据(false 意味着 little-endian) public static void trans() throws Exception{ File outFile = new File("F:/123.wav"); RandomAccessFile file = new RandomAccessFile("F:/1234123.v3", "r"); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte tempBuffer[] = new byte[10000]; while (true) { //读取10000个数据 int cnt = file.read(tempBuffer, 0, tempBuffer.length); if (cnt > 0) { //保存该数据 byteArrayOutputStream.write(tempBuffer, 0, cnt); }else { byteArrayOutputStream.close(); break; } } AudioFormat audioFormat = new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian); byte audioData[] = byteArrayOutputStream.toByteArray(); InputStream byteArrayInputStream = new ByteArrayInputStream(audioData); AudioInputStream audioInputStream = new AudioInputStream(byteArrayInputStream, audioFormat, audioData.length / audioFormat.getFrameSize()); AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, outFile); System.out.println("success"); } /** * @param args */ public static void main(String[] args) throws Exception{ Test.trans(); } }