Audio Capture在Raspberry Pi中抛出异常

时间:2016-02-27 18:42:40

标签: java raspberry-pi raspbian

我使用以下JAVA方法捕获音频,然后使用套接字传输到另一端。

private AudioFormat getAudioFormat() {
     float sampleRate = 8000.0F;
     int sampleSizeInBits = 8;
     int channels = 1;
     boolean signed = true;
     boolean bigEndian = false;
     return new AudioFormat(sampleRate, sampleSizeInBits, channels,
           signed, bigEndian);
  }

  private void captureAudio() throws Exception {
     try {
        System.out.println("Capturing audio........");
        AudioFormat audioFormat = getAudioFormat();
        DataLine.Info dataLineInfo = new DataLine.Info(
              TargetDataLine.class, audioFormat);
        Mixer mixer = null;
        System.out.println("Available mixers:");
        for (int cnt = 0; cnt < mixerInfo.length; cnt++) {
           mixer = AudioSystem.getMixer(mixerInfo[3]);
           if (mixer.isLineSupported(dataLineInfo)) {
              System.out.println(mixerInfo[cnt].getName());
              targetDataLine = (TargetDataLine) mixer
                    .getLine(dataLineInfo);
           }
        }
        targetDataLine.open(audioFormat);
        targetDataLine.start();

        while (true) {
           int cnt = targetDataLine.read(tempBuffer, 0,
                 tempBuffer.length);
           System.out.println("Read buffer......."+cnt);
           out.write(tempBuffer);
           out.flush();
        }


     }
     catch (Exception e) {
        System.out.println(e);
        throw e;
     }
  }

但是当我在Raspberry Pi 2模型B上运行完整代码时,它会在引用调用captureAudio()和targetDataLine.open(audioFormat)的行时抛出java.lang.NullPointerException。

是因为我的捕获设备没有正确安装在Raspberry Pi上,还是与bigEndian问题有关?

0 个答案:

没有答案