The idea: I am trying to do an application like speech jammers. In theory when you listen yourself with a delay, you cant be able to speak properly.
So i am recording input from mic then playing it back to earphones. So far so good.
I want to add some delay to playback part. Looking for solutions.
val audioRecord = AudioRecord(
MediaRecorder.AudioSource.MIC,
intRecordSampleRate,
AudioFormat.CHANNEL_IN_STEREO,
AudioFormat.ENCODING_PCM_16BIT,
intBufferSize
)
audioTrack = AudioTrack(
AudioManager.STREAM_MUSIC,
intRecordSampleRate,
AudioFormat.CHANNEL_IN_STEREO,
AudioFormat.ENCODING_PCM_16BIT,
intBufferSize,
AudioTrack.MODE_STREAM,
)
audioTrack.playbackRate = intRecordSampleRate
audioRecord.startRecording()
audioTrack.play()
while (isActive){
audioRecord.read(shortAudioData, 0, shortAudioData.size)
shortAudioList.add(shortAudioData)
audioTrack.write(shortAudioData, 0, shortAudioData.size)
}
-I have tried to start playing with a delay. Plackback started with a delay but couldnt played back my voice which i speak before audioTrack.play()
-I tried to save shortAudioData to arraylist and write it one by one to audioTrack. couldnt be able to.
To be clear, i want to start recording, after about 500 ms delay, i want to start playing it back till user clicks stop button.