Issue with audio.h in esp32

Good point. I was aware that he is using ESP32-audioI2S but thought it depends on an audio library. But it does not and comes with its own Audio.h. Thanks.

Thank you So much, Max.
It is worked.
I really appreciated your help.
My question now is, how did you know that I need to add this library and not the one that Platform IO recommended here: PlatformIO Registry

Thank you
Iman

The article you’ve linked to contains a direct link to the library (GitHub - schreibfaul1/ESP32-audioI2S: Play mp3 files from SD via I2S). So we must make absolutely sure that code from the repo is used. The only question is whether this library is in the PIO library repository (–> we can refer to it with its library name and owner) or not (we must provide a direct downlink to the repo). In the library, there is a library.properties that declares the library’s name as

And the search results for that is empty. Thus we have to go the direct-link route. Using the documentation we then find the correct syntax for adding a library throgh its download link – whereas the downlink link is taken form the Github website’s “Code → Download zip” button.

You can also see that when you follow any of these libraries which you found by just searching for Audio.h link to an entirely different repository (“Repository” link) and thus are the wrong ones.

1 Like

Thank you for the clarification.

@imanpakii did you get this working? I’m getting this error.

I’m running the latest PlatformIO
platformio.ini

[env:m5stack-core-esp32]

platform = espressif32

board = m5stack-core-esp32
framework = arduino
upload_speed = 115200
monitor_speed = 115200
lib_deps =
ESP32-audioI2S-master=https://github.com/schreibfaul1/ESP32-audioI2S/archive/master.zip

.pio/libdeps/m5stack-core-esp32/ESP32-audioI2S-master/src/Audio.cpp: In constructor ‘Audio::Audio(uint8_t, uint8_t, uint8_t)’:
.pio/libdeps/m5stack-core-esp32/ESP32-audioI2S-master/src/Audio.cpp:134:17: error: ‘class WiFiClientSecure’ has no member named ‘setInsecure’
clientsecure.setInsecure(); // if that can’t be resolved update to ESP32 Arduino version 1.0.5-rc05 or higher
^
Compiling .pio/build/m5stack-core-esp32/FrameworkArduino/MD5Builder.cpp.o
*** [.pio/build/m5stack-core-esp32/lib7bf/ESP32-audioI2S-master/Audio.cpp.o] Error 1

The latest released stable version of Arduino-ESP32, that PlatformIO uses, is 1.0.4.

The problem is that

you’re taking the master-version of the library which might be written against not yet released release-candidates. However sadly this library also has no tags / versioning, so you would have to go back in the commit history to get a version that works against 1.0.4, which might be cumbersome.

The other option is to just upgrade the Arduino-ESP32 core to bleeding-edge master. That can be done as seen in Arduino Espressif ESP32 - #2 by maxgerhardt.

1 Like

I’m not sure what changed recently, for some reason I’m starting to get build errors. This was working before.
I’m running PlatformIO v2.2.1

platformio.ini

[env:audio]
platform = espressif32
board = featheresp32
framework = arduino
platform_packages =
framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#master
upload_port = /dev/cu.usbserial-0001
upload_speed = 115200
monitor_speed = 115200

lib_deps =
  ESP32-audioI2S-master=https://github.com/schreibfaul1/ESP32-audioI2S/archive/master.zip
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/featheresp32.html
PLATFORM: Espressif 32 (3.1.0) > Adafruit ESP32 Feather
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 0.0.0+sha.6f23cd5 
 - tool-esptoolpy 1.30000.201119 (3.0.0) 
 - toolchain-xtensa32 2.50200.97 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 29 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <ESP32-audioI2S-master> 2.0.0+sha.783f67c
|   |-- <FFat> 1.0
|   |   |-- <FS> 1.0
|   |-- <FS> 1.0
|   |-- <SD(esp32)> 1.0.5
|   |   |-- <FS> 1.0
|   |   |-- <SPI> 1.0
|   |-- <SD_MMC> 1.0
|   |   |-- <FS> 1.0
|   |-- <SPI> 1.0
|   |-- <SPIFFS> 1.0
|   |   |-- <FS> 1.0
|   |-- <WiFiClientSecure> 1.0
|   |   |-- <WiFi> 1.0
|-- <FS> 1.0
|-- <SD(esp32)> 1.0.5
|   |-- <FS> 1.0
|   |-- <SPI> 1.0
|-- <WiFi> 1.0
Building in release mode
Compiling .pio/build/audio/src/main.cpp.o
Archiving .pio/build/audio/lib13f/libWiFi.a
src/main.cpp:16:1: error: 'Audio' does not name a type
 Audio audio;
 ^
