# Record and playback has echo/feedback

I didn't mess around with the code here, it was straight from their website, I just want to see if it would work. However, whenever I run it, it has feedback in it, sometimes I can't hear anything at all. It is not the speaker because I can record and play things separately. Here is the code if you want.

I tried changing the frames per buffer to 5000 and it lost the feedback and started an echo. I also tried to have it record and then play back later, but it said that the input had overloaded.

NEW DEVELOPMENT: the feedback is the echo, for some reason when the frames per buffer or the CHUNK is decently high, there is an echo, when it is like the code below, the echo compounds and speeds up to result in feedback, multiple echos playing at once to become a high shrill noise.

PLEASE HELP!!!

import pyaudio

CHUNK = 1024
WIDTH = 2
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5

p = pyaudio.PyAudio()

stream = p.open(format=p.get_format_from_width(WIDTH),
channels=CHANNELS,
rate=RATE,
input=True,
output=True,
frames_per_buffer=CHUNK)

print("* recording")

for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
stream.write(data, CHUNK)

print("* done")

stream.stop_stream()
stream.close()

p.terminate()


## 1 Answer

Feedback squeal or echo is pretty much the expected result of the given code.
This program just takes audio in from the microphone and sends it back out through the speaker. If the speaker is loud enough, the audio the microphone picks up from the speaker will be louder than what was sent to the speaker - with each go around, it gets louder. This produces the infamous feedback squeal. If the delay is long enough, you an echo that gets louder and louder instead of a squeal.

You may also have a problem with your sound card configuration. Some sound cards allow you to send the microphone input straight to the speaker output so that you can use headphones to monitor the recoring live. If that is active on your sound card, then that may contribute to the feedback. This will more likely cause a high pitched squeal that is independent of the length of the buffer.

To break the feedback, do the following:

1. Check that your sound card isn't routing the microphone straight to the speaker. (Stop your program and talk into the microphone. If you hear your voice coming out of the speaker then you need to fix this in your sound card mixer.)
2. User headphones instead of a speaker.
3. Turn the speaker volume down or lower the microphone sensitivity (both can be done through the mixer, speaker can also be done on the speaker with the volume control.)
• Headphones did the trick, the problem was both the echo but once I used the headphones I found that my laptop's fan was also adding to the noise. – Queue21 Dec 18 '14 at 1:03