Unfortunately, this will not be possible ... at least not directly.
Some audio devices will use a different clock between recording and playback. This will be especially true for cell phones, where what works on a microphone can be great equipment than the audio output for headphones.
Basically, if you record at 44.1 kHz and play at 44.1 kHz, but this watch is not synchronized, you can record at 44.099 kHz and play at 44.01 kHz. Over time, this drift will mean that you will not have enough data in the buffer to send to the output.
Another complication (and most likely your problem) is that your recording and playback frequencies may vary. If you record with a microphone at 11 kHz and play at 48 kHz, you will notice that 11 does not even fit into 48. The software is often used to re-sample the recording. Sometimes this is done with a good algorithm, which is guaranteed to give you the desired result. In other cases, that 11 kHz will be brought up to 44 kHz and is considered "close enough."
In short, you cannot rely on synchronizing recording and playback devices, and you will need to synchronize yourself. There are many algorithms to handle this. The easiest way is to add a sample here and there, which averages the sample before and after it. If you do this with just a few samples, it will not be heard. Depending on the type of drift problem you have, this may be enough.
source share