Listener

 

Listener is a Python script I wrote because noise cancellation headphones prevented me from responding to calls of attention from family members. The result was a Python script that enabled my to use my microphone to listen to the outside world. I then used a bash script to poll and then used GeekTool to throw this output on my desktop. You can obtain the scripts below.

The Theoretical Stuff:


In case you wonder how this works, it will simply suffice to know that Listener just records audio to a waveform file which encodes the intensity of incoming electromagnetic wave as a number between -128 and 127 (8 bit waveforms are sufficient for this script).


Once this number is obtained, a simple operation is performed to obtain the intensity in decibels and the resulting value is analyzed to check how close it is to normal intensities.


55 dB is the normal intensity for  a conversation at a 1 meter distance between two people. Hit something higher than that and you probably have someone demanding your attention / the phone ringing and so on (if you are in a different room, you probably won’t have any luck). In a classroom environment, this is not the best tool to use. But hey, why the hell are you using noise-cancellation headsets in a class where you want your ears to sample all audio?


You can subsequently use GeekTool to throw the output to the screen. Basically running the repeat BASH script will result in the output of this being thrown into /var/log/audio.tmp

You can get GeekTool to use it.


Skype Behavior:


Currently Listener makes use of an applescript to check if the user is engaged in a call on Skype. During a call, the mic keeps receiving input at a decent intensity and keeps printing out to file. This is not what we want and as a result, operations are stopped while the call is taking place. This is probably a very crude hack but hey, it works for me.



Screenshots on my machine:











































What you need to use Listener:


You need to grab PyAudio from http://people.csail.mit.edu/hubert/pyaudio/

You also need to install numpy.



Downloads:


The Python listener script: http://shriphani.com/scripts/audio_analysis.py

The shell script to poll the above script: http://shriphani.com/scripts/repeat.sh

The Applescript file needed to detect skype’s call status: http://shriphani.com/scripts/skypeChecker.scpt


You place them all in the same directory and then you can run Listener by running the command:


> sh repeat.sh



Please beware, listener is not a serious project and was only written to satisfy my problems in a computing environment that is unique. No official support / assistance is offered in getting this app to work.


Questions go to shriphani_at_shriphani.com


All code offered under the MIT license. All the code here is (c) Shriphani Palakodety 2009. Don’t mess with my copyright.