Create custom script using edge impulse model

Question/Issue:
I am trying to create a custom python code which can record .wav files on a raspberry pi using a usb microphone and also run the edge impulse model on the .wav files to look for outliers/anomalies. I am currently able to run the model in the raspberry pi terminal using the terminal, but i now want to integrate the audio recording code and edge impulse model together in the same python script. Is this possible, and does someone have a suggestion on how to achieve this?

Context/Use case:
I have created a sound anomaly detection model using a classification learning block with 2 categories: anomaly and non-anomaly. This model needs to run on a raspberry pi which records sounds with a usb microphone. The model needs to detect anomalies in the recorded sound files.

Hello @nijo0312,

This example classifies audio using an external microphone and should be a good starting point: linux-sdk-python/classify.py at master · edgeimpulse/linux-sdk-python · GitHub

Best,

Louis

1 Like

Thanks for replying!

The example is a excellent start code. The only downside I have found is that the code stops running when the microphone does not receive any input (complete silence). Do you have an idea on how to fix it?

File “/home/pi/.local/lib/python3.9/site-packages/edge_impulse_linux/audio.py”, line 101, in fill_buffer
raise Exception(‘There is no audio data comming from the audio interface’)
Exception: There is no audio data comming from the audio interface

I haven’t tried but I guess you can just comment out the exception:

2 Likes

I’m still working on this project and I have encountered a new problem. I am trying to create a .wav file from the audio that is going into the ML model. I like to try to put that data into a list and convert that list into a .wav file using the wave package. The problem is that i cannot find the right variable in the audio.py script that contains the raw audio data.

I was trying to use the audio variable of the classifier function, but that seems to corrupt the .wav file (probably because the audio flow is not constant, but devided in chunks (im not sure…)). Does anyone know a solution?