Arduino Forum

Using Arduino => Audio => Topic started by: un1x on Feb 09, 2011, 07:33 pm

Title: How to capture voice and playback with Arduino
Post by: un1x on Feb 09, 2011, 07:33 pm
Hi all.

I'm trying to make a (apparently) senseless experiment.
The idea is to capture voice and sound from a microphone and simply riproduce the sound
through a speaker.

I assume that both microphone and speaker has to be connected to the PWM in some way.

I also really don't know what Arduino can read from the microphone PWM and if it's possible to
send these values to the destination PWM.

Any suggests appreciated.

BYE !
Title: Re: How to capture voice and playback with Arduino
Post by: Grumpy_Mike on Feb 09, 2011, 07:37 pm
Basically you do not have enough memory to store anything but a small fraction of a second of speech on an arduino.

Therefore you need to get into sound shields with things like SD cards and external d/A converters. There are commercial ones available.
Title: Re: How to capture voice and playback with Arduino
Post by: WilliamK Govinda on Feb 09, 2011, 10:05 pm
Hummm, I wonder how fast is the max sample-rate of the analog input...

Depending on what he wants to do, there's no need for much memory. In any event, a cheap FLASH or EEPROM 2-wire chip could do the trick. Just don't know what would be the rates to record and read from those.

Wk
Title: Re: How to capture voice and playback with Arduino
Post by: Grumpy_Mike on Feb 09, 2011, 10:23 pm
Quote
Hummm, I wonder how fast is the max sample-rate of the analog input

That is fine, it's not the problem.
You can't write to flash or EEPROM fast enough, especially over the i2c bus. You might just get away with SDRAM on i2c running at 400KHz but you still have the output side, PWM doesn't hack it.
Title: Re: How to capture voice and playback with Arduino
Post by: Senso on Feb 10, 2011, 01:53 am
In the arduino default code its something like 9.6Khz, the maximum is almost 15.2Khz.
Title: Re: How to capture voice and playback with Arduino
Post by: un1x on Feb 10, 2011, 05:11 pm
Thank you very much for your replies.

Basically 9.6 Khz is enough for me, telephone quality is acceptable for this project.

I don't need to store the voice recorded but just "route" values from the analog in to the speaker.

Something like:

val = analogRead(..);
analogWrite(val,...);

My confusion is actually on signals and the pin to connect.

Microphone must be amplified and connected to an analog pin, but I don't know how to connect the speaker (PWM ?)
and how to convert analog values read from microphone to something useful and correct to write on the speaker pin.

MIC --> OP AMP --> ANALOG IN (?????) PWM --> SPEAKER

Is it right ?

Thank you very much.
Title: Re: How to capture voice and playback with Arduino
Post by: Grumpy_Mike on Feb 10, 2011, 06:17 pm
Quote
I don't need to store the voice recorded but just "route" values from the analog in to the speaker.

So why have it going into the arduino in the first place, surely a piece of wire would do.

Analogue in returns a 10 bit number, the PWM needs only an 8 bit number so you have to convert the sample between reading it and spitting it out. Something like
analogWrite(13, analogRead(0) >> 2) ); would do it.
Title: Re: How to capture voice and playback with Arduino
Post by: un1x on Feb 10, 2011, 06:39 pm

Quote
I don't need to store the voice recorded but just "route" values from the analog in to the speaker.

So why have it going into the arduino in the first place, surely a piece of wire would do.

Analogue in returns a 10 bit number, the PWM needs only an 8 bit number so you have to convert the sample between reading it and spitting it out. Something like
analogWrite(13, analogRead(0) >> 2) ); would do it.


Eh eh eh I'm studying this to get in confidence with different kind of signals.
Next step is to send the read value to another arduino via radio to play the voice with a remote speaker.
Title: Re: How to capture voice and playback with Arduino
Post by: Grumpy_Mike on Feb 10, 2011, 06:46 pm
Quote
to send the read value to another arduino via radio to play the voice with a remote speaker.