src/main.cpp: In function 'void setup()':
src/main.cpp:24:5: error: 'audio' was not declared in this scope
     audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
     ^
src/main.cpp: In function 'void loop()':
src/main.cpp:31:5: error: 'audio' was not declared in this scope
     audio.loop();
     ^
Indexing .pio/build/audio/lib13f/libWiFi.a
Archiving .pio/build/audio/lib301/libWiFiClientSecure.a
Indexing .pio/build/audio/lib301/libWiFiClientSecure.a
Compiling .pio/build/audio/lib401/ESP32-audioI2S-master/Audio.cpp.o
Compiling .pio/build/audio/lib401/ESP32-audioI2S-master/aac_decoder/aac_decoder.cpp.o
Compiling .pio/build/audio/lib401/ESP32-audioI2S-master/flac_decoder/flac_decoder.cpp.o
Compiling .pio/build/audio/lib401/ESP32-audioI2S-master/mp3_decoder/mp3_decoder.cpp.o
Archiving .pio/build/audio/libFrameworkArduinoVariant.a
Indexing .pio/build/audio/libFrameworkArduinoVariant.a
Compiling .pio/build/audio/FrameworkArduino/Esp.cpp.o
Compiling .pio/build/audio/FrameworkArduino/FunctionalInterrupt.cpp.o
Compiling .pio/build/audio/FrameworkArduino/HardwareSerial.cpp.o
*** [.pio/build/audio/src/main.cpp.o] Error 1
Compiling .pio/build/audio/FrameworkArduino/IPAddress.cpp.o
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp: In member function 'int Audio::read_M4A_Header(uint8_t*, size_t)':
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp:1439:18: warning: variable 'atomName' set but not used [-Wunused-but-set-variable]
             char atomName[5];
                  ^
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp:1522:80: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'uint32_t {aka unsigned int}' [-Wformat=]
             sprintf(chbuf, "Sampling Frequency: %lu",samplingFrequencies[sRate]);
                                                                                ^
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp:1522:80: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'uint32_t {aka unsigned int}' [-Wformat=]
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp:1485:21: warning: unused variable 'len_of_OD' [-Wunused-variable]
             uint8_t len_of_OD  = *(pos + 12); // length of this OD (which includes the next 2 tags)
                     ^
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp:1486:21: warning: unused variable 'len_of_ESD' [-Wunused-variable]
             uint8_t len_of_ESD = *(pos + 20); // length of this Elementary Stream Descriptor
                     ^
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp:1532:21: warning: unused variable 'dependsOnCoreCoder' [-Wunused-variable]
             uint8_t dependsOnCoreCoder  = (ASC & 0x02);
                     ^
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp:1533:21: warning: unused variable 'extensionFlag' [-Wunused-variable]
             uint8_t extensionFlag       = (ASC & 0x01);
                     ^
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp: In member function 'int Audio::read_OGG_Header(uint8_t*, size_t)':
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp:1622:19: warning: variable 'headerSize' set but not used [-Wunused-but-set-variable]
     static size_t headerSize;
                   ^
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp:1624:19: warning: variable 'f_lastMetaBlock' set but not used [-Wunused-but-set-variable]
     static bool   f_lastMetaBlock;
                   ^
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp: In member function 'bool Audio::playSample(int16_t*)':
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp:3301:13: warning: unused variable 'sample1' [-Wunused-variable]
     int16_t sample1[2]; int16_t* s1;
             ^
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp:3301:34: warning: unused variable 's1' [-Wunused-variable]
     int16_t sample1[2]; int16_t* s1;
                                  ^
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp:3302:34: warning: unused variable 's2' [-Wunused-variable]
     int16_t sample2[2]; int16_t* s2 = sample2;
                                  ^
.pio/libdeps/audio/ESP32-audioI2S-master/src/Audio.cpp:3303:34: warning: unused variable 's3' [-Wunused-variable]
     int16_t sample3[2]; int16_t* s3 = sample3;
                                  ^

