ESP32 Audio library example error

hello, I'm a mechanical engineer student and I don't have much experinces about cpp software. I need to make a text to speech software and I found it from github but eventhoug I didn't change anything, code didn't work. I saw people did manage to work it somehow. Error message was about Audio library. Then I tried to run libraries example which its name is "Simple Audio Player". but again it failed.

code is:

/*
  Simple Audio Player

 Demonstrates the use of the Audio library for the Arduino Due

 Hardware required :
 * Arduino shield with a SD card on CS4
 * A sound file named "test.wav" in the root directory of the SD card
 * An audio amplifier to connect to the DAC0 and ground
 * A speaker to connect to the audio amplifier

 Original by Massimo Banzi September 20, 2012
 Modified by Scott Fitzgerald October 19, 2012
 Modified by Arturo Guadalupi December 18, 2015

 This example code is in the public domain

 http://www.arduino.cc/en/Tutorial/SimpleAudioPlayer

*/

#include <SD.h>
#include <SPI.h>
#include <Audio.h>

void setup() {
  // debug output at 9600 baud
  Serial.begin(9600);

  // setup SD-card
  Serial.print("Initializing SD card...");
  if (!SD.begin(4)) {
    Serial.println(" failed!");
    while(true);
  }
  Serial.println(" done.");
  // hi-speed SPI transfers

  // 44100 Hz stereo => 88200 Hz sample rate
  // 100 mSec of prebuffering.
}

void loop() {
  int count = 0;

  // open wave file from SD card
  File myFile = SD.open("test.wav");
  Audio.begin(88200, 100); 
  if (!myFile) {
    // if the file didn't open, print an error and stop
    Serial.println("error opening test.wav");
    while (true);
  }

  const int S = 1024; // Number of samples to read in block
  short buffer[S];

  Serial.print("Playing");
  // until the file is finished
  while (myFile.available()) {
    // read from the file into buffer
    //myFile.read(buffer, sizeof(buffer));

    // Prepare samples
    int volume = 1024;
    Audio.prepare(buffer, S, volume);
    // Feed samples to audio
    Audio.write(buffer, S);

    // Every 100 blocks print a '.'
    count++;
    if (count == 100) {
      Serial.print(".");
      count = 0;
    }
  }
  myFile.close();
  Audio.end();
  Serial.println("End of file. Thank you for listening!");
  while (true) ;
}

And Error is:

WARNING: library Audio claims to run on sam architecture(s) and may be incompatible with your current board which runs on esp32 architecture(s).
In file included from c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/Audio.h:16,
                 from C:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\examples\SimpleAudioPlayer\SimpleAudioPlayer.ino:24:
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h:21:15: error: expected ')' before '*' token
  DACClass(Dacc *_dac, uint32_t _dacId, IRQn_Type _isrId) :
          ~    ^~
               )
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h:35:2: error: 'Dacc' does not name a type
  Dacc *dac;
  ^~~~
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h:37:2: error: 'IRQn_Type' does not name a type
  IRQn_Type isrId;
  ^~~~~~~~~
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h: In member function 'void DACClass::enableInterrupts()':
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h:31:44: error: 'isrId' was not declared in this scope
  void enableInterrupts()  { NVIC_EnableIRQ(isrId); };
                                            ^~~~~
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h:31:29: error: 'NVIC_EnableIRQ' was not declared in this scope
  void enableInterrupts()  { NVIC_EnableIRQ(isrId); };
                             ^~~~~~~~~~~~~~
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h: In member function 'void DACClass::disableInterrupts()':
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h:32:45: error: 'isrId' was not declared in this scope
  void disableInterrupts() { NVIC_DisableIRQ(isrId); };
                                             ^~~~~
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h:32:29: error: 'NVIC_DisableIRQ' was not declared in this scope
  void disableInterrupts() { NVIC_DisableIRQ(isrId); };
                             ^~~~~~~~~~~~~~~
In file included from C:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\examples\SimpleAudioPlayer\SimpleAudioPlayer.ino:24:
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/Audio.h: In member function 'virtual size_t AudioClass::write(uint8_t)':
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/Audio.h:25:82: warning: no return statement in function returning non-void [-Wreturn-type]
  virtual size_t write(uint8_t c)                         { /* not implemented */ };
                                                                                  ^
