2016-11-25 1 views
0

.wav 오디오 파일에서 웨이브 폼의 그래프를 플롯하려고합니다. 이 사이트에서 .WAV의 바이트를 추출하는 기능 찾을 :오디오 웨이브 폼 그래프 플롯 Java

ByteArrayOutputStream out = new ByteArrayOutputStream(); 
BufferedInputStream in = null; 
try { 
    in = new BufferedInputStream(new FileInputStream(args[0])); 
} catch (FileNotFoundException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

int read; 
byte[] buff = new byte[1024]; 
while ((read = in.read(buff)) > 0) 
{ 
    out.write(buff, 0, read); 
} 
out.flush(); 

byte[] audioBytes = out.toByteArray(); 
for (int i=0; i<audioBytes.length; i++) { 
    System.out.println(audioBytes[i]); 
} 

그럼 내가 콘솔에서 볼 수있는 포인트를 사용을 (System.out에이 ...) "Microsoft Excel에서"내 오디오 파형을 플롯합니다 그리고 risult은 다음과 같습니다

waveform on Excel 하지만 내 .wav 파일의 파형은 파형 다른 많은입니다 플롯 (예) 오픈 소스 "프라 트"

waveform on Praat 어디에서 잘못? 내가 가져야하는 파일의 바이트가 아닌가요?

답변

2

"결과는"당신이 발견하는 위치가

public double[] extract(File inputFile) { 
     AudioInputStream in = null; 
     try { 
      in = AudioSystem.getAudioInputStream(inputFile); 
     } catch (Exception e) { 
      System.out.println("Cannot read audio file"); 
      return new double[0]; 
     } 
     AudioFormat format = in.getFormat(); 
     byte[] audioBytes = readBytes(in); 

     int[] result = null; 
     if (format.getSampleSizeInBits() == 16) { 
      int samplesLength = audioBytes.length/2; 
      result = new int[samplesLength]; 
      if (format.isBigEndian()) { 
       for (int i = 0; i < samplesLength; ++i) { 
        byte MSB = audioBytes[i * 2]; 
        byte LSB = audioBytes[i * 2 + 1]; 
        result[i] = MSB << 8 | (255 & LSB); 
       } 
      } else { 
       for (int i = 0; i < samplesLength; i += 2) { 
        byte LSB = audioBytes[i * 2]; 
        byte MSB = audioBytes[i * 2 + 1]; 
        result[i/2] = MSB << 8 | (255 & LSB); 
       } 
      } 
     } else { 
      int samplesLength = audioBytes.length; 
      result = new int[samplesLength]; 
      if (format.getEncoding().toString().startsWith("PCM_SIGN")) { 
       for (int i = 0; i < samplesLength; ++i) { 
        result[i] = audioBytes[i]; 
       } 
      } else { 
       for (int i = 0; i < samplesLength; ++i) { 
        result[i] = audioBytes[i] - 128; 
       } 
      } 
     } 

     return result; 
    } 
0

파일의 각 바이트가 다음 시점에서 웨이브의 진폭을 나타내는 것으로 가정하는 것 같습니다. 이것은 (일반적으로 말하면) 대소 문자가 아닙니다. 파일이 헤더로 시작한다는 사실 외에도 각 샘플은 여러 채널로 구성되며 각 채널 내에서 샘플은 단지 1 바이트보다 적은 공간 (예 : 4 비트 이상 (예 : 16 비트) 공간)을 차지할 수 있습니다. 예를 들어이 설명 :. 배열에서 http://www.topherlee.com/software/pcm-tut-wavformat.html

+0

아 맞다 그래서, 당신을 위해 어떤 점을 나는 같이 그 차트를 가지고해야합니다.! Praat의 이미지? –