Tag Archives: mp3

Cyclic sound MP3 audio recording in ubuntu

I work in a relatively safe environment, yet it may very well happen that I need to prove something that someone said in my office, so I can hold it against them when the time comes.

My laptop is always turned on, so I could use it to record the environmental sounds around it, with a couple of requirements:

  • the recording must be totally unattended, starting when I turn on the pc, and stopping when I turn it off, without any user intervention
  • the recorded files must be somehow purged, starting from the oldest ones, so that my disk doesn’t get filled with audio files

As in the Ubuntu spirit, I tried to search for something that did the job right away, but with no luck.

So, still in the Ubunt spirit, I had to arrange it myself: the idea is to record the audio in chunks of 10 minutes, and each time delete the oldest files, so that there is a chosen number of max files inside the recording folder.

You will need the audio-recorder package for the job, install it as follows:

sudo apt-add-repository ppa:osmoma/audio-recorder
sudo apt-get update
sudo apt-get install audio-recorder

when the program is installed, open it (Alt-F2 and then launch audio-recorder), click on the “additional settings” button, and setup your default recording folder there, in this example it’s the folder “audiofiles” directly under your home folder.
Also I suggest changing the file naming standard to %Y-%m-%d-%H:%M:%S so that each recording can be easily associated with the time of starting.

Then, you need to make a bash script that will deal with starting a new recording, while closing the previous one, this is what I came up with:

#!/bin/bash

/usr/bin/audio-recorder --display=:0.0 -c stop
/usr/bin/audio-recorder --display=:0.0 -c start
cd /home/username/audiofiles
rm `ls -t | awk 'NR>150'`

which does exactly the following: stops a previously open (if existing) instance of the program, and starts a new one, then deletes the oldest recorded audio chunks so that there are maximum 150 files inside the recording folder (if you want a different amount, just replace 150 with the number you prefer); please note that the recording folder written in this bash script must be the same that is set in the additional settings, so if you want to use a different folder make sure to set it up both in audio-recorder and in this bash script.
Also, please note that the username part of the path must be replaced with your ubuntu username.

You can create this bash script as a “recordaudio.sh” file in your home folder, and then be sure to chmod +x recordaudio.sh so you can execute it.

Then, you need something that actually starts the recording, and cron is our friend here.

Run the command

crontab -e

and if it’s the first time you run it,  you should be presented with a choice screen asking you which editor you prefer… absolutely choose nano!

Inside the editor screen, paste this:

*/10 * * * * /home/username/recordaudio.sh

where “username” must be replaced with you ubuntu username, then press Ctrl-X to save the file (press Y is prompted to confirm).

What this cron line does, is running the bash script we just created every ten minutes, so the recorded sound files will be 10 minutes long. If you want to change this length, just change the 10 in the command to the number of minutes you prefer.

Restart the pc, and notice how files are being created inside of your folder. After a while, you will also get over the set limit for the files, and you will notice how the number of files will always stay the same, with the oldest files being deleted.

How to order, manage, rename, tag your MP3 collection

Have thousands of MP3 files? Literally? Hopefully, you’re like me, and your entire collection is made by ripping the original CD’s you own and you paid for.

So, often the files you …ehrm… "rip" have funny names, often they are all CAPS or are badly Capitalized, or, again, are full_of_underscores, they miss the proper order (Artist – Album Name – Track Number – Title Here), and most of all, they are badly tagged. As long as you’re willing to spend some time, and I assure you, after you can master the tools in here, it will be a short time, your whole collection will be in perfect shape and be ready to be shar– ehrm– shown to your best friends by doing an ASCII format list of them all.

First of all, we need to rename the files properly, this is what we use Magic Renamer for (get it from the Downloads/Tools section).

Since I simply cannot list evey kind of combination of naming errors you may encounter, let’s explain the worst case of them all, that is an album where the single songs have: underscores (like_this_one), wrong capitalization (LikE ThIs OnE), missing parts (like author-track-title, no album name), unordered parts (like track-album-title-author instead of author-album-track-title), trimmed letters (like hor-title instead of author-title). There may be more, but once you know how to deal with this, you’ll also learn how to use Magic Renamer yourself.

This is a polite example of what I am talking about. I just made up the thing, I don’t think you’ll be so unlucky. BTW I own the album. Natalie you rock!!

 

Start Magic Renamer and set it up as follows.

In the "Case" panel use this setting If You Want Every Word To Begin With Capital, the other options are self-explanatory.

 

In the "Space" panel this is what you should want to set. Oh, if you are wondering about the funny colours of these screenshots, they are the result of the extreme compression of the images.

 

And now let’s see how to fix those filenames in the screenshot. In the upper panel of Magic Renamer you will see how the files are currently named, and how they will be after the "makeup", which you make essentially by working on the trimmer, replacer and formatter panels. Some strategy: we will need to fix the author name to "Natalie Imbruglia", remove the dot after the track number, adjust the case of the words, replace the underscores with spaces, and put order in the sequence to have Author – Album – Track# – Title. The underscores and word case are easily corrected by the settings we already saw. Now to the rest.

