Arduino build error

fatal error: Audio.h: No such file or directory

Audio.h is not part of Arduino itself. Sketches that play web radio or MP3 on an ESP32 include it from the ESP32-audioI2S library.

  • Build error
  • 2 common causes
The message

What the Arduino IDE prints

Output window
sketch.ino:1:10: fatal error: Audio.h: No such file or directory
    1 | #include <Audio.h>
      |          ^~~~~~~~~~
compilation terminated.
exit status 1

The library has to be installed, and the board has to be an ESP32.

Mokxi's compiler, clang, words it as 'Audio.h' file not found.

Causes

The 2 usual causes with the fix

1The board is not an ESP32

The library plays audio through the ESP32 I2S port, so it needs an ESP32. Mokxi builds the sketch but does not play sound: the connect calls return false and say so on the serial monitor.

Broken
#include "Audio.h"

Audio audio;

void setup() {
  Serial.begin(9600);
}

void loop() {
}
Fixed
#include "Audio.h"

#define I2S_DOUT 25
#define I2S_BCLK 27
#define I2S_LRC 26

Audio audio;

void setup() {
  Serial.begin(115200);
  audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
  audio.setVolume(12);
  if (!audio.connecttohost("http://stream.example.com/radio.mp3")) {
    Serial.println("could not start the stream");
  }
}

void loop() {
  audio.loop();
}

void audio_info(const char *info) {
  Serial.print("info        ");
  Serial.println(info);
}

Mokxi’s build tab says: Pick an ESP32 board

Try this fix in Mokxi

2The ESP32-audioI2S library is not installed

Install it once in the Arduino IDE. Do not confuse it with the Audio library for the Arduino Due, which has the same header name.

  1. Open Sketch, Include Library, Manage Libraries, and search for ESP32-audioI2S.
  2. Install the one by schreibfaul1, or download it from GitHub and add it as a ZIP library.
  3. Choose an ESP32 board under Tools, Board, then compile again.
FAQ

Questions and answers

Is Audio.h part of Arduino?

No. For ESP32 sketches it comes from the ESP32-audioI2S library. The Arduino Due has a different Audio library with the same header name.

Does audio play in Mokxi?

No. There is no MP3 decoder and no I2S DAC that plays a stream, so the sketch builds and its other parts run, and the connect calls return false.

What hardware does it need?

An ESP32 and an I2S DAC board, such as a MAX98357 amplifier, on the pins you pass to setPinout.