Tweaking the delay a bit... 0,050 s for output seems too little; it results in choppy audio and ultimately, a heap of errors. 0,100 seems ok for the output buffer. But the input buffer needs to be much larger else it overflows. Also, an extra stop stream before terminating to make sure all audio from the audio buffer is played.