Continuous audio sampling and continuous Classification in main.cpp file for Raspberry Pi 4

Hi @mdchestn,

It looks like the -32 error code comes from snd_pcm_readi() if there is a buffer overrun. That sounds like the audio buffer is filling up with data and not being used in a timely manner. My guess is that your sleep_for() functions are blocking the next run_classifier() (or run_classifier_continuous()) from being called), which results in the audio buffer overflowing.

I recommend finding a way to do without the single-thread sleeping or use multiple threads (where one performs continuous inference while the other monitors the inference output to perform whatever action you need).

Hope that helps!

Hi @shawn_edgeimpulse ,

We removed the timers and it performs longer now but it still crashes. I was wondering if our classifier wasn’t that accurate could we get the same issue? Our model runs like we want it to but it doesn’t predict yes and no as accurate as we would like.

Hi @mdchestn,

Does your code run without crashing if you remove the system and sleep_for calls? For example:

            yesholder=1;
            if(yesCount > 1 && yesCount%10==0){
                printf("yes multple of 10\r\n");
                // sleep_for(milliseconds(1000));
                // system("vlc file:///home/mdchestn/Desktop/example-standalone-inferencing-linux/49_MusicBoxHat_790.wav --play-and-exit");
                // sleep_for(milliseconds(1000));
                // system("vlc file:///home/mdchestn/Desktop/example-standalone-inferencing-linux/49_MusicBoxHat_790.wav --play-and-exit");
                // sleep_for(milliseconds(1000));
                // system("vlc file:///home/mdchestn/Desktop/example-standalone-inferencing-linux/49_MusicBoxHat_790.wav --play-and-exit");

                
            }
            else{
                printf("yes other\r\n");
                // sleep_for(milliseconds(1000));
                // system("vlc file:///home/mdchestn/Desktop/example-standalone-inferencing-linux/49_MusicBoxHat_790.wav --play-and-exit");
            }
            
        } 
        if( result.classification[ix].label == "no" && result.classification[ix].value >=.5){
            noCount=noCount+1;
            noholder=1;
            if(noCount > 1 && noCount%10==0){
                printf("no multiple of 10\r\n");
                // sleep_for(milliseconds(1000));
                // system("vlc file:///home/mdchestn/Desktop/example-standalone-inferencing-linux/150_Upsweep_05_641.wav --play-and-exit");
                // sleep_for(milliseconds(1000));
                // system("vlc file:///home/mdchestn/Desktop/example-standalone-inferencing-linux/150_Upsweep_05_641.wav --play-and-exit");
                // sleep_for(milliseconds(1000));
                // system("vlc file:///home/mdchestn/Desktop/example-standalone-inferencing-linux/150_Upsweep_05_641.wav --play-and-exit");
            }
            else{
                printf("no other\r\n");
                    // sleep_for(milliseconds(1000));
                    // system("vlc file:///home/mdchestn/Desktop/example-standalone-inferencing-linux/150_Upsweep_05_641.wav --play-and-exit");

            }
        } 
        
        if((yesholder == 1) || (noholder == 1)){
            printf("%s: %.05f", result.classification[ix].label, result.classification[ix].value);
            if (ix != EI_CLASSIFIER_LABEL_COUNT - 1) {
                printf(", ");
            }  
        }

What kind of accuracy do you see with your test dataset? How is it behaving differently in deployment? What accuracy are you hoping for?

Hi @shawn_edgeimpulse ,

We believe we improved the model by going with the dataset that was available, this increased our yes, no, unknown, and noise data to about 19 minutes each, that improved the model. And yes it runs if I comment out the system() as well.

Hi @mdchestn,

Glad to hear it works. It sounds like the system() call is blocking, so you may want to make any calls within that function non-blocking. For example, by adding a & at the end of the call to fork a new task.

system("vlc file:///home/mdchestn/Desktop/example-standalone-inferencing-linux/49_MusicBoxHat_790.wav --play-and-exit &");

You’ll also want to avoid sleeping your main thread (i.e. the thread that performs sampling and inference).

Where did you get your dataset from? Is it just the Google Speech Commands Dataset, or did you augment it in any way?

1 Like

Hi @shawn_edgeimpulse,

We didn’t augment the dataset in anyway and we used the one that came with the edge impulse tutorial. We use yes, no, noise, and unknown.

Hi @mdchestn,

That dataset is a decent starting point, but I found it does not provide very accurate results when used in a real-world environment. I highly recommend augmenting the dataset (e.g. with samples from your own voice or others). I have a Colab script to help you do that here: https://github.com/ShawnHymel/ei-keyword-spotting