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
I work for an acoustics company and we use either matlab or CoolEdit pro to analyze waveforms. Given the size of your data, it could be difficult though. Probably would want to break down the input into hour segments.
Might want to check with an acoustics lab.
Try http://www.ee.sunysb.edu/~cspv/CSPV.html or something similar.
100% Insightful
Pick up Microsoft Visual C++ then look at their time and sound librar.. uh.. oh.. IT colour scheme hurt brain... cannot continue.. blarerhfdsl jjjjjjjjjjjjjj fjwkef
Ask P-Diddy.
He frequently samples other artists' work and then makes millions. Reminds me of an archived Onion article, which you now must pay for
Click here for a free picture of an iPod!
Sounds like a job for a really simple shell script driving mp3split. Sounds a lot easier than a custom chip!
If I was a participant in this research I think I would be more concerned with my privacy if they were physically recording everything and then just 'randomly sampling' what they needed later. Having the trigger physically on the player seems much more reassurring. But hey, maybe I'm just paranoid.
Download the MP3 Module, RTFM and do it!
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.
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)
10 a = rand number
20 b = a + 30 seconds
30 open MP3 with appropriate sound API, get sound between a and b
40 save a and b to a table so you don't use those values again
50 goto 10
Why does this seem absurdly simple to me? I think just about any modern language with a decent set of libraries will be able to handle this, if there isn't a shareware app out there already. 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.
Doesn't this void your privacy requirements you previously mentioned. I understand you want to grab short samples after the fact, but you'll still have access to all the continous data to begin with.
"Look Lois, the two symbols of the Republican Party: an elephant, and a fat white guy who is threatened by change."
This is the sort of application that screams for a script, rather than some sort of drag-n-drool GUI windows-ish thing. There are several audio sampling and processing utilities over at sourceforge.net, which would be suitable for this sort of thing.
Maybe it's because my background is in the *nix world, but it'd be a half-day project to get this up and running done on a *nix box with something free from sourceforge.
Usually one wants to design the solution to fit the problem, not to introduce more complexity by limiting what the solution can be chosen from. Doesn't seem to be the case in this guy's project. I also can't imagine finding audio sampled snippets of someone's day all that interesting, but I'm sure there are people who enjoy that sort of thing?
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.").
IIRC, a MP3 file is made up of frames which contain the sound data in its entirity. You should be able to just cut a block anywhere in the middle, say any 20 second piece and expect at elast 18 seconds of continous sound. Too lazy to script it.
If you set things up properly (namely limiting the use of the interframe bit reservoir), then there are many utilities which will allow you to pull out specific frames from within an MP3 file. This should both be much faster from a processing standpoint, and not incur more data loss from two encodings.
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."
If they're desperate enough to use your program, they don't have to "40 save a and b to a table". The odds that they'll get the same random number again are lower than the probability that they'll use the program ;).
--
make install -not war
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 OP said as much
compare, for example, to the latest (federal) medical privacy rules, www.hhs.gov/ocr/hipaa/
[this sig has been trunca
You ask a person to carry an 18 hour voice recorder... I'm just curious what batteries you use.
dd if=(my mp3) of=(sample file) bs=(mp3 frame size, or size of "one second" of audio) skip=(start from) count=(duration)
There you go. Write some script to make up the values in parentheses.
On to tackle the next great engineering mystery of computer science. Maybe I'll solve some of those NP-complete problems, or install one of those really sweet case fans that light up when the music plays!
I don't need no instructions to know how to rock!!!!
Then why did they reject my story on how to pop up a dialog box in Windows?
Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
> (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).
The recordings exist. Just because you will somehow post process them, I don't think you have really met your standard of not recording the whole day.
Would you submit them under subpeona? Will they be destroyed? When? How?
I think anybody in the CS dept could write the program you require. But I am pretty sure you are going to have to keep coming up with a way to do this "pre-record". And exactly why is it so hard to just buy *enough* recorders?
This is an excellent research field. I may convert section of my recombinant lab to this study. I will urge the head of Oncoproteomics department to do the same thing and cut budget to other projects for this.
I suggest you read Slashdot
Problem solved. Next!
Just ask the RIAA. They've got some great software for taking an MP3, extracting bits of the file, and replacing the rest with (loud) white noise. Should be perfect for your needs.
I don't understand why he'd need to change the hardware every six months. Sure, there are new MP3 players, but as long as they've implemented on a model that is sufficient for their work, who cares whether there are newer models out (other than that old models will get cheaper, which is nice).
And the idea of recording an entire day and sampling seems terrible in terms of both privacy and efficiency. If you can record a day's samples in a $75 MP3 flash-based player plus a tiny circuit that randomly presses the record button twice every so often, why bother using a $400 hard-drive based MP3 player, recording an entire day, then copying that day to a desktop computer, then sampling out random tiny bits of the day.
Enable 3D printed prosthetics!
This sounds like a great opportunity for an undergrad student. Most undergrads CS/EE at top universities, etc. would have been able to write this as a freshman in high school. As an undergrad myself, I've been employed at an acoustics lab writing scripts in matlab, C, PHP, etc. to do this sort of thing. Cheap labor, exellent results. They'd love to work for references and beer money and can develop custom idiot-proof software. Just post a flyer or post to the CS newsgroup.
To solve your problem(s) here are a few suggestions.
You are at University.
Is there a music lab?
Is there a Computer Science dept?
Is there an electronics dept?
If you can answer yes to 3 of these question most of your problems can solve themselves.
Talk to the Deans of those departments, explain your needs and suggest that the students in these depts may participate in the construction of what you need for their labs or projects.
I'm sure you would have students banging down the door to work on a project.
My point is, use what you have available.
I read a few posts down that someone "couldn't handle, dropped out of college because of professors like this". Well to me this sounds like a lesson with a deeper meaning than just some sort of useless project.
Perhaps it is an effort to show how even the simplest of experiments present difficult logistical problems.
I am Bennett Haselton! I am Bennett Haselton!
To be honest, if I were involved in something unsavory that day, I wouldn't return their recording device.
LK
"Hi. This is my friend, Jack Shit, and you don't know him." - Lord Kano
#!/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
He is a professor of social psychology not a software developer - give him a break. For an average developer this would be a very simple task - a few days at the most for a simple command line tool or sparse GUI app (Algorithm would be quite simple and all modern languages would support the features you need). You could look for an online forum where developers bid on projects like this for extra money. Usually these sites (Somebody post one I can't remember any of them now but a google search might help you) are very low cost solutions for simple one-off applications like you need. But, since you are part of a University I would contact the CS or IT department and see if there are any Undergrads who would like a small project to make some extra money and/or put on their resume. This would also help solve the problem of setting up your computer to make sure the code works properly (minor configurations would be necessary). Hope all goes well...
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.
James Pennebaker and I developed the method at the University of Texas at Austin at the end of the last century.
Oh you mean FOUR YEARS AGO? Bunghole.
Bad management trumps ideology - Show the world you want better leadership. http://www.timefornewmanagement.com
Use small Windows-based devices and don't give it any further thought. The OS will crash at random (you don't have to pay extra for this, it does it out of the box), thereby giving you the fragmented recordings you seek.
On the other hand, you could do it with an embedded linux device too; the frequent battery changes will have the desirable effect.
Okay I confess I wrote this post to confuse the moderators into inaction; he's bashing windows -- no, he's bashing linux -- oh FUCK what to do...
The correct moderation, gentle mod point merchant, is `funny'.
Blearf. Blearf, I say.
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.
Not to mention that surrepticious electronic recording is a felony in many states(ask Linda Tripp). You may want to contact your law dept. as well as your CS dept. However, I suspect that what you are really studying is slashdot social behaviour and your post is just a ruse to elicit responses. Forget it, we're on to you.
You can't run Open Source code on Windoze without destroying the American way of life!, pinko
It's a sort of 'if there's nobody in the forest, the sound was never heard' type of solution.
Free Software: Like love, it grows best when given away.
>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).
Almost every recorder has a noise/voice activation mode and most of the ones I've used had a mic or line-in as well. So just have an external mic -> custom chip that cuts it off when needed -> recorder. I suppose you could crack open the player and get between the internal mic if you wanted to as well. Either way the custom bit will never go obsolete. I record lectures I go to and found quality is much better with a good external mic anyway, even if it's a pocket size one like the small Sony conference mics.
$5 / month hosted VPS on linux = awesome!
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.
I've built a simple Java app that parses through an mp3 file and can do exactly this. You feed it three parameters... the begin time, the duration, and a filename and it outputs the request.
I originally did this for a *large* organization which had a huge number of sound recordings and they wanted specific cuts and already had the offsets and durations.
Drop me an email for details.
Since you want to analyze ambient sound, should'nt you be using a lossless codec instead of MP3 ?
:wq
I'm not sure that your proposed solution fits with your previously-mentioned privacy concerns. Sure, you'll only see a given part, but you're still recording the whole thing.
It'd be like having the FBI record your calls 24/7, but only listen to them if something came up, or having police be able to raid your house the moment they suspected you, but not look at what they gathered without a warrant. Even if they were completely honest in carrying it out, it's still too Big Brother-ish.
I think that, if the requirements say you can only record brief snippets, then you can only record brief snippets; not record everything and only listen to brief snippets. While it's the same from your perspective, it's not the same in terms of what's actually happening, and it sounds like it's completely bypassing your privacy concerns.
If you're already designing an external microchip, why not design a whole little recorder?
________________________________________________
suwain_2
Basically what you want to do is some time compression. You can do that by means of granulation or a FFT. Most audio applications already have time compression/expansion plugins built in to them. Sound Forge, Pro Tools Free, Live and Cool Edit are some of the commercial programs that come to mind. You could also build a stand alone program fairly easily with Csound, Max/MSP or Pure Data. These are audio programming/scripting languages. Csound and Pure Data are free. You just need to know a little about digital audio to make a program with any of those languages.
I can't find anything on his web page about it, but Greg Abowd, a professor at Georgia Tech has been working on continuous capture. He has some pda/cell phone software that his group has been working on which allows for continuous capture of audio. He also knows a lot about the laws regarding such recording. Not all states/provinces allow it, but many do.
I think his goals are more along the lines of automating segmentation and indexing of the audio for easy searching of your entire last day/week/year/decade of conversations with people.
Anyway, you might be interested in the kinds of things he's doing. But actually picking out random snippets of mp3 audio should be a trivial coding task. I'm sure there have already been a dozen libraries/scripting tools/command-line solutions proposed already in previous posts.
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
...because I'd be really annoyed that my taxes were being spent keeping this "professor" in his work-avoidance program.
Gentoo Linux - another day, another USE flag.