Weird, it can’t find the Audio type defined in Audio.h.

You don’t have any other header files in the project which define the AUDIO_H_ macro yes?

No, I don’t. It’s very weird, it just started giving that error yesterday, I see there was an update in master branch yesterday.

I have no problems compiling the current master branch and the I2SAudio.ino example verbatim as main.cpp with the platformio.ini

[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps = 
  https://github.com/schreibfaul1/ESP32-audioI2S.git
Dependency Graph
|-- <ESP32-audioI2S-master> 2.0.0+sha.783f67c
|   |-- <FFat> 1.0
|   |   |-- <FS> 1.0
|   |-- <FS> 1.0
|   |-- <SD(esp32)> 1.0.5
|   |   |-- <FS> 1.0
|   |   |-- <SPI> 1.0
|   |-- <SD_MMC> 1.0
|   |   |-- <FS> 1.0
|   |-- <SPI> 1.0
|   |-- <SPIFFS> 1.0
|   |   |-- <FS> 1.0
|   |-- <WiFiClientSecure> 1.0
|   |   |-- <WiFi> 1.0
|-- <FS> 1.0
|-- <SD(esp32)> 1.0.5
|   |-- <FS> 1.0
|   |-- <SPI> 1.0
|-- <SPI> 1.0
|-- <WiFi> 1.0
Building in release mode
[..]
Linking .pio\build\esp32\firmware.elf
Building .pio\build\esp32\firmware.bin
Retrieving maximum program size .pio\build\esp32\firmware.elf
Checking size .pio\build\esp32\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  15.5% (used 50876 bytes from 327680 bytes)
Flash: [========  ]  84.3% (used 1104917 bytes from 1310720 bytes)
esptool.py v3.0
============================ [SUCCESS] Took 18.76 seconds ============================

Maybe try and remove the .pio folder of the project to get a clean version of the library again.

Weird, deleted .pio, still same errors, this was working before :frowning:

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/featheresp32.html
PLATFORM: Espressif 32 (3.1.0) > Adafruit ESP32 Feather
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 3.10005.210308 (1.0.5) 
 - tool-esptoolpy 1.30000.201119 (3.0.0) 
 - toolchain-xtensa32 2.50200.97 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Library Manager: Installing git+https://github.com/schreibfaul1/ESP32-audioI2S
git version 2.23.0
Cloning into '/Users/jeff/.platformio/.cache/tmp/pkg-installing-hg0212bv'...
Library Manager: ESP32-audioI2S-master @ 2.0.0+sha.783f67c has been installed!
Found 29 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <ESP32-audioI2S-master> 2.0.0+sha.783f67c
|   |-- <FFat> 1.0
|   |   |-- <FS> 1.0
|   |-- <FS> 1.0
|   |-- <SD(esp32)> 1.0.5
|   |   |-- <FS> 1.0
|   |   |-- <SPI> 1.0
|   |-- <SD_MMC> 1.0
|   |   |-- <FS> 1.0
|   |-- <SPI> 1.0
|   |-- <SPIFFS> 1.0
|   |   |-- <FS> 1.0
|   |-- <WiFiClientSecure> 1.0
|   |   |-- <WiFi> 1.0
|-- <FS> 1.0
|-- <SD(esp32)> 1.0.5
|   |-- <FS> 1.0
|   |-- <SPI> 1.0
|-- <WiFi> 1.0
Building in release mode
Compiling .pio/build/audio/src/main.cpp.o
Generating partitions .pio/build/audio/partitions.bin
Compiling .pio/build/audio/lib991/FS/FS.cpp.o
Compiling .pio/build/audio/lib991/FS/vfs_api.cpp.o
Compiling .pio/build/audio/lib9da/FFat/FFat.cpp.o
Compiling .pio/build/audio/libf85/SPI/SPI.cpp.o
Compiling .pio/build/audio/libfea/SD/SD.cpp.o
Compiling .pio/build/audio/libfea/SD/sd_diskio.cpp.o
Compiling .pio/build/audio/libfea/SD/sd_diskio_crc.c.o
Compiling .pio/build/audio/lib4d4/SD_MMC/SD_MMC.cpp.o
src/main.cpp:16:1: error: 'Audio' does not name a type
 Audio audio;
 ^
src/main.cpp: In function 'void setup()':
src/main.cpp:24:5: error: 'audio' was not declared in this scope
     audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
     ^
src/main.cpp: In function 'void loop()':
src/main.cpp:31:5: error: 'audio' was not declared in this scope
     audio.loop();
     ^
Compiling .pio/build/audio/lib058/SPIFFS/SPIFFS.cpp.o
Compiling .pio/build/audio/lib889/WiFi/ETH.cpp.o
*** [.pio/build/audio/src/main.cpp.o] Error 1

Full main.cpp code?

Also, you can point back at specific commits of the library if that’s what caused the problem, in #<commit> form at the end of the .git link in the platformio.ini.

This is the one that used to work… in VSCode, it’s showing Audio as ‘Audio’ does not name a type. Not sure why it is not able to see Audio.

#include <Arduino.h>
#include "WiFi.h"
#include "Audio.h"
#include "SD.h"
#include "FS.h"

// Digital I/O used
#define SD_CS          5
#define SPI_MOSI      23
#define SPI_MISO      19
#define SPI_SCK       18
#define I2S_DOUT      25
#define I2S_BCLK      27
#define I2S_LRC       26

Audio audio;

void setup() {
pinMode(SD_CS, OUTPUT);
digitalWrite(SD_CS, HIGH);
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
Serial.begin(115200);
SD.begin(SD_CS);
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(10); // 0...21
audio.connecttoFS(SD, "Ensoniq-ZR-76-01-Dope-77.wav");
}

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

// optional
void audio_info(const char *info){
Serial.print("info        "); Serial.println(info);
}
void audio_id3data(const char *info){  //id3 metadata
Serial.print("id3data     ");Serial.println(info);
}
void audio_eof_mp3(const char *info){  //end of file
Serial.print("eof_mp3     ");Serial.println(info);
}
void audio_showstation(const char *info){
Serial.print("station     ");Serial.println(info);
}
void audio_showstreaminfo(const char *info){
Serial.print("streaminfo  ");Serial.println(info);
}
void audio_showstreamtitle(const char *info){
Serial.print("streamtitle ");Serial.println(info);
}
void audio_bitrate(const char *info){
Serial.print("bitrate     ");Serial.println(info);
}
void audio_commercial(const char *info){  //duration in sec
Serial.print("commercial  ");Serial.println(info);
}
void audio_icyurl(const char *info){  //homepage
Serial.print("icyurl      ");Serial.println(info);
}
void audio_lasthost(const char *info){  //stream URL played
Serial.print("lasthost    ");Serial.println(info);
}
void audio_eof_speech(const char *info){
Serial.print("eof_speech  ");Serial.println(info);
}

Then something else must be supplying Audio.h. Can you show the VSCode file explorer where all folders are expanded, and the full platformio.ini?

Try renaming your src/audio.h file to something else.

oh my goodness, dah!, that was a sample audio file got put there by mistake. Thanks for your help.

I’m actually trying to store the audio in SPIFF that I got from https://texttospeech.googleapis.com/v1/text:synthesize. And play the audio by reading from SPIFF. I’m struggling to save the file in the correct format so it can be playback, any suggestion?

Some predetermined audio file thaht you place in the SPIFFS? Per example

you should be store the audio in either MP3, AAC or FLAC format (see decoders in library source) in the SPIFFSa and use code above, while changing SD to SPIFFS of course, and .begin()-ing it before. Simply creating a folder called data, putting the file in there and using the ‘Upload File System Image’ will put it on the ESP, as documented. Careful however that you do not surpass the SPIFFS partiion limit as defined by the partition table (or change it otherwise).

Why make it two-stage? The Audio API already has the code to fetch and play it, no itermediate storage required.

I’m just exploring how I can store short sentence response I got from https://texttospeech.googleapis.com/v1/text:synthesize such as saving it as mp3 encoded or decoded. But when I tried to read from SPIFFS and play the audio, nothing gets played.

obj = JSON.parse(payload);
mp3Value = obj["audioContent"];
char buffer[sizeof(mp3Value)];
memcpy(buffer, &mp3Value, sizeof(mp3Value));
unsigned char * decoded = base64_decode((const unsigned char *)buffer, sizeof(buffer), &outputLength);
Serial.println(buffer);

// file.println(mp3Value);
file.write((uint8_t *)decoded, sizeof(decoded));
file.close();