Skip to content

AudioSpeech pitch / rate problem #80

Description

@vcchm

First thanks for theis great piece of software.
I am using this with an ESP32C3, and the pitch / speech rate is much too fast to be understood.
Code I use is folloiwing and even reducing rate to the minimum it is still too fast

#include <BackgroundAudioSpeech.h>
#include <ESP32PDMAudio.h>
#include <libespeak-ng/voice/fr.h>

#define GPIO_BUZZER GPIO_NUM_10

ESP32PDMAudio audio(GPIO_BUZZER);
BackgroundAudioSpeech BMP(audio);

void setup() {
  BMP.setVoice(voice_fr);
  BMP.setRate(1); // Words per minute
  BMP.setPitch(2);  // 50 = normal pitch
  BMP.begin();
}

uint32_t last = 0;
void loop() {
  if (millis() - last > 5500) {
    BMP.flush(); // Stop any existing output, reset for new file
    BMP.speak("Ceci est un essai");
  }
}

Any idea how I can slow this down ? I tried to look if I could downscale the speed but it is not obvious. I suppose the chip frequency (160 Mhz) is too high but I need ti keep a fast CPU...

Activity

  1. earlephilhower commented on Oct 13, 2025

    @earlephilhower
    Owner

    PDM audio has(had?) a bug in the IDF where the clock rate they set the HW was too high, but I thought I accounted for that in

    // TODO - There is some fixed off-by-ratio 1/1.25 in the PDM output clock vs. the PCM input data at IDF 5.5
    freq *= 8;
    freq /= 10;

    As a sanity test, are you able to get the proper speeds output when running another example like BeepWAV modified for PDM?

    Also, what exact version of pioarduino and IDF are you running?

  2. vcchm commented on Oct 14, 2025

    @vcchm
    Author

    Hello !

    Playing a mp3 works fine using PDM (the volume is very low, but pitch is fine).
    I am using idf 4 (esp32c3). So i should tune freq to slow wpm rate ?

    V

  3. earlephilhower commented on Oct 14, 2025

    @earlephilhower
    Owner

    The volume out from the PDM device is just a function of the HW itself. It's just throwing out fewer transitions than you'd expect. Use the setGain method to amplify the raw digital data.

    IDF4 is very old. https://github.com/espressif/arduino-esp32 is on 5.5, and has been on 5.x for over a year. I'd recommend updating if you're really on that old a version (not just for this, but for all the other bug fixes they've been doing!).

    That said, I'll give it a test later today on the 3.3.1 core (5.5+ IDF) and see if I can repro the problem. Since you see it only in eSpeak, that narrows things down a lot!

    One other possibility is that the PDM HW for some reason doesn't support the lower sample rate eSpeak data. eSpeak generates at a fixed at 22khz, while most MP3s are running 44.1 or 48k. We'll see...

  4. Meshwa428 commented on Oct 14, 2025

    @Meshwa428

    You can take a look at #81 i tried to fix it for IDF v5.5.1.250929 and I have tested it for my ESP32 S3, the pitch and speed is perfect.

    The problem occurs because we are not taking the hardware clock rate into account. Which led the hardware to consume sample faster than they should.
    We can instruct it to use a stable clock rate by letting I2S run as a DAC.

  5. added a commit that references this issue on Oct 14, 2025
    a80bab8
  6. earlephilhower commented on Oct 14, 2025

    @earlephilhower
    Owner

    #81 looks like a good change, but it wasn't the root problem here. I reproduced @vcchm 's failure on an ESP32C3 and tracked it down to the sample rate change being lost before startup. So the audio for speech is playes back at 2x the rate it is generated for, because the setFrequency(22050) got lost. #82 fixes that.

    I still think #81 is a good change, since it removes the "magic numbers" I reversed out, though!

  7. added a commit that references this issue on Oct 14, 2025
    3886c51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions