5#include "AudioCodecs/CodecMP3Helix.h"
6#include "AudioDictionary.h"
7#include "AudioTools/AudioOutput.h"
8#include "AudioTools/AudioStreams.h"
9#include "AudioTools/AudioTypes.h"
10#include "NumberToText.h"
25 tts.registerCallback(
callback,
this);
30 decodedStream =
new audio_tools::EncodedAudioStream(&sink, &decoder);
36 tts.registerCallback(
callback,
this);
41 decodedStream =
new audio_tools::EncodedAudioStream(&sink, &decoder);
51 decodedStream =
new audio_tools::EncodedAudioStream(&sink, &decoder);
58 void say(
const char *word) {
59 if (word !=
nullptr) {
61 queue.push_back(word);
67 if (word !=
nullptr) {
68 queue.push_front(word);
74 for (
int j = 0; j <
size; j++) {
81 void say(
char *(&word)[N]) {
82 for (
int j = 0; j < N; j++) {
88 void say(audio_tools::Vector<const char *> words) {
89 for (
auto word : words) {
96 int size = queue.size();
98 const char *word = (*this)[0];
101 LOGI(
"say: %s (size: %d -> %d)", word,
size, queue.size());
103 if (queue.size() == 0) {
112 AudioStream *mp3Stream = p_dictionary->get(word);
113 if (mp3Stream !=
nullptr) {
119 copier.begin(*decodedStream, *mp3Stream);
125 LOGE(
"Word not available in dictionary: %s", word);
131 for (
int j = 0; j < n; j++) {
137 size_t size() {
return queue.size(); }
170 void delay(uint32_t delay_ms = 1000) {
171 uint8_t buffer[1024] = {0};
172 unsigned long timeout = millis() + delay_ms;
173 while (timeout > millis()) {
174 p_sink->write((
const uint8_t *)buffer, 1024);
180 Vector<const char *> queue;
183 audio_tools::AudioDecoder *p_decoder =
nullptr;
184 audio_tools::EncodedAudioStream *decodedStream =
nullptr;
188 audio_tools::StreamCopy copier;
189 Print *p_sink =
nullptr;
192 static void callback(audio_tools::Vector<const char *> words,
void *ref) {
Dictionary which provides a Stream of Audio for the indicated word.
Definition: SimpleTTSBase.h:49
Translates a number into englich words.
Definition: NumberToText.h:15
Common Functionality for TTS classes.
Definition: SimpleTTSBase.h:15
Audio output from text via the indicated audio sink. The text components need to be prerecorded and a...
Definition: TextToSpeechQueue.h:20
void silence(int n=1)
Sends silence to mp3 decoder for n secods.
Definition: TextToSpeechQueue.h:130
void delay(uint32_t delay_ms=1000)
writes silence for the indicated ms
Definition: TextToSpeechQueue.h:170
void say(const char *word)
a simple API to add a single c string to the queue
Definition: TextToSpeechQueue.h:58
void processWord(const char *word)
Output of word to audio sink.
Definition: TextToSpeechQueue.h:111
bool isEmpty()
Returns true if the queue is empty.
Definition: TextToSpeechQueue.h:140
void end()
Ends the processing and clears the queue.
Definition: TextToSpeechQueue.h:160
void say(char *(&word)[N])
Addds an array of c strings.
Definition: TextToSpeechQueue.h:81
TextToSpeechQueue(AudioStream &sink, AudioDecoder &decoder, AudioDictionaryBase &dict)
Default Constructor.
Definition: TextToSpeechQueue.h:46
static void callback(audio_tools::Vector< const char * > words, void *ref)
callback which adds the words to the queue
Definition: TextToSpeechQueue.h:192
void begin()
Opens the processing.
Definition: TextToSpeechQueue.h:154
TextToSpeechQueue(SimpleTTSBase &tts, AudioStream &sink, AudioDecoder &decoder, AudioDictionaryBase &dict)
TextToSpeech which support a SimpleTTSBase.
Definition: TextToSpeechQueue.h:23
void sayNow(const char *word)
Adds a word to the front.
Definition: TextToSpeechQueue.h:66
void clear()
Clears the queue.
Definition: TextToSpeechQueue.h:167
size_t size()
Returns the number of words to be spoken in the queue.
Definition: TextToSpeechQueue.h:137
void say(audio_tools::Vector< const char * > words)
a simple API to say multiple of the supported words
Definition: TextToSpeechQueue.h:88
const char * operator[](int n)
Determines the nth word in the queue.
Definition: TextToSpeechQueue.h:143
void say(const char *word[], int size)
Addds an array of c strings.
Definition: TextToSpeechQueue.h:73