Did you make sure to install PortAudio, PyAudio is dependent of PortAudio and will not work if it isn't properly installed.
Yeah I have it installed. As I described, I can do recording or playing alone, but not at the same time.
I solved the problem by changing CHUNK size to 512. Still the problem shows up once in a while, but at least it works most of the time.
Have you tried to set exception_on_overflow=False ? From the Pyaudio docs:
Read samples from the stream. Do not call when using non-blocking mode.
- num_frames – The number of frames to read.
- exception_on_overflow – Specifies whether an IOError exception should be thrown (or silently ignored) on input buffer overflow. Defaults to True.
if stream is not an input stream or if the read operation was unsuccessful.