Sampling Short Sequences From Long MP3 Recordings?
mehl writes "I am a professor for social psychology at the University of Arizona and I am looking for help with finding / developing a special program. In my research, I ask participants to carry around a digital voice recorder while they go about their normal lives. The voice recorder then tracks the ambient sounds in their environments and produces an 'acoustic log' of a person's day. We then use these ambient sound recordings as source data for various person perception studies. For privacy reasons, we are required to sample brief snippets of ambient sounds instead of recording an entire day continuously ('Big Brother is listening to you...'). So far, we have achieved this by modifying the hardware of a digital voice recorder (triggering it with an external microchip). With the high turn-over in player models, however, this strategy has turned out to be short-sighted (every half a year we have to build a new chip). I am thinking about switching strategy, recording continuously in the first place (no problem with the current generation of flash memory) and then sampling (random) snippets after the fact from the continous recordings. Does anybody know of an existing program that can randomly (or pseudo-randomly; e.g., 30 sec every 10 min) and automatically sample short sequences from a day-long (18 hours) mp3 recording? What would it entail to develop such a program (for Windows)?."
Just get something like mp3 splitter, cut it into appropriate size chunks, shuffle them and merge them back together. Then cut them to your ideal length.
I don't know if this is really what you are looking for, but Audacity is what I would look at. Perhaps a custom module could be written to handle random samples.
M
Audacity and a relatively simple plugin. Open source software is good like that.
"It's not your information. It's information about you" - John Ford, Vice President, Equifax
Sounds like a job for a really simple shell script driving mp3split. Sounds a lot easier than a custom chip!
Jump to a a random offset, look for the sync-word, copy a number of frames, repeat. The MP3 format is made of frames, there is no per-file header and since the format is designed to be used in streaming applications and to be robust against errors, you can jump right to the middle and grab a couple of frames without worrying about the rest. Many webpages have the frame spec. Here is one.
Perhaps something based off of PyMP3Cut ? I haven't used it, but the description seems pretty relevant ("PyMP3Cut was designed to slice high quality MP3 recordings of day-long congresses into smaller per-speaker MP3 files. It only needs the exact same amount of disk space as the original file to slice, even less if you plan to skip some parts, which PyMP3Cut can do automatically if you use a specially formatted *SKIP* entry in your timeline. It was successfully used many times against several hundredths megabytes MP3 files.").
finally able to load http://dingo.sbs.arizona.edu/~mehl/EAR.htm and it says "...So far, the EAR has operated on a 30 seconds on -- 12 minutes off cycle (i.e., it comes on every 12 minutes for 30 seconds), yielding on average about 70 samples of a person's acoustic social environment (i.e., 35 minutes of ambient sounds) per person per day...." so it's not full on all the time to begin with.
"Look Lois, the two symbols of the Republican Party: an elephant, and a fat white guy who is threatened by change."
MP3 is a bitstream, so you can basically use the language of your choice to seek to arbitrary offsets, slice wherever you like for as long as you like, and whatever frames are broken will simply not get decoded. You may of course want to actually have on-frame-boundry edits (they generally sound better and play more reliably, especially on ipod which doesn't have great stream reassembly code). cutmp3 can work:
- 0. 08/Frame.pm
/ Sp litter.pm
t /p p
:-)
http://www.puchalla-online.de/cutmp3.html
There's lots of pure windows code to do this too:
http://www.programurl.com/software/cutter.htm
But if you want to code this yourself, there's some excellent Perl libraries for managing MP3:
http://search.cpan.org/~nuffin/MPEG-Audio-Frame
(and most directly speaking to what you're working on)
http://search.cpan.org/~ilyaz/MP3-Splitter-0.02
It's not too bad to use Perl either, especially with the Perl Packager. Given only one host with the full Cygwin Perl install, you can create compiled executables that encapsulate everything you need down to a single file. It rocks!
http://search.cpan.org/~autrijus/PAR-0.85/scrip
I imagine though that you'd eventually want to only analyze random chunks that contain speech, or at least speech like frequency distributions. This is trickier, and I don't know if there's Perl code to do it. Maybe you could investigate Praat's internal scripting language?
http://www.fon.hum.uva.nl/praat/
Praat is pretty mind-bogglingly cool -- it's worth checking out no matter what.
--Dan
P.S. Yes, I've been working on some mildly related stuff. How could you tell?
The problem with that is that it wouldn't be a really good social experiment because the person would either forget to press the button or only press the button when there was something that they wanted to record. Maybe what you could do is install a special "privacy button" where if they were on the phone and telling the person something personal (like there SSN) they could hit the button and it would mute the mike. However, I'd still be nervous to include such a thing because I think it would still skew the output.
Personally how I'd tackle the problem is with something like mp3split and some scripting.
You'd drop a "whole" mp3 into a directory and have a job that would take the file and chunk out 10 minute segements and then glue them into one 240 minute mp3.
Though I'm not sure what's less elegant, recording tons of data just to throw 5/6th of it away or going to Rat shack and buying a 555, a couple of resisters, a switch and a battery harness and modifying the player.
Yes Francis, the world has gone crazy.
> (for Windows)?."you don't want to do that
A flip answer but correct in the sense that this is simply a problem of calculation. You don't need any GUI or any fancy interface. I suggest, since you are at a school anyway, that you swing by the computer science department and get some senior to do this for his independent study project. All it needs to do is take the input sound file and put out the random samples. Requirements: 1. the input file, 2. parameters for how often and for how long to randomly sample (could be in a text file) and 3. the output file. No Windows, (MS, X, or other), required. Heck, it could be a DOS program (depending on the input file sizes).
Even with the interframe bit reservoir you only need to pull out a maximum of 9 frames to have playable audio.
Regards,
Steve
#!/bin/bash
for i in $(seq n)000
do
- mpg123 -w out$i.wav -k $i -n f source_filename.mp3
doneWhere n is the number of MP3 frames to skip, in thousands, f is the number of frames to extract per iteration, and source_filename.mp3 is your MP3 file. For a 128kbps MP3, if you wish to extract 30s of audio for roughly every 10 minutes, you would use n=22 and f=1100. Output would be in files named out1000.wav, out2000.wav, and so on. Experimentation with the numbers is encouraged when using different bitrates. Please feel free to critique my bash code -- I am a little rusty.
Slashdot's first reaction to VMware
Why does this seem absurdly simple? Because it is. A proof of concept for this idea could be developed by even a moderately "okay" programmer in just about any language.
:)
Oddly enough, I speak from experience, being both an okay programmer, and having done almost exactly this in the past using perl. We were gathering 30 to 60 second samples of tracks off of audio CDs at different offsets (dependant upon the type of music) for online streaming. CDs came in one side of the process, were ripped, sampled, and converted to various formats.
One word of advice, deal with raw audio for the sampling process, I've always found it much easier to deal with, and it gives you a lot of options on the output side for reencoding.
Come to think of it, just grabbing 10 minute samples every hour on the purely electronics side wouldn't be difficult either, but you're more likely to be able to find someone who can write code rather than someone who can modify your recorders
Karma: 0 (But I wield a mean +10 Vorpal Apathy)
Agreed..
In any case I couldn't imagine that it'd take more than half a day or so to do this in Java or Python.
Or five minutes in Perl with MP3::Splitter:
Why is it hard to buy enough recorders? Simple. It's because they're using Pocket PCs running their custom software. It seems overly complicated for something that could be accomplished with a hardware recorder and later parsing via software. Why distribute a handful of expensive recorders when you can distribute many cheaper recorders? Academia confuses me sometimes - the objectives seem much less spectacular than the methods proposed to reach such objectives.
To see what I'm talking about, check out the newest model of their EAR at the bottom of the page.
The SoX utility is quite useful for scripted or automated mangling of audio files. While a dedicated MP3-splitting program would certainly work just fine, SoX has a "trim" command that cuts a certain section out of the file; "sox trim [randomstart] 00:00:30" would grab 30 seconds starting from whenever you want.
mpgedit (http://mpgedit.org/) is an mp3 frame cutter that can easily handle this job. The size of the input mp3 file does not matter, mpgedit can handle anything you throw at it. You want to use the command line interface in conjunction with something like Perl or Python to pick random edit times and lengths. There are also Python bindings you can call directly if you are programming in Python.
A brief command line example:
mpgedit -e39-44 -e111-137 -e222-244 huge.mp3
Will create huge_1.mp3 huge_2.mp3 and huge_3.mp3, 5, 26 and 22 seconds in length respectively.
The script you need to write will generate a command line similar to this example, generating random time offsets and segment lengths. You can determine the total input file play time by running "mpgedit huge.mp3" and parse the time from the "Track length:" field.
This is what you want:
mpgedit has a -e flag so you could do
mpgedit -e 1:20-1:30 -e 600:20-601:10 -f file.mp3
Would grab from 1 minute 20 seconds to 1 minute 30 seconds, and from minute 600, 20 seconds to minute 601, 10 seconds of file.mp3 into file_1.mp3 and file_2.mp3
I use it to cut the 2 hour mp3 of the bbc news hours into 5 minute chunks so my mp3 player will let me skip segments.
With a bit of scripting you could do random cuts of any size mp3.
It claims to work under windows, but I have not tested it there.
--
Zot O'Connor