wav音频文件

来源:互联网 发布:java shell 交互 编辑:程序博客网 时间:2024/05/06 09:42

package test;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;

public class Audio {

public static void main(String[] args) {
     File file = new File("f:/tt.wav");
     AudioFormat audioFormat = null;
     try {
          audioFormat = AudioSystem.getAudioFileFormat(file).getFormat();
     } catch (FileNotFoundException e) {
          e.printStackTrace();
     } catch (UnsupportedAudioFileException e) {
          e.printStackTrace();
     } catch (IOException e) {
          e.printStackTrace();
     }
 
     System.out.println("文件长度为:"+file.length()/1024+"Kb");
     System.out.println("音频编码方式为:"+audioFormat.getEncoding().toString());
     System.out.println("音频通道数为:"+audioFormat.getChannels());
     System.out.println("音频采样频率为:"+audioFormat.getSampleRate());
     System.out.println("音频采样位数为:"+audioFormat.getSampleSizeInBits()+"位");
  }
}

 

 

 

 

 

 

 

 

 

 

 

import javax.sound.sampled.*;
import java.io.*;
/**
* @author Hardneedl
*/
class WavReader {

    public static void main(String[] args) throws IOException, UnsupportedAudioFileException {
        FileInputStream fin = new FileInputStream(args[0]);
        AudioInputStream ain = AudioSystem.getAudioInputStream(fin);
        AudioFormat format=ain.getFormat();
    }

}

原创粉丝点击