java音频转wav、获取wav时长

网址http://www.sauronsoftware.it/projects/jave/download.php下载jar包


转wav代码
File source = new File(tempPath);
File target = new File(targetPath);
AudioAttributes audio = new AudioAttributes();
audio.setCodec("pcm_alaw");
audio.setBitRate(new Integer(64000));
audio.setChannels(new Integer(1));
audio.setSamplingRate(new Integer(8000));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("wav");
attrs.setAudioAttributes(audio);
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);


获得wav时长代码

        File source = new File("C:\\22.wav");
        Encoder encoder = new Encoder();
        try {
             MultimediaInfo m = encoder.getInfo(source);
             long ls = m.getDuration();
             System.out.println(ls+" "+ls/1000);
        } catch (Exception e) {
            e.printStackTrace();
        }

 

你可能感兴趣的:(java音频转wav,获取wav时长)