That's the bit I told you that you couldn't do. Best of luck at doing it or redefining the success criteria.
Title: Re: How to capture voice and playback with Arduino
Post by: un1x on Feb 10, 2011, 07:05 pm
Mmmmmh .. well, I can't believe isn't possible to build up something easy like a walkie talkie with Arduino  :)
Title: Re: How to capture voice and playback with Arduino
Post by: Grumpy_Mike on Feb 10, 2011, 07:12 pm
Used many digital walkie talkies then?  ;)

Analogue transmission is a whole different ball game to digital transmission.
Title: Re: How to capture voice and playback with Arduino
Post by: WilliamK Govinda on Feb 10, 2011, 10:40 pm
I think its totally possible, maybe even using a cheaper FM transmitter, but heck, in the Arduino you could use Xbee.

Wk
Title: Re: How to capture voice and playback with Arduino
Post by: un1x on Feb 12, 2011, 11:21 am
Well, for the transmission it's easy to use some radio module.

But I still don't understand if it's correct to send value read from the analag in to the module to the other board :D

And if it's possible to play back again to the speaker.

bye!
Title: Re: How to capture voice and playback with Arduino
Post by: Luan on Feb 15, 2011, 08:47 pm
Hi un1x

My Last project (when I was a student) using a PIC record sound from a mic and the phone line the pic buffered it and streamed it to the PC.
I used a 20Mhz Crystal and were able to get 12Khz.

The Microphone Amplifier

A LM324N a low-cost operational amplifier is used to amplify the microphone to an audible level. Two stages are used the first stage gives a amplification of  +- 45 (R7/R2), R5 is set to +- 22K? and the second stage give an amplification of +- 22 ((R9+R5)/R8). The two stages combined give a total amplification gain of 990. R3 and R4 provide a center voltage of 2.5V for microphone and is connected to the first stage. C8 only lest the AC audio signal through.  R11 and R12 provide a center voltage of 2.5V which is connected to the ADC input  on  the Microcontroller.

Attached is the diagram for the MIC interface.

Regards

Luan
Title: Re: How to capture voice and playback with Arduino
Post by: Grumpy_Mike on Feb 15, 2011, 10:39 pm
Quote
the pic buffered it and streamed it to the PC.

So how much memory did this PIC have?
Title: Re: How to capture voice and playback with Arduino
Post by: Luan on Feb 15, 2011, 11:23 pm
Hi

I don't remember, it was a pic18F2550, I buffered 32 bytes at a time to the PC and the PC saved all the bytes, when the recording was done the PC converted it to a WAV file.
The PIC only streamed the audio to the PC.
I wroted code in C Builder to write the buffer to a file and then used a WAVE Module by Timothy J. Weber. to conver it to a wav file,

I did the project in 2007 You will have to goolge for the module.

Hope that helps

Regards
Title: Re: How to capture voice and playback with Arduino
Post by: Grumpy_Mike on Feb 15, 2011, 11:41 pm
That chip has a USB 2.0 full speed interface on it, is that how you were able to transfer so much memory so quickly?
Remember the arduino only has a serial port.
Title: Re: How to capture voice and playback with Arduino
Post by: Luan on Feb 16, 2011, 08:30 am
Hi Grumpy_Mike

I used the CDC Class (128000 // baud rate) and not the full USB on the PIC, Because I used a serial driver on the PC It looked to difficuled to use full USB and I did not have a lot of time to complete the project.

I was just trying to contribute to the form.

Bye for now
Title: Re: How to capture voice and playback with Arduino
Post by: un1x on Feb 16, 2011, 11:51 am
Thank you very much Luan, I really appreciate it.

Bye !
Title: Re: How to capture voice and playback with Arduino
Post by: buycris on Mar 14, 2012, 12:54 am
Guys I havent read everything here, but this is more than possible. Using an AVR I stream straight out of a pwm pin 8KHz wav files stored on an sd card. It was reading the data into a buffer, while sending the values of a second buffer full of wav file to pwm0. Worked like a charm
Title: Re: How to capture voice and playback with Arduino
Post by: Veee on Sep 19, 2012, 10:59 am
Do you have the code for this? On how you captured the voice.
Thanks :)