Load the files inside Magic Renamer by browsing to the folder cotaining them and pressing the ">>>" button or by selecting all the single files and pressing the ">" button.

1) Fix the author name and put it in the beginning.

Remove the album name form the start of the filename, we will insert it later. In the "Trimmer" panel choose to remove the first "n" letters, check with the preview filenames to see how many of them need to be cut.

 

Here. Replace "alie_imbruglia" with "natalie imbruglia". Capital letters will be changed by Magic Renamer since it has been setted to, you don’t need to write them correctly. The other settings should be left as they are unless specifically needed. Note the hint at the bottom: we don’t use it in this example, anyway if you need to remove a word *inside* a filename, that is you can’t trim the beginning or the end to do it, simply replace it with a null string.

 

Press the "Go!" button in the bottom left corner (after it you can undo to the last state by pressing "Undo"). You will now have the files beginning with "Natalie Imbruglia", no album name, and a dot after the track number, where we want instead a "-".

2) Replace the dot after the track number with a "-"

Disable the trimmer since you don’t need anymore to cut parts of the filename.

You need now to replace the dot right after the track number, and insert a "-" with a space before it. This is how you do it: put a single dot followed by a space after "Replace", and " – " (beginning and ending with a space, this to avoid to change also the dot of the .mp3 extension) after "with".

 

Press the Go button again. Now you miss only the album name.

3) "Insert" the album name after the Author

Errm you could find this a bit stupid, but it’s for education purposes. Replace "Natalie Imbruglia" with "Natalie Imbruglia – White Lilies Island". C’mon, you don’t need a screenshot this time. Press Go and the game is done.

This is just one way we could do it, there are millions of combinations you can use Magic Renamer, the good is to find the shorter one. Anyway, considering you are renaming at least 10 files at a time with a few clicks and typing, you’re saving time. Let’s see another way we could do it.

1) Fixing the Author AND the Album Name at the same time.

Trim the first characters until there are only the track number and title left. Now you use the formatter panel. Yeah, no biggie, since you need to learn how to use the formatter, trim ALL the characters before the title, that is remove ALSO the track numbers and spaces after them. DO NOT PRESS GO YET. Now we see how to use the formatter.

In the "Formatter" panel you write how you would like to make additions to the current filename. In this case we have only the titles, so need everything before them. We will write "Natalie Imbruglia – White Lilies Island – $n – $w" where $n is the serial number of the file as it is ordered ascending by name, and $w is the filename as it results form the changes made in the other panels: this means that if you chose to trim the first and/or last n characters, and replace something with something else, the partial result of those transformations will be considered as the filename. The legend on the right side of the panel explains all the "jolly characters".

 

Press Go and everything is done. Easy isn’t it.

One last recommendation: always remember to disable the parts you don’t need to use, that is Trimmer, Replacer or Formatter, because they will otherwise always mess up with the filename.

 

Now to the ID3 Tags. There are two kind of ID3Tags, as you should know, ID3v1 (the very first, ultra-standard, few characters, one) and ID3v2 (the new, still-not-so-standard one which accepts longer strings and more fields).

Here I support only the first version, both because the only free versatile tool for tagging I know has no v2 support, and because another shareware one I know isn’t as flexible as the former creating ID3v2 tagnames. So, if you think you absolutely need to work on ID3v2 tags, the rest of the guide isn’t for you. I actually don’t care for short strings, I think they’re too short only for 5% of my collection, so who cares.

All those things being said, I go on with the directions. Download and install Quick MP3 Tag Maker from the Downloads/AudioVideo section. Browse to the folder containing the files you just renamed with Magic Renamer, and open the "Files-ID3" panel. You now will use the "Filenames to ID3" input line to tell the program how to pick up the single parts of the filename and put them in the correct tag fields. The "jolly" string I use 99% of the time is "%1- %3- %7 – %2" (space-sensitive), that is , as long as you renamed the file as I told you, in the format "Author – Album – Track – Title"

Look at the part "Filenames to ID3 Tags". If you are not sure about what to put in the input line, press the "Help" button and see the legend with the explanation for each jolly character. If you want to see how the tags will be written in the file, select a filename in the folder and press the test button. Press "Go" in the right part, Filenames to ID3 Tag.

 

It is done, for the rought part. If you want to fill all the ID3v1 fields you are now missing, Year, Genre and Comment, which anyway are not usually included in the filename itself, go to the "Multiple" panel and add those fields to all the files in one time.

Fill only the fields you miss, and check the boxes near them, then press the big Go button on the right.

 

You can check the result in the "Single" panel by highlighting one file per time.

The files are ready for storage.