# Output .wav files to amp/8Ohm speaker?

**URL:** <https://discourse.syntiant.com/t/output-wav-files-to-amp-8ohm-speaker/59>\
**Category:** TinyML Board\
**Created:** [July 27, 2022, 8:08pm UTC](https://discourse.syntiant.com/t/output-wav-files-to-amp-8ohm-speaker/59 "2022-07-27T20:08:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlutz](https://discourse.syntiant.com/letter_avatar_proxy/v4/letter/j/b19c9b/32.png) [@jlutz](https://discourse.syntiant.com/u/jlutz)\
**Post date:** [July 27, 2022, 8:08pm UTC](https://discourse.syntiant.com/t/output-wav-files-to-amp-8ohm-speaker/59/1 "2022-07-27T20:08:47Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![rajmund](https://discourse.syntiant.com/letter_avatar_proxy/v4/letter/r/cc9497/32.png) [@rajmund](https://discourse.syntiant.com/u/rajmund)\
**Post date:** [July 28, 2022, 7:59pm UTC](https://discourse.syntiant.com/t/output-wav-files-to-amp-8ohm-speaker/59/2 "2022-07-28T19:59:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jlutz](https://discourse.syntiant.com/letter_avatar_proxy/v4/letter/j/b19c9b/32.png) [@jlutz](https://discourse.syntiant.com/u/jlutz)\
**Post date:** [July 28, 2022, 8:42pm UTC](https://discourse.syntiant.com/t/output-wav-files-to-amp-8ohm-speaker/59/3 "2022-07-28T20:42:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AviAIML](https://discourse.syntiant.com/letter_avatar_proxy/v4/letter/a/ecd19e/32.png) [@AviAIML](https://discourse.syntiant.com/u/AviAIML)\
**Post date:** [August 2, 2022, 12:51am UTC](https://discourse.syntiant.com/t/output-wav-files-to-amp-8ohm-speaker/59/4 "2022-08-02T00:51:25Z")

</div>

Please see following repo

> **[GitHub - AviAIML/TinyMLmicroSD: This repository is to show how to read and...](https://github.com/AviAIML/TinyMLmicroSD)**
>
> This repository is to show how to read and write on Syntiant's TinyML board uSD card slot - GitHub - AviAIML/TinyMLmicroSD: This repository is to show how to read and write on Syntiant's Ti...

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.

---

<div class="post-metadata">

**Author:** ![jlutz](https://discourse.syntiant.com/letter_avatar_proxy/v4/letter/j/b19c9b/32.png) [@jlutz](https://discourse.syntiant.com/u/jlutz)\
**Post date:** [August 2, 2022, 2:55am UTC](https://discourse.syntiant.com/t/output-wav-files-to-amp-8ohm-speaker/59/5 "2022-08-02T02:55:11Z")

</div>

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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![jlutz](https://discourse.syntiant.com/letter_avatar_proxy/v4/letter/j/b19c9b/32.png) [@jlutz](https://discourse.syntiant.com/u/jlutz)\
**Post date:** [August 11, 2022, 12:54pm UTC](https://discourse.syntiant.com/t/output-wav-files-to-amp-8ohm-speaker/59/6 "2022-08-11T12:54:25Z")

</div>

Thanks to the @rajmund’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](https://www.hackster.io/justinelutz/may-the-tinyml-force-be-with-you-36865f)

Check it out!
