Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I saw this yesterday and run this script all night:

while true; do sox -t .wav "|arecord -d 1" -n stat 2> /tmp/tmp; echo -n `date +"%Y%m%d%H%M%S"` " "; cat /tmp/tmp | grep "Maximum amplitude" | cut -d ":" -f 2 | tr -d '\n'; cat /tmp/tmp | grep "Midline amplitude" | cut -d ":" -f 2 | tr -d '\n'; cat /tmp/tmp | grep "Rough *frequency" | cut -d ":" -f 2; done

and got this: http://i.imgur.com/oD6ZKIg.png?1

Interesting things: When my neighbor walks in his apartment above mine, it creates a amp peak with low frequency.

I have no idea what are those approx. one hour long periodic variations in the frequency, maybe my computer's fan or me snoring.

Anyway, pretty useless...



I look at that command line and feel amazed at what you can do with a command prompt. These are the two things that strike me as incredible:

* You didn't write a single line of code (well technically you did write one), nor researched about sound APIs or any kind of sound analysis algorithms or theory.

* You used several tools that just seamlessly shared their inputs and outputs and each one worked as supposed.

Granted, you need to know some bash and figure out how every utility works and the right command line switches to use, but still, pretty impressive.


This is the advantage of living at the command prompt. If you're mostly working through GUI (or CUI) interfaces that hide those details it can be somewhat convenient in the short run but you trap yourself: the effort needed when you want to do something complex that requires that knowledge is now suddenly much greater, because first you need to learn how to talk to each of the components of that pipeline before fitting them all together. I'll still need to check a man-page or two for less familiar functionality or a less familiar utility, but that's much better than checking five (the number of commands in the above pipeline that are passed at least one switch) and that's assuming you know which commands you'll want to be using in the first place.


Two things to note, though: 1) the script as given doesn't actually generate graphical output, just a text file; 2) something like Quartz Composer would be perfect for doing this with a GUI.


I have used Automator before (I think this is what you refer to) and also graphical programming languages as LabVIEW (not for scripting, of course ;) and I still feel very constrained when compared to using a command line or writing a script. I feel that the gain in simplicity comes at the expense of flexibility: when chaining program blocks/elements together you are constrained to what the original designers of the language thought were the most common use cases.


You need to do less thinking and more listening, friend. When I say Quartz Composer, I mean Quartz Composer.


Regarding 1), the plotting is also done with a (gnuplot) script.


Nice line, but you don't actually need all those separate greps and cats. You can do:

while true; do sox -t .wav "|arecord -d 1" -n stat 2> /tmp/tmp; echo -n $( date +%Y%m%d%H%M%S ); grep -e "Maximum amplitude" -e "Midline amplitude" -e "Rough *frequency" /tmp/tmp | cut -d ":" -f 2 | tr -d "\n"; echo; done

Shortening a line like this reminds me of a discussion on a forum about picking a random movie to play. It started off with loops and scripts of all kinds, and eventually ended with "shuf" :)


That looks rathe cool! Do you know by chance what it takes to get something like this running on a Mac?


sox and arecord, or equivalents, it looks like...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: