ESP32-CAM play audio files

Hi,
since several weeks I try to make a sketch to play a audio file on an ESP32-CAM.
The hardware consits of

  1. an ESP32-CAM
  2. a speaker
  3. a Interface I2S PCM5102 DAC Decoder GY-PCM5102

It seems to be very complicated to make such a script.
Has anybode experience in creating such a solution?
Thanks a lot in advance.

Please post a schematic of your project and your best effort at paying a sound file. Describe what problems that you have had

@UKHeliBob ,
thanks a lot for your answer.
This is my configuration.
This means I use the I2S interface on the ESP32-CAM to the PCM5102 board.

I got a example but it doesn't work (compiling errors)

#include "driver/i2s.h"

// DAC-Konfiguration
#define I2S_DOUT_PIN 25
#define I2S_NUM I2S_NUM_0
#define I2S_SAMPLE_RATE 44100
#define I2S_CHANNEL_NUM 2
#define I2S_BITS_PER_SAMPLE 16
#define I2S_DMA_BUF_COUNT 6
#define I2S_DMA_BUF_LEN 60

void app_main()
{
    // Config the DAC
    i2s_config_t i2s_config = {
        .mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_TX),
        .sample_rate = I2S_SAMPLE_RATE,
        .bits_per_sample = i2s_bits_per_sample_t(I2S_BITS_PER_SAMPLE),
        .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
        .communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
        .dma_buf_count = I2S_DMA_BUF_COUNT,
        .dma_buf_len = I2S_DMA_BUF_LEN,
        .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1
   };
    i2s_pin_config_t pin_config = {
        .bck_io_num = -1,
        .ws_io_num = I2S_PIN_NO_CHANGE,
        .data_out_num = I2S_DOUT_PIN,
        .data_in_num = I2S_PIN_NO_CHANGE
    };
    i2s_driver_install(I2S_NUM, &i2s_config, 0, NULL);
    i2s_set_pin(I2S_NUM, &pin_config);

    // open the PCM-file for reading
    FILE* pcm_file = fopen("audio.pcm", "rb");
    if (!pcm_file) {
        printf("PCM-Dfile could not be opend\n");
        return;
    }

    // Playing the PCM-Data
    char data[I2S_DMA_BUF_LEN * 2];
    while (true) {
        size_t read_len = fread(data, 1, sizeof(data), pcm_file);
        if (read_len <= 0) {
            break;
        }
       i2s_write_bytes(I2S_NUM, data, read_len, portMAX_DELAY);
    }

    // Close the PCMFile
    fclose(pcm_file);

    // Deinitialize the DAC
    i2s_driver_uninstall(I2S_NUM);
}

The errors repoted are:

C:\Users\Kurt\Documents\Arduino\ESP32-CAM-Audio\ESP32-CAM-Audio.ino: In function 'void app_main()':
C:\Users\Kurt\Documents\Arduino\ESP32-CAM-Audio\ESP32-CAM-Audio.ino:24:4: error: designator order for field 'i2s_driver_config_t::intr_alloc_flags' does not match declaration order in 'i2s_config_t' {aka 'i2s_driver_config_t'}
    };
    ^
C:\Users\Kurt\Documents\Arduino\ESP32-CAM-Audio\ESP32-CAM-Audio.ino:48:8: error: 'i2s_write_bytes' was not declared in this scope
        i2s_write_bytes(I2S_NUM, data, read_len, portMAX_DELAY);
        ^~~~~~~~~~~~~~~
C:\Users\Kurt\Documents\Arduino\ESP32-CAM-Audio\ESP32-CAM-Audio.ino:48:8: note: suggested alternative: 'i2s_write_expand'
        i2s_write_bytes(I2S_NUM, data, read_len, portMAX_DELAY);
        ^~~~~~~~~~~~~~~
        i2s_write_expand

exit status 1

Compilation error: designator order for field 'i2s_driver_config_t::intr_alloc_flags' does not match declaration order in 'i2s_config_t' {aka 'i2s_driver_config_t'}

Thats what I did up to now.
Thanks for any help!

Hi,
I think I didn't quite understand some things.
I have now written a script for the ESP32-CAM, which compiled without errors.
That can supposedly also output a sound.
Now I want to test the whole thing and I still need to know which pins can be used on the ESP32-CAM board.
It's a bit unclear to me which pins on the ESP32-CAM board have which function.


I use a PCM1502 DAC to connect a digital output.
Some pins are already occupied by the camera and the SD card reader.
I know that I have to connect the DAC to the 3.3V. The ground is also clear.

Which pins can I use?
Does anyone have any experience?
Thanks in advance!

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