Android音频录制乱码

Android音频录制乱码,android,audio,Android,Audio,我们有一个长期运行的android应用程序,可以在按下按钮时录制音频。重新安装后,音频录制将按预期工作 我让应用程序运行了一夜,今天早上再次尝试录制。音频听起来像这样: 我在想,可能是该应用程序将声音处理器置于了一种奇怪的状态,因此我从Play store安装了一个录音应用程序,结果如下: 切换回我们的应用程序并录制相同的乱码音频。下面是我们实例化录制对象的地方: // the recording rate in samples per second (hz) public static fin

我们有一个长期运行的android应用程序,可以在按下按钮时录制音频。重新安装后,音频录制将按预期工作

我让应用程序运行了一夜,今天早上再次尝试录制。音频听起来像这样:

我在想,可能是该应用程序将声音处理器置于了一种奇怪的状态,因此我从Play store安装了一个录音应用程序,结果如下:

切换回我们的应用程序并录制相同的乱码音频。下面是我们实例化录制对象的地方:

// the recording rate in samples per second (hz)
public static final int RECORDING_RATE = 11025;

// we will be recording and playing back as mono with PCM 16 bit encoding.
private static final int RECORDING_CHANNEL = AudioFormat.CHANNEL_IN_MONO;
private static final int ENCODING_FORMAT = AudioFormat.ENCODING_PCM_16BIT;

// the buffer size is determined by the recording rate, channel and format
private static int RECORDING_BUFFER_SIZE = AudioRecord.getMinBufferSize(
        RECORDING_RATE, RECORDING_CHANNEL, ENCODING_FORMAT) * 2;

// the audio recorder instance used for microphone input
private static AudioRecord recorder =
        new AudioRecord(MediaRecorder.AudioSource.MIC,
                RECORDING_RATE, RECORDING_CHANNEL, ENCODING_FORMAT,
                RECORDING_BUFFER_SIZE);
在后面的代码中,我们有一个长时间运行的线程,该线程从记录器实例读取音频并将其写入BufferedOutputStream对象:

考虑到新安装的应用程序可以很好地录制多个音频文件,我不认为wav文件的编写是个问题

当我强制停止应用程序并再次启动时,录制将恢复正常:

那么你认为什么会导致wav文件像那样乱码呢

BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filename);

// as long as the user has not canceled the streaming...
while (transmitting) {

    // read the data into the buffer
    int read = recorder.read(buffer, 0, buffer.length);

    // write the buffer to the output stream
    bos.write(buffer);
}

// close the buffer and write the wav file