6#include "SimpleTTSBase.h"
11typedef File AudioFile;
14typedef File32 AudioFile;
15typedef SdFat32 AudioFat;
32 virtual bool begin(T &file) {
36 virtual bool begin()
override {
41 virtual void end()
override {
46 virtual size_t readBytes(uint8_t *buffer,
size_t length)
override {
47 return p_file->readBytes((
char *)buffer, length);
50 virtual size_t write(
const uint8_t *buffer,
size_t length)
override {
51 return p_file->write(buffer, length);
54 virtual int available()
override {
return p_file->available(); }
56 virtual int availableForWrite()
override {
57 return p_file->availableForWrite();
60 operator bool() {
return *p_file; }
78 this->cs_pin = cs_pin;
84 AudioStream *
get(
const char *word) {
87 const char *file_name = getFileWithPath(word);
88 if (SD.exists(file_name)) {
89 file = SD.open(file_name, FILE_READ);
90 fileWrapper.begin(file);
93 LOGE(
"File does not exist: %s", file_name);
99 audio_tools::StrExt url_with_text;
107 StrExt file_path{40};
108 bool is_setup =
false;
114 LOGI(
"Setup SD library");
115 if (!SD.begin(cs_pin)) {
116 LOGE(
"SD.begin failed for cs_pin: %d", cs_pin);
120 LOGI(
"Setup SdFat library");
122 SdSpiConfig(cs_pin, DEDICATED_SPI, SD_SCK_MHZ(SDFAT_SPEED)))) {
123 LOGE(
"SD.begin failed for cs_pin: %d", cs_pin);
127 if (!SD.exists(path)) {
128 LOGI(
"Creating directory: %s", path)
129 if (!SD.mkdir(path)) {
130 LOGE(
"Could not create directory: %s", path);
138 const char *getFileWithPath(
const char *name) {
144 file_path.toLowerCase();
145 const char *str = file_path.c_str();
146 LOGI(
"%s -> %s", name, str);
Dictionary which provides a Stream of Audio for the indicated word.
Definition: SimpleTTSBase.h:49
A dictionary which is based on files stored on an SD card. By default we use the SdFat library....
Definition: AudioDictionarySD.h:73
AudioStream * get(const char *word)
retrieves recorded audio file for the word
Definition: AudioDictionarySD.h:84
A simple Wrapper that let's a file pretend to be a AudioStream to support the begin and end methods.
Definition: AudioDictionarySD.h:29