我希望录制现场音频,并在指定的一段时间后回放到发言人。
示例..如果我调用该函数,它将记录音频并以2000毫秒的延迟将其传输到扬声器。如果我说“你好”,我会在2秒后听到你好。
请帮助我,我坚持了几天,并在互联网上找不到解决方案。在此先感谢。
这是我的功能
`public void echoSound(){
new Thread(new Runnable() {
@Override
public void run() {
isRecording = true;
buffersize = AudioRecord.getMinBufferSize(11025, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT);
arec = new AudioRecord(MediaRecorder.AudioSource.MIC, 11025, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, buffersize);
buffer = new byte[buffersize];
arec.startRecording();
atrack = new AudioTrack(AudioManager.STREAM_MUSIC, 11025, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, buffersize, AudioTrack.MODE_STREAM);
atrack.setPlaybackRate(11025);
atrack.play();
atrack.setPositionNotificationPeriod(msValue);
while(isRecording) {
arec.read(buffer, 0, buffersize);
atrack.write(buffer,0,buffer.length);
}
}
}).start();
}
`