以下是关于Android AudioRecord用于记录呼叫的设置的答案:
以下是一个简单的示例代码,用于使用Android AudioRecord录制呼叫:
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
public class AudioRecordHelper {
private static final int SAMPLE_RATE = 44100;
private static final int CHANNEL_CONFIG = AudioFormat.CHANNEL_IN_DEFAULT;
private static final int AUDIO_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
private static final int BUFFER_SIZE = AudioRecord.getMinBufferSize(SAMPLE_RATE, CHANNEL_CONFIG, AUDIO_FORMAT);
private AudioRecord audioRecord;
public void startRecording() {
audioRecord = new AudioRecord.Builder()
.setAudioSource(MediaRecorder.AudioSource.DEFAULT)
.setAudioFormat(new AudioFormat.Builder()
.setEncoding(AUDIO_FORMAT)
.setSampleRate(SAMPLE_RATE)
.setChannelMask(CHANNEL_CONFIG)
.build())
.setBufferSizeInBytes(BUFFER_SIZE)
.build();
audioRecord.startRecording();
}
public void stopRecording() {
if (audioRecord != null) {
audioRecord.stop();
audioRecord.release();
audioRecord = null;
}
}
public byte[] readData() {
byte[] data = new byte[BUFFER_SIZE];
int read = audioRecord.read(data, 0, BUFFER_SIZE);
return data;
}
}
在使用此代码时,需要注意以下几点:
领取专属 10元无门槛券
手把手带您无忧上云