Running the classification-audio.js code on the edge impulse linux cli

I ran the edge-impulse-linux-runner command and I wanted a way to customize the output and so I found this classification-audio.js example on the github repo

However there is no README on how to run the file. Kindly help

Hi @eskay,

  1. Install edge-impulse-linux normally: npm install edge-impulse-linux -g --unsafe-perm
  2. Get the classify-audio.js file locally on your computer/linux device
  3. Change the top line of the file to: const { AudioClassifier, LinuxImpulseRunner, AudioRecorder } = require("edge-impulse-linux");
  4. Make sure you have SoX installed/in your path somewhere on your device, for example on my mac: export PATH=$PATH:~/sox-14.4.2/
  5. Download your model file from your Edge Impulse project/account with: edge-impulse-linux-runner --download modelfile.eim
  6. Run the script with: node classify-audio.js modelfile.eim

If you see the following output, then you need to also clarify which microphone you want to use:

➜  node classify-audio.js modelfile.eim
Starting the audio classifier for Jenny Plunkett / Glass Breaking - Acoustic Anomaly Detection (v12)
Parameters freq 16000Hz window length 1000ms. classes [ 'background', 'glassbreak' ]
Error: Multiple microphones found ("MacBook Pro Microph", "MacBook Pro Speaker", "Virtual Desktop Mic", "Virtual Desktop Spe", "ZoomAudioDevice"), add the microphone to use to this script (node classify-audio.js model.eim microphone)
    at /Users/jenny/Local/portenta/classify-audio.js:29:19

Run the script and select a microphone, successful output looks something like this:

➜  node classify-audio.js modelfile.eim "MacBook Pro Microph"
Starting the audio classifier for Jenny Plunkett / Glass Breaking - Acoustic Anomaly Detection (v12)
Parameters freq 16000Hz window length 1000ms. classes [ 'background', 'glassbreak' ]
classification 1ms. { background: '0.0000', glassbreak: '1.0000' }
classification 0ms. { background: '0.0000', glassbreak: '1.0000' }
classification 0ms. { background: '0.0000', glassbreak: '1.0000' }
classification 1ms. { background: '0.0000', glassbreak: '1.0000' }
classification 0ms. { background: '0.0001', glassbreak: '0.9999' }
classification 0ms. { background: '0.0000', glassbreak: '1.0000' }

Hope this helps! I will add these to the README.

Thank you!
Jenny

2 Likes

Thank you very much. It worked!

1 Like

Additional question. I am uploading the classification results to MongoDB but the classifier is too fast. Is there a way I can slow it down so that I upload one classification at a time?