ESP8266SAM
ESP8266SAM copied to clipboard
Speak example never stopping on ESP32
Similar to : https://github.com/earlephilhower/ESP8266Audio/pull/473
On ESP32, after playing a SAM voice it never stop to say the last sound. To find out this you have to modify a little the default example by replacing the delay(); with something not blocking.
Here the example to verify this little bug on ESP32 (and a quick/dirty solution in comments) :
#include <Arduino.h>
#include <ESP8266SAM.h>
#include <AudioOutputI2S.h>
unsigned long previousMillis = 0; // will store last time sam voice was played
const long interval = 5000; // inerval between the repeats
AudioOutputI2S *out = NULL;
void setup()
{
out = new AudioOutputI2S();
out->begin();
}
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
ESP8266SAM *sam = new ESP8266SAM;
sam->Say(out, "Bonjour");
delete sam;
// quick fix to avoird infinite repeat on ESP32 :
//out->stop();
}
}
I hesitated to create this issue in ESP8266audio library but I think that the out->stop(); could be added at line 87 of ESP8266SAM.cpp. Need expert opinion to confirm 😉
I have found that on the ESP32, I often need to finish each sentance with a SPACE (or a full-stop, or a comma) for example
"sam->Say(out, "Hello ");
and this stops the sound at word/sentance end.
BUT, I still also occasionally get and issue on the ESP32 if the battery is getting low, that the above command is repeatedly started but never finished (as if the ESP32 was crashing, but it isn't, and instead the "Say(" function seems to be crashing part way through and repeating, giving me: "Hel" "Hel" "Hel" "Hel" until the ESP32 is rebooted (or runs out of power). I haven't found a way of identifying or fixing this yet (other than recharging the battery!) (Although this MIGHT be the "Adafruit MAX98357A i2s 3W amplifier" which is crashing/looping?)