Posts Tagged ‘european union’

Linux record audio from console / terminal with rec, arecord and ffmpeg

Monday, January 14th, 2013

 

Recording sound input from microphone linux penguin holding microphone

Recording from microphone input on Linux is possible, through multiple programs.

1. Recording microphone input using SoX's rec

 The classical old-school way is through a little proggie called sox. Back in the day I remember we recorded with sox with a friend from the school years necroleak – mirror of his website is on kenamick.www.pc-freak.net, trying to make save vox for one of his Tracked Songs. The experiments was not very succesful as both the PC microphone was low quality one, as well as the the state of recording microphone sound streams on Linux was terrible, but at least I learned about sox.

sox is not so popular and mainstream as it used to be back in the day but for anyone willing to investigate into the roots of GNU / Linux sound capturing make sure you have installed sox, alsa-utils and lame package. The package is available across virtually all main stream Linux distributions, depending on the distro to INSTALL sox do:

 

apt-get install --yes sox alsa-utils lame 
....

 (On Debian, Ubuntu, Arch, Xubuntu … )

yum -y install sox  alsa-utils lame
....

 (on Fedora, CentOS, RHEL …)

 slapt-get install sox ; swaret install sox alsa-utils lame
.....

(on Slackware and derivatives)

Before continuing it is a good idea to check, the microphone is not muted in alsamixer, amixer or aumix

The SoX package provides 4 binaries;

dpkg -L sox|grep -i /usr/bin/
/usr/bin/sox
/usr/bin/rec
/usr/bin/play
/usr/bin/soxi

sox -is tool to apply effects to recorded sound streams

rec – is historically among the first sound recorder tool to make records from microphone (even form the days of OSS – Open Sound System)

play – play is tiny .WAV and some other native classical sounds formats with a beautiful ASCII art (text) equalizer

soxi – gives information on recorded sound stream header (info)

rec -r 8000 -c 1 record_microphone_input.wav

rec is unfortunately made to use the old and now obsolete /dev/dsp sound interface, so on many Linux distributions, recording sound with it might pose problems.

Another problem of rec is it usually records with a lot of noise, thus reducing the noise later with sox cmd is almost necessery, to mitigate the noise you will have to experiment with its options. For some better quality of recording use arg -r 22050.

A little shell script with plenty of example use cases of rec and post sox effect applied as synchronization record_and_normalize_from_mic_with_rec_and_sox_on_linux.sh is here

Generally I mentioned rec for historical reasons, nowadays it is quite obsolete so you probably better stick to the newer alsa native arecord.

2. Recording sound from microphone using alsa-utils arecord

alsa-utils package has bunch of tools to record, play and tune sound;

dpkg -L alsa-utils |grep -i /usr/bin/
/usr/bin/aplaymidi
/usr/bin/aplay
/usr/bin/aconnect
/usr/bin/amixer
/usr/bin/alsamixer
/usr/bin/aseqdump
/usr/bin/arecordmidi
/usr/bin/speaker-test
/usr/bin/iecset
/usr/bin/amidi
/usr/bin/aseqnet
/usr/bin/arecord

One of tools included arecord is able to capture sound from microphone. arecord, can record into .WAV, but as .WAVs are not compressed and most people prefer to save the input to some more wide recognized format as .MP3 it should be invoked in conjunction with lame;

arecord -D plughw:0,0 -f S16_LE -c1 -r22050 -t raw | lame -r -s 22.05 -m m -b 64 - mic-input.mp3


Writting this long and hard to remember command line and arguments is tough, so I created a tiny shell script wrapper which accepts as 1-st argument a file name and saves .WAV and converts it to .MP3. The script linux_record_from_microphone.sh is here

3. Recording from microphone input using ffmpeg

I've earlier blogged on how to use ffmpeg to capture Microphone sound here.

For those lazy to read my previous post the skele syntax is;

ffmpeg -f alsa -ac 2 -i pulse -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 -y myVOICE.wav 

To later convert WAV to MP3 use lame;

 lame -r -s 22.05 -m m -b 64 myVOICE.wav  mic-input.mp3

Selecting Best Wireless channel / Choosing Best Wi-FI channel for Wireless Routers or (How to improve Wireless Network performance)

Monday, February 22nd, 2010

Wireless AP
Below are some valuable advices on Wireless Access Point initial install and configuration to better off your Wireless connection.It’s worthy to note that the 2.4 GHz

Wi-Fi signal range is divided into a number of smaller bands or “channels,” similar to television channels. I decided to run my wireless on channel 12 since this there was no other wireless routers operating on that frequency, though most routers are preconfigured to spread it’s signal on channel 6.

There is a difference in channels available for setup for 802.11b and 802.11g wireless networks in the United States and the European Union. In the USA the wireless channels available are from (1 to 11) whether in the EU it’s in the range of (1-13). Each of the Wireless channels run on a different frequency.

The lower the number of the channel is the lowest the radiating frequence band on which data is transmitted .Subsequently, increasing the channel increases the frequency slightly. Therefore the higher the channel you select on your AP the lesser the overlap with other devices running on the same channel and thus the lesser the possibility to overlap and interference.
It’s quite likely that you experience problems, if you use the default wireless channel which is 6.
If that’s the case it’s recommended to use either channel 1 or channel 11. In case of interference, i.e. overlap with other wireless networks, cellphones etc., there are 2 possible ways to approach the situation. In case of smaller interference, any change in channel on which there is no wireless device running could fix it up. The second way is to choose a wireless channel for your router in between 1,6 or 11 in (The USA) or 1,7,13 in Europe.
Up to 3 networks can run on the same space with minimum interference, therefore it would be a wise idea to check the list of wireless routers in your and check if there are others running on the same frequency.
As I mentioned in the beginning of the post I initially started running my wireless on channel 12, however after I discovered it is recommended to run your wireless router either on channel 1 7 or 13 in Europe I switched my D-Link DI-524 wireless router to transmit it’s signal on Channel 13.

I should testify that after changing the wireless channel, there was quite an improvement in my wireless connection.For instance before I change to Channel 13 (when my wireless internet was still streamed on channel 12) my wireless had constantly issues with disconnects because of low wireless signal.

Back then My wireless located physically in like 35 meters away set in another room, I can see my wireless router hardly connected on like 35%, changing to channel 13 enhanced my connection to the current 60% wireless router availability.

It’s also an interesting fact that Opened Wireless networks had better network thoroughput, so if you’re living in a house with a neighbors a bit distant from your place then you might consider it as a good idea to completely wipe out Wireless Router security encryption and abandon the use of WEP or WPA network encryption.

In case if all of the above is not working for you, you might consider take a close look at your Wireless Wireless LAN pc card and see if there are no any kind of bumps there. Another really interesting fact to know is that many people here in Bulgaria tend to configure there Wireless Access Points on channels either 1,6 or 11 which is quite inadequate considering that we’re in the EU and we should use a wireless channel between 1, 7 or 13 as prescribed for EU citizens.

Another thing not to forget is to place your wireless in a good way and prevent it from interferences with other computer equipment. For example keep the router at least few meters away from PC equipment, printers, scanners, cellphones, microwaves. Also try to put your wireless router on some kind of central place in your home, if you want to have the wireless signal all around your place.

At my place I have a microwave in the Kitchen which is sometimes an obstacle for the Wireless signal to flow properly to my notebook, fortunately this kind of interference happens rare (only when the Microwove is used to warm-up food etc.).Upgrading 802.11b wireless card / router to a better one as 802.11g is a wise idea too. 802.11g are said to be like 5 times faster than 802.11b.

You can expect 802.11b wireless network to transfer maximum between 2-5 Mbp/s whether 802.11g is claimed to transfer at approximately (12 to 23 Mbp/s). If even though the above prescriptions there is no wireless signal at some remote place at your home, you might consider adding a wireless repeater or change the AP router antenna.

By default wireless Routers are designed to be omni-directional (in other terms they broadcast the wireless signal all around the place. Thus is quite unhandy if you intend to use your Wireless net only in certain room or location at your place. If that’s the case for you, you might consider upgrading to a hi-gain antenna that will focus the wireless signal to an exact direction. Let me close this article with a small diagram taken from the net which illustrates a good router placement that will enable you to have a wwireless connection all over your place.

improve wireless router placement diagram