Skip to content

Commit 9037a8f

Browse files
committed
new delay method
1 parent 2254c1a commit 9037a8f

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

examples/audio-analog/audio-analog.ino

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ void increment() {
4242

4343
void loop() {
4444
// speach output
45-
out.begin();
4645
utt.say(number, "usd");
47-
delay(200);
48-
out.end(); // closing to avoid disturbing noise
4946

5047
increment();
51-
delay(1000);
48+
// we continue to write empty audio to avoid noise
49+
tts.delay(200);
5250
}

src/TextToSpeech.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class TextToSpeech {
2929
p_tts = &tts;
3030
p_dictionary = &dict;
3131
p_decoder = &decoder;
32+
p_sink = &sink;
3233
decodedStream = new audio_tools::EncodedAudioStream(&sink, &decoder);
3334
begin();
3435
}
@@ -39,6 +40,7 @@ class TextToSpeech {
3940
p_tts = &tts;
4041
p_dictionary = &dict;
4142
p_decoder = &decoder;
43+
p_sink = &sink;
4244
decodedStream = new audio_tools::EncodedAudioStream(&sink, &decoder);
4345
begin();
4446
}
@@ -48,6 +50,7 @@ class TextToSpeech {
4850
AudioDictionaryBase &dict) {
4951
p_dictionary = &dict;
5052
p_decoder = &decoder;
53+
p_sink = &sink;
5154
decodedStream = new audio_tools::EncodedAudioStream(&sink, &decoder);
5255
begin();
5356
}
@@ -90,14 +93,24 @@ class TextToSpeech {
9093
end();
9194
}
9295

96+
/// writes silence for the indicated ms
97+
void delay(uint32_t delay_ms){
98+
uint8_t buffer[1024] = {0};
99+
unsigned long timeout = millis()+delay_ms;
100+
while(timeout>millis()){
101+
p_sink->write((const uint8_t*)buffer,1024);
102+
}
103+
}
104+
93105
protected:
94106
bool active = false;
95107
NumberToText ntt;
96108
audio_tools::AudioDecoder *p_decoder = nullptr;
97109
audio_tools::EncodedAudioStream *decodedStream = nullptr; // Decoding stream
98-
SimpleTTSBase *p_tts = nullptr; // Text source
110+
SimpleTTSBase *p_tts = nullptr; // Text source
99111
AudioDictionaryBase *p_dictionary = nullptr; // Dictionary to access audio data
100-
audio_tools::StreamCopy copier; // copy in to out
112+
audio_tools::StreamCopy copier; // copy in to out
113+
Print *p_sink=nullptr;
101114

102115
/// callback which says the words
103116
static void callback(audio_tools::Vector<const char *> words, void* ref) {

0 commit comments

Comments
 (0)