pschatzmann / arduino-espeak-ng

eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
GNU General Public License v3.0
26 stars 4 forks source link

Included WIFI exceeds the memory limits #7

Closed fenyvesi closed 1 year ago

fenyvesi commented 1 year ago

This is a really nice implementation.

I would like to use it to read loudly the error messages sent through MQTT.

The problem when I include just the WIFI connection, the dram0_0_seg overflowed by 12992 bytes.

Is there any potential work-around it?

Thank you.

Arduino v.1.8.19, ESP32 Core: v2.9, WIN10

c:/users/x/appdata/local/arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:\Users\x\AppData\Local\Temp\arduino_build_285595/reader.ino.elf section.dram0.bss' will not fit in region dram0_0_seg' c:/users/x/appdata/local/arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: DRAM segment data does not fit. c:/users/x/appdata/local/arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: DRAM segment data does not fit. c:/users/x/appdata/local/arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: regiondram0_0_seg' overflowed by 12992 bytes collect2.exe: error: ld returned 1 exit status `

pschatzmann commented 1 year ago

Did you compile with Partition Scheme Huge App?

fenyvesi commented 1 year ago

Yes.

pschatzmann commented 1 year ago

If you have processor with psram you can try to use psram https://www.pschatzmann.ch/home/2022/05/30/esp32-and-psram/

fenyvesi commented 1 year ago

Thank you, I look around maybe I have it. Coming back.

fenyvesi commented 1 year ago

I just got the ordered module with PSRAM and tried again in platformio. The problem is the same: :/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: region `dram0_0_seg' overflowed by 13104 bytes

I included the proposed heap_caps_malloc_extmem_enable() function but as it has effect only at runtime it has no benefit at compiling time.

Maybe I misunderstood you. The code:

`#define WIFI_EXIST

include

include "esp_heap_caps.h"

include "esp_system.h" //This inclusion configures the peripherals in the ESP system.

include "esp32-hal-psram.h"

//#include "esp_himem.h"

include "esp32/himem.h"

include "AudioTools.h" // https://github.com/pschatzmann/arduino-audio-tools

//#include "AudioLibs/AudioKit.h" // https://github.com/pschatzmann/arduino-audiokit

include "FileSystems.h" // https://github.com/pschatzmann/arduino-posix-fs

include "espeak.h"

//const int limit = 8192; const int limit = 4096; // the minimum I2SStream i2s; // or replace with AudioKitStream for AudioKit const bool load_english = false; ESpeak espeak(i2s, load_english);

void setup() { heap_caps_malloc_extmem_enable(limit); Serial.begin(115200); //Initialize serial ports for communication with the console Serial.println("Program started"); psramInit(); vTaskDelay(3); Serial.printf("Total heap: %u\r\n", ESP.getHeapSize()); Serial.printf("Free heap: %u\r\n", ESP.getFreeHeap()); Serial.printf("Total PSRAM: %u\r\n", ESP.getPsramSize()); Serial.printf("Free PSRAM: %d\r\n", ESP.getFreePsram());

// add foreign language configuration files espeak.add("/mem/data/hu_dict", espeak_ng_data_hu_dict,espeak_ng_data_hu_dict_len); // espeak.add("/mem/data/lang/de", espeak_ng_data_lang_gmw_de, espeak_ng_data_lang_gmw_de_len); espeak.add("/mem/data/lang/hu", espeak_ng_data_lang_urj_hu, espeak_ng_data_lang_urj_hu_len);

// setup espeak espeak.begin(); espeak.setVoice("hu");

// setup output auto espeak_info = espeak.audioInfo(); auto cfg = i2s.defaultConfig(); cfg.channels = espeak_info.channels; // 1 cfg.sample_rate = espeak_info.sample_rate; // 22050 cfg.bits_per_sample = espeak_info.bits_per_sample; // 16 i2s.begin(cfg);

ifdef WIFI_EXIST

WiFi.begin("AP_NAME", "AP_PASS");
while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

endif

} void loop() { espeak.say("Csöngettek!"); delay(1000); }

platformio.ini:

[platformio] description = Espeak-NG Example default_envs = esp32dev

[env:esp32dev] platform = https://github.com/platformio/platform-espressif32.git board = esp32dev framework = arduino lib_deps = https://github.com/pschatzmann/arduino-audio-tools https://github.com/pschatzmann/arduino-espeak-ng https://github.com/pschatzmann/arduino-posix-fs build_flags = -DCORE_DEBUG_LEVEL=5 -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-function -Wno-format-extra-args -DBOARD_HAS_PSRAM monitor_speed = 115200 monitor_filters = esp32_exception_decoder board_build.partitions = huge_app.csv`

pschatzmann commented 1 year ago

Hmm, If you must use Wifi, why don't you just do TTS via Wifi as well?. There are plenty of options and the quality could also be also much better.

https://www.pschatzmann.ch/home/2021/06/23/text-to-speach-in-arduino-conclusions/

fenyvesi commented 1 year ago

Yeah. I Have already made it on an all-day-working Debian server but it was so shocking that I could do it on a microcontroller that I was not able not to try it.

Thank you for yout patience. The whole audio package you made is magnificient.

pschatzmann commented 1 year ago

It should be possible to change some big arrays to be allocated dynamically.

Top 3 variables:

pschatzmann commented 1 year ago

You can try to activate the ESPEAK_HEAP_HACK and check if it is working with psram with the latest commit

fenyvesi commented 1 year ago

Really nice touch.

I used the last version and it works with MQTT messages. As I see ~80k is used from PSRAM. ( heap_caps_malloc_extmem_enable(4096);)

Thank you once more.

pschatzmann commented 1 year ago

I was just running a test with ESPEAK_HEAP_HACK 1, psram (heap_caps_malloc_extmem_enable(256);) and Wifi and it was working like a charm:

10:40:58.479 -> Total heap: 269996 10:40:58.479 -> Free heap: 183392 10:40:58.479 -> Total PSRAM: 4191915 10:40:58.479 -> Free PSRAM: 4122023

pschatzmann commented 1 year ago

https://github.com/pschatzmann/arduino-espeak-ng/wiki/Using-PSRAM

fenyvesi commented 1 year ago

It is useful for anybody who wants to use it. The usage of PSRAM can be problematic because of the common cache with the normal RAM.

Just a remark: as far as I remember the minimum and default allocation is 4096 in the heap_caps...().

This is a really useful tool. For example if you would like to know your debug messages but there is no serial connection, then you can listen to it. For blind people you can construct a web page reader and so on.

As the vast majority of the PSRAM is not used, there are real possibilities.