Multiple libraries were found for "SD.h"
  Used: C:\Users\abdul\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\libraries\SD
  Not used: C:\Users\abdul\AppData\Local\Arduino15\libraries\SD
  Not used: C:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\SD
exit status 1

Compilation error: exit status 1

On the page that you linked to it says

This tutorial demonstrates how to use an Arduino board (Arduino Zero, MKRZero or MKR1000 WiFi) to play a wave file stored on an SD card

Your board has an an ESP32. Can you see a problem ?

actually I didn't connect my card. just verified the code for testing (with esp 32 dev module) . after your comment I tried Arduino MKR zero and got same error. I guess its about audio library installation but I'm not sure. I reinstalled all library

I give another example for error

#include "Arduino.h"
#include "WiFi.h"
#include "Audio.h"

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

Audio audio;


void setup()
{

  Serial.begin(115200);

  WiFi.disconnect();
  WiFi.mode(WIFI_STA);
  WiFi.begin( "SSID", "PASSWORD");

  while (WiFi.status() != WL_CONNECTED)
    delay(1500);

  audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
  audio.setVolume(100);
  audio.connecttospeech("Hello", "en"); // Google TTS
}


void loop()

{

  audio.loop();

}

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

And the error is:

WARNING: library Audio claims to run on sam architecture(s) and may be incompatible with your current board which runs on esp32 architecture(s).
In file included from c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/Audio.h:16:0,
                 from C:\Users\abdul\AppData\Local\Temp\.arduinoIDE-unsaved2024225-19224-1onp0lu.2tiz\sketch_mar25a\sketch_mar25a.ino:3:
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h:21:16: error: expected ')' before '*' token
  DACClass(Dacc *_dac, uint32_t _dacId, IRQn_Type _isrId) :
                ^
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h:35:2: error: 'Dacc' does not name a type
  Dacc *dac;
  ^
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h:37:2: error: 'IRQn_Type' does not name a type
  IRQn_Type isrId;
  ^
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h: In member function 'void DACClass::enableInterrupts()':
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h:31:44: error: 'isrId' was not declared in this scope
  void enableInterrupts()  { NVIC_EnableIRQ(isrId); };
                                            ^
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h:31:49: error: 'NVIC_EnableIRQ' was not declared in this scope
  void enableInterrupts()  { NVIC_EnableIRQ(isrId); };
                                                 ^
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h: In member function 'void DACClass::disableInterrupts()':
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h:32:45: error: 'isrId' was not declared in this scope
  void disableInterrupts() { NVIC_DisableIRQ(isrId); };
                                             ^
c:\Users\abdul\OneDrive\Belgeler\Arduino\libraries\Audio\src/DAC.h:32:50: error: 'NVIC_DisableIRQ' was not declared in this scope
  void disableInterrupts() { NVIC_DisableIRQ(isrId); };
                                                  ^
C:\Users\abdul\AppData\Local\Temp\.arduinoIDE-unsaved2024225-19224-1onp0lu.2tiz\sketch_mar25a\sketch_mar25a.ino: At global scope:
C:\Users\abdul\AppData\Local\Temp\.arduinoIDE-unsaved2024225-19224-1onp0lu.2tiz\sketch_mar25a\sketch_mar25a.ino:9:1: error: 'Audio' does not name a type
 Audio audio;
 ^
C:\Users\abdul\AppData\Local\Temp\.arduinoIDE-unsaved2024225-19224-1onp0lu.2tiz\sketch_mar25a\sketch_mar25a.ino: In function 'void setup()':
C:\Users\abdul\AppData\Local\Temp\.arduinoIDE-unsaved2024225-19224-1onp0lu.2tiz\sketch_mar25a\sketch_mar25a.ino:24:3: error: 'audio' was not declared in this scope
   audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
   ^
C:\Users\abdul\AppData\Local\Temp\.arduinoIDE-unsaved2024225-19224-1onp0lu.2tiz\sketch_mar25a\sketch_mar25a.ino: In function 'void loop()':
C:\Users\abdul\AppData\Local\Temp\.arduinoIDE-unsaved2024225-19224-1onp0lu.2tiz\sketch_mar25a\sketch_mar25a.ino:34:3: error: 'audio' was not declared in this scope
   audio.loop();
   ^

exit status 1

Compilation error: 'Audio' does not name a type

For those interested, I solved the problem.
What I did was I removed the Arduino ide completely and uploaded the code by platform ide. Done. I don't know why, I might have installed the library wrong somehow.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.