Electronic – How to integrate microphone and speaker into the microcontroller project

audiomicrocontrollermicrophonespeakers

Having never worked with mic and speakers in the past, I am experimenting with these. I already made a simple circuit with a mic (electret condenser microphone) and speaker. I used the above mic with simple amplifier stage and then computer speaker. It works well.

Now, I am thinking of building a simple microphone, speaker and microcontroller circuit. The idea is basically to feed in the input from mic to microcontroller and then output the audio signal to the speaker.

For that I think I need to first convert the analog signal from the mic to digital values using AVR's ADC. After that I need to output the analog values to the speaker. Since this is my first time, I need advice on how to build a working circuit. What should be the sampling and playback rate? Do I have to worry about codecs, etc? (I don't know how large raw audio data can be.)

I am planning on using Arduino first since it's easy and quick for prototyping.

Any help is appreciated as always! 🙂

Best Answer

Your sample rate must be twice the maximum frequency of interest. This is the Nyquist–Shannon sampling theorem. If you want hi-fidelity audio, your maximum frequency is the limit of human hearing, about 20kHz. Human voice is less demanding: telephone networks work up to about 3400 Hz.

You will find that the AVR's ADC isn't terribly fast, and you don't have much resources to process the data. So probably, your hardware limitations will dictate the sample rate for you.

You probably don't need to worry about codecs. A codec encodes and decodes an audio stream. A common thing to do is compress the audio for more efficient storage or transmission, but it doesn't sound like you are doing either. There are codecs that encode and decode for reasons other than compression, but I can't think of any that would be relevant here. Your computing resources are very limited on the microcontroller anyway, and you won't have much time for encoding or decoding anyway.