Output .wav files to amp/8Ohm speaker?

Hello, I was thinking of a use case of performing an audio classification model on the TinyML board, and then depending on that inference, playing an audio file (from the SD card) on an 8 Ohm speaker. Is this possible on the TinyML board? I was planning on using Edge Impulse to create and deploy the model to an Arduino sketch, and I have compiled the sample Edge Impulse code/sketch. However, I’ve had trouble integrating a library to play audio (I’ve had success with TRMpcm with an Arduino uno). The audio libraries I’ve tried also bring up SD code issues as well.

Not sure if this is even possible with the TinyML board. Figured I would reach out to the forum before I spend too much time.
Are there any sample sketches anywhere of using the SD card? I’ve only seen the low power example sketch on this forum.

Thanks!

Hi Justin

This is a great idea. As you are aware that TinyML is based on Arduino MKR Zero. However, small subset of pins are brought out. Please review if these pins can generate audio signal or not. The data can be saved easily on uSD card, the same way as it can saved on Arduino MKR Zero board using SDFat library. I will reachout to you and give you some sample code.

Thanks. I’m pretty sure I just need a DAC pin (A0) on the MKR Zero. Other challenge is finding an audio library that is compatible. Thanks again. Looking forward to the sample sketches.

Please see following repo

This is using the same libraries which is shown in the low power repo by R. D. Poor.
The sketch creates a file, writes data and then reads it and displays it.

Thank you. Atul sent me some code as well, and I was able to get audio outputted on pin 5 to a speaker. Below is the code using the AudioZero library. However, I’m now trying to run it in the Edge Impulse firmware, and it hangs when a keyword is detected. Here is the code:

void on_classification_changed(const char *event, float confidence, float anomaly_score) {

    if (strcmp(event, "breathe") == 0) {
        // Toggle LED
        digitalWrite(LED_RED, HIGH);
        Serial.println("Playing breathe!");
        myFile1 = SD.open("breathe2.wav", FILE_READ);
        AudioZero.begin(22050);
        AudioZero.play(myFile1);
        AudioZero.end();
        myFile1.close();
    }

    if (strcmp(event, "talk") == 0) {
        // Toggle LED
        digitalWrite(LED_GREEN, HIGH);
        Serial.println("Playing talk!");
        myFile1 = SD.open(talk, FILE_READ);
        AudioZero.begin(22050);
        AudioZero.play(myFile1);
        AudioZero.end();
        myFile1.close();
    }
}

The model that I created works pretty well, and the keyword spotting is solid. Is there a mutex or a block on the SD card while inference is running? Is it a timing thing in syntiant_loop()? Any help would be appreciated. I feel like I am almost there!

Thanks to the @Atul’s guidance and the simple inference sketch, I was able to get the code to run. My project write up can be found here: May the (TinyML) Force Be With You! - Hackster.io

Check it out!