----
https://cn.comsol.com/paper/download/153149/thiagarajan_paper.pdf
-----
mp3 <--- raspberry <--- usb soundcard <--- preamp <--- electret
-----
The ADS1113, ADS1114, and ADS1115 are precision analog-to-digital converters (ADCs) with 16 bits of resolution offered in an ultra-small, leadless QFN-10 package or an MSOP-10 package. The ADS1113/4/5 are designed with precision, power, and ease of implementation in mind. The ADS1113/4/5 feature an onboard reference and oscillator. Data are transferred via an I²C-compatible serial interface; four I²C slave addresses can be selected. The ADS1113/4/5 operate from a single power supply ranging from 2.0V to 5.5V.
http://raspberrypi.stackexchange.com/questions/1293/how-can-i-connect-an-analog-to-digital-converter-adc
http://www.forum-raspberrypi.de/Thread-raspbian-line-in-als-mp3-direkt-aufzeichnen
pi@raspberrypi ~ $ arecord -l
https://www.raspberrypi.org/forums/viewtopic.php?t=67543&p=493872
http://sonof8bits.com/automated-raspberry-pi-audio-recorder/2014/09
Automated Raspberry Pi audio recorder
Today we’re gonna roll our very own sound recorder using a Raspberry PiThis tutorial will show you how to build a fully automated recorder using an RPi, a USB sound card and a USB drive.
First up; install Raspbian, make sure it defaults to the command line and/or has SSH access so you can login to it from another computer. There’s plenty of tutorials out there explaining how to do this.
Second; make sure you have a compatible sound card, (I used a spare Griffin iMic, any class compatible one should work) and a USB flash drive. It should be possible to write to the SD card you’re using on the RPi, but people have had problems going that route. Besides, using a fat32 formatted usb drive will ensure you can plug it into you computer and play or copy the sound files without having to login (ssh) to the RPi.
First we’re gonna get rid of a lot of unwanted stuff! This isn’t a complete list, but I’m sure we can live without these applications installed taking up precious CPU cycles, RAM and disk space. Note: This will completely wipe the graphical user interface. You won’t be able to use the desktop anymore!
$ sudo apt-get purge galculator idle3 idle idle-python3.2 python3 midori scratch xpdf midori dillo netsurf-common netsurf-gtk leafpad penguinspuzzle pistore gpicview heirloom-mailx wpasupplicant aptitude xarchiver omxplayer aspell usbmuxd debian-reference-common debian-reference-en python-picamera cups-bsd cups-common vim-common vim-tiny desktop-base lightdm lxappearance lxde-common lxde-icon-theme lxinput lxpanel lxpolkit lxrandr lxsession-edit lxshortcut lxtask lxterminal obconf openbox raspberrypi-artwork xinit xserver-xorg xserver-xorg-video-fbdev xserver-common xserver-xorg-core xserver-xorg-video-fbturbo x11-common x11-utils x11-xkb-utils xauth xfonts-encodings xfonts-utils oracle-java7-jdk aptitude-common python python-gi python-minimal python-pifacecommon python-pifacedigitalio python-rpi.gpio python-serial python-support python2.7 python2.7-minimal python3.2 python3.2-minimalFollowed by:
$ sudo apt-get autoremoveAnd:
$ sudo apt-get autocleanThat’s a lot of stuff we won’t be using! Now, we’re gonna install what we do want:
$ sudo apt-get install sox libsox-fmt-mp3Sox is a specialized recording, processing and playback application. I won’t go into it too much, but it fits our needs perfectly. The second, libsox-fmt-mp3, is a library so we can encode to MP3 (if that’s what you want).
Now that we deleted and installed what we need, let’s set-up the soundcard. First up, let’s kill the built-in sound card:
$ sudo nano /etc/modulesAnd comment out:
snd-bcm2835By putting a “#” in front of it. Like so:
# snd-bcm2835To be sure USB is first in line, we’re gonna force ALSA to pick it over the built-in one, even if we’ve just killed it.
$ sudo nano /etc/modprobe.d/alsa-base.confAnd comment out:
options snd-usb-audio index=-2Again, with a “#” like this:
# options snd-usb-audio index=-2
Last but not least enter:
$ alsamixerAnd set the recording levels of your soundcard to how you like them by pressing F4. To make sure the Raspberry Pi always boots up with these sound settings, enter this in the command line:
$ sudo alsactl storeMake a folder to mount the USB stick in:
$ sudo mkdir /mnt/USB/Now we’re gonna make a few scripts. Don’t be afraid if you’ve never done this before, I’ve pre-fabricated them for you! In your home folder (Type “cd” and hit enter if you’re not certain), type:
$ mkdir ScriptsThis’ll make a neat little folder for you to put scripts in. Change into it by typing:
$ cd Scripts/Next:
$ nano MyBoot.shCopy and paste the following into it.
#!/bin/bashPress “ctrl+x” to exit, “Y” to save, followed by an enter. You should now be back in the command line. This script will automatically mount your USB drive in /mnt/USB/ and kill some unwanted services clogging up RAM and CPU cycles. Most of this script was made by Autostatic, check out his original work here.
## Created by Son of 8-Bits
## http://sonof8bits.com/
## Borrowing parts from Autostatic
## http://autostatic.com/
## Mount the USB stick and kill unwanted services
## mount the USB stick
sudo mount -t auto /dev/sda1 /mnt/USB
## Stop the ntp service
sudo service ntp stop
## Stop the triggerhappy service
sudo service triggerhappy stop
## Stop the dbus service. Warning: this can cause unpredictable behaviour when running a desktop environment on the RPi
sudo service dbus stop
## Stop the console-kit-daemon service. Warning: this can cause unpredictable behaviour when running a desktop environment on the RPi
sudo killall console-kit-daemon
## Stop the polkitd service. Warning: this can cause unpredictable behaviour when running a desktop environment on the RPi
sudo killall polkitd
## Kill the usespace gnome virtual filesystem daemon. Warning: this can cause unpredictable behaviour when running a desktop environment on the RPi
killall gvfsd
## Kill the userspace D-Bus daemon. Warning: this can cause unpredictable behaviour when running a desktop environment on the RPi
killall dbus-daemon
## Kill the userspace dbus-launch daemon. Warning: this can cause unpredictable behaviour when running a desktop environment on the RPi
killall dbus-launch
## Set the CPU scaling governor to performance
echo -n performance | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
exit
Now for the recording script:
$ nano Record.shContaining:
#!/bin/bashctrl+X, Y, enter
## Created by Son of 8-Bits
## http://sonof8bits.com/
## 48000Hz stereo MP3 at 320kbps that automatically stops recording after 1 minute of silence.
FILENAME=$(date +”%Y%m%d_%H%M”)
sudo rec -c 2 -r 48000 -C 320.99 –buffer 262144 /mnt/USB/${FILENAME}.mp3 silence 1 0.1 1% 1 1:00 1%
[ $? -eq 0 ] || exit $?
sleep 10
sudo shutdown now
exit
To make these scripts work as planned enter:
$ sudo chmod 755 MyBoot.sh Record.shBut these scripts won’t start by themselves just by being there! To make them start at boot type:
$ sudo nano /etc/rc.localOn the empty line after “# By default this script does nothing.” add:
sudo /home/pi/Scripts/MyBoot.shctrl+X, Y, enter
sudo /home/pi/Scripts/Record.sh
BAM! You’re done!
Try it out by hooking up a sound source to the line-in of your soundcard, booting the Pi, and recording a part of whatever it is you want to record. Note that after one minute of silence the RasPi will shut itself down. Listen back what you’ve just recorded by unplugging the USB flash drive and plugging it in you computer. Here are some tips if things are not to your liking.
Volume too low or high? Check the part about Alsamixer. (And don’t forget to check the level coming out of your audio source as well!)
Like to stop sooner (or later) after silence sets in, edit the recording script. See the part that says “1:00″? This is 1 minute, edit it to your liking. For instance ‘0:30′ for 30 seconds or ‘2:00′ for 2 minutes.
Pi not getting enough power? Use a 2 ampere powerplug or put a powered USB-hub between the RasPi and the soundcard/USB stick.
----------------------
http://scruss.com/blog/2012/11/20/raspberry-pi-as-a-usb-audio-capture-device/
sudo apt-get install alsa-utils pulseaudiohttp://plugable.com/2014/11/06/how-to-switch-to-usb-audio-on-raspberry-pihttp://www.g7smy.co.uk/?p=283Recording Sound on the Raspberry Pi
The Raspberry Pi does not have a microphone socket, which is
inconvenient when you wish to record sound. To fix this you will need a
USB Sound Card, for which I bought a Creative Sound Blaster Play! for about £20 and a short USB extension lead as the sound card is slightly too large and blocks the other USB port.
With the latest Raspbian “wheezy” installed on a Pi Model B with 512Mb of RAM and the overclocking set to High in raspi-config, here is a recipe for getting your Raspberry Pi to record sound from the command line. For the test setup I connected my iPod to the microphone port of the sound card, plugged everything in and powered up.
After logging into the Pi, check that the computer can see the card, use lsusb to find it, here the card is highlighted in blue:
Your user will need to be in the audio group, check this with groups <username>:
There is/was an issue with the Pi’s USB port that meant it can/could become overwhelmed1 with data which causes popping and bubbling noises to be included in your recordings, this can be fixed with an update of the Pi’s firmware:
The Raspbian image already has the alsa-utils for sound already installed, the programs I am using for recording and playback are:
There are two methods for setting up the the microphone port on the card, the first is alsamixer:
Alternatively, you can use amixer. First find your sound card, in amixer there does not appear to be a method of listing the available cards, but on a Raspberry Pi I guess it will always be card 1, you can list the cards current status with:
So I want to turn the Auto Gain Control off, and the recording volume to 14:
again, store the settings so that they will be used again on a reboot:
Now we are ready to do a test recording, first check that arecord will see your card:
and now for a ten second test recording, this will create a file called rectest.vav in your home directory. Remember to set the Device (-D plughw:1) number to the right card (card 1):
the default settings will play the wav fie through the TV if it is connected by HDMI, To playback through the USB sound card set the device to the card number, like in arecord:
Congratulations, you now have a fully working Pi Recording Device. Remember to experiment with the volume levels, too high and your recording will sound distorted.
References:
With the latest Raspbian “wheezy” installed on a Pi Model B with 512Mb of RAM and the overclocking set to High in raspi-config, here is a recipe for getting your Raspberry Pi to record sound from the command line. For the test setup I connected my iPod to the microphone port of the sound card, plugged everything in and powered up.
After logging into the Pi, check that the computer can see the card, use lsusb to find it, here the card is highlighted in blue:
$ lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 046d:c52e Logitech, Inc.
Bus 001 Device 005: ID 041e:30d3 Creative Technology, Ltd Sound Blaster Play!remember that different makes of card will have different names and ID’sYour user will need to be in the audio group, check this with groups <username>:
$ groups pi
pi : pi adm dialout cdrom sudo audio video plugdev games users netdev input if not, then add them with:$ sudo usermod -a -G audio <username>There is/was an issue with the Pi’s USB port that meant it can/could become overwhelmed1 with data which causes popping and bubbling noises to be included in your recordings, this can be fixed with an update of the Pi’s firmware:
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install rpi-update
$ sudo rpi-update
The Raspbian image already has the alsa-utils for sound already installed, the programs I am using for recording and playback are:
- alsamixer – GUI for setting the recording and playback levels
- amixer – Command Line for setting the recording and playback levels
- alsactl – for saving the settings set in alsamixer or amixer to use again after a reboot
- arecord – For recording the sound
- aplay – For playing back your recording
There are two methods for setting up the the microphone port on the card, the first is alsamixer:
$ alsamixerPress F6: Select Sound Card, and choose yours from the list, the bcm2835 ALSA is the on-board sound, for me the one to pick was: USB Device 0x41e:0x30d3 and take a note of the card number, in my case: 1. Now select the Mic
and increase the volume to 52, or the first white blob, you’ll need to
change it later, but its a good place to start. The Auto Gain Control
wants to be off, select the gain control and press M to toggle so it displays [MM] for mute. Press Esc to exit and save the settings with:$ sudo alsactl store 1 where 1 is the card number.Alternatively, you can use amixer. First find your sound card, in amixer there does not appear to be a method of listing the available cards, but on a Raspberry Pi I guess it will always be card 1, you can list the cards current status with:
$ amixer --card 1 contents
numid=1,iface=MIXER,name='Mic Playback Switch'
; type=BOOLEAN,access=rw------,values=1
: values=off
numid=2,iface=MIXER,name='Mic Playback Volume'
; type=INTEGER,access=rw---R--,values=1,min=0,max=32,step=0
: values=21
| dBminmax-min=0.00dB,max=47.81dB
numid=5,iface=MIXER,name='Mic Capture Switch'
; type=BOOLEAN,access=rw------,values=1
: values=on
numid=6,iface=MIXER,name='Mic Capture Volume'
; type=INTEGER,access=rw---R--,values=1,min=0,max=16,step=0
: values=7
| dBminmax-min=0.00dB,max=23.81dB
numid=7,iface=MIXER,name='Auto Gain Control'
; type=BOOLEAN,access=rw------,values=1
: values=on
numid=3,iface=MIXER,name='Speaker Playback Switch'
; type=BOOLEAN,access=rw------,values=1
: values=on
numid=4,iface=MIXER,name='Speaker Playback Volume'
; type=INTEGER,access=rw---R--,values=2,min=0,max=151,step=0
: values=52,52
| dBminmax-min=-28.37dB,max=0.06dBSo I want to turn the Auto Gain Control off, and the recording volume to 14:
$ amixer -c 1 cset numid=7,iface=MIXER,name='Auto Gain Control' 0
numid=7,iface=MIXER,name='Auto Gain Control'
; type=BOOLEAN,access=rw------,values=1
: values=off
$ amixer -c 1 cset numid=6,iface=MIXER,name='Mic Capture Volume' 14
numid=6,iface=MIXER,name='Mic Capture Volume'
; type=INTEGER,access=rw---R--,values=1,min=0,max=16,step=0
: values=14
| dBminmax-min=0.00dB,max=23.81dBagain, store the settings so that they will be used again on a reboot:
$ sudo alsactl store 1Now we are ready to do a test recording, first check that arecord will see your card:
$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: U0x41e0x30d3 [USB Device 0x41e:0x30d3], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0and now for a ten second test recording, this will create a file called rectest.vav in your home directory. Remember to set the Device (-D plughw:1) number to the right card (card 1):
arecord -D plughw:1 --duration=10 -f cd -vv ~/rectest.wav the -vv
option displays extra information on the screen as well as a volume
meter, this should be peaking at around 95% on the loudest sounds, if it
is at 100% all a lot of the time then you are probably recording
distortion. Playback the recording with aplay:aplay ~/rectest.wavthe default settings will play the wav fie through the TV if it is connected by HDMI, To playback through the USB sound card set the device to the card number, like in arecord:
aplay -D plughw:1 ~/rectest.wavCongratulations, you now have a fully working Pi Recording Device. Remember to experiment with the volume levels, too high and your recording will sound distorted.
References:
- Raspberry Pi Usb Audio fix (10 May 2013)
4 thoughts on “Recording Sound on the Raspberry Pi”
Leave a Reply
Your email address will not be published. Required fields are marked *
I have one question. In your opinion, could someone record sound and something later (for example 60 seconds) playback the file. That is, could you introduce this type of delay to your IPOD. I am interested in designing one device that record what I listen from my radio and sincronize with a video streaming.
Thanks so much.
Pablo.
I am new to the whole raspberry pi thing, but I am trying to record sound with one. Would I be able to connect a microphone into the sound card instead of the iPod and still record sound? (I want to record sound on a street). And then would I need to write additional code for that or could i just use the code you have created?
Looking forward to your advice.
Thanks,
Jessica