Skip to content

Commit baf8e0f

Browse files
committed
AudioDictionaryURL
1 parent 41b062b commit baf8e0f

File tree

4 files changed

+63
-8
lines changed

4 files changed

+63
-8
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Arduino Simple TTS
22

33
Microcontrollers do not have enough resources to provide a high quality Text to Speech functionality.
4-
However often it might be good enough just to provide a solution which is based on some pre-recorded audio.
4+
However, often it might be good enough to provide a solution which is based on some pre-recorded audio.
55

66
I was wondering about the limitations of this approach and decided to implement a small prototype Arduino library
7-
which is based on the [Arduino Audio Tools](https://github.com/pschatzmann/arduino-audio-tools) for the audio output.
7+
that is based on the [Arduino Audio Tools](https://github.com/pschatzmann/arduino-audio-tools) for the audio output.
88

9-
To keep things simple I decided to start with a simple implementation that can process numbers and on top of that another one which
9+
To keep things simple I started with a simple implementation that can process numbers and on top of that another one which
1010
reads out the time. So the starting point are some classes that tranlate numbers to test.
1111

1212
This functionality can be used e.g. to build some
@@ -122,5 +122,5 @@ I think this leave plenty of headroom and you still have the option to store the
122122

123123
## Documentation
124124

125-
Here is the [link to the generated class documentation](https://pschatzmann.github.io/arduino-simple-tts/docs/html/annotated.html)
125+
Here is the [link to the generated class documentation](https://pschatzmann.github.io/arduino-simple-tts/docs/html/annotated.html).
126126
Further information can be found in the [Uncyclo](https://github.com/pschatzmann/arduino-simple-tts/wiki) and in my [Blogs](https://www.pschatzmann.ch/home/tag/tts/)

examples/time-to-speech-sd/time-to-speech-sd.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
#include "AudioLibs/AudioKit.h"
1717

1818
TimeToText ttt;
19-
AudioKitStream i2s; // Replace with desired class e.g. AudioKitStream
2019
MP3DecoderHelix mp3;
2120
const char* path = "/tts";
2221
AudioDictionarySD dictionary(path, "mp3", PIN_AUDIO_KIT_SD_CARD_CS);
22+
AudioKitStream i2s; // Replace with desired output class e.g. I2SStream
2323
TextToSpeech tts(ttt, i2s, mp3, dictionary);
2424

2525
void setup(){
2626
Serial.begin(115200);
27-
AudioLogger::instance().begin(Serial, AudioLogger::Info);
27+
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
2828

2929
// setup i2s
3030
auto cfg = i2s.defaultConfig();
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
/**
3+
* @file time-to-speech.ino
4+
* @author Phil Schatzmann
5+
* @brief Test sketch which announces the indicated time - the audio files are loaded from the internet
6+
* @version 0.1
7+
* @date 2022-02-16
8+
*
9+
* @copyright Copyright (c) 2022
10+
*
11+
*/
12+
#include "AudioTools.h"
13+
#include "SimpleTTS.h"
14+
#include "AudioDictionaryURL.h"
15+
#include "AudioCodecs/CodecMP3Helix.h"
16+
#include "AudioLibs/AudioKit.h"
17+
18+
19+
const char *ssid = "ssid";
20+
const char *password = "password";
21+
const char *url = "https://pschatzmann.github.io/arduino-simple-tts/audio/";
22+
23+
TimeToText ttt;
24+
URLStream in(ssid, password);
25+
AudioDictionaryURL dictionary(in, url, "mp3");
26+
MP3DecoderHelix mp3;
27+
TextToSpeech tts(ttt, in, mp3, dictionary);
28+
AudioKitStream i2s; // Replace with desired class e.g. I2SStream
29+
30+
void setup(){
31+
Serial.begin(115200);
32+
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
33+
34+
// setup in
35+
auto cfg = i2s.defaultConfig();
36+
cfg.sd_active = false; // for AudioKitStream to use all pins
37+
cfg.sample_rate = 24000;
38+
cfg.channels = 1;
39+
i2s.begin(cfg);
40+
41+
// speach output
42+
ttt.say(11,40);
43+
}
44+
45+
void loop() {
46+
47+
}

src/AudioDictionaryURL.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "AudioHttp/URLStream.h"
34
#include "SimpleTTSBase.h"
45

56
namespace simple_tts {
@@ -14,22 +15,29 @@ namespace simple_tts {
1415
*/
1516
class AudioDictionaryURL : public AudioDictionaryBase {
1617
public:
17-
AudioDictionaryURL(URLStream &urlStream, const char *url) {
18+
AudioDictionaryURL(URLStream &urlStream, const char *url, const char *ext) {
1819
p_url = &urlStream;
1920
url_cstr = url;
21+
ext_cstr = ext;
2022
}
2123

2224
AudioStream *get(const char *word) {
2325
url_str = url_cstr;
24-
url_str.add("/");
26+
if (!url_str.endsWith("/")){
27+
url_str.add("/");
28+
}
2529
url_str.add(word);
30+
url_str.add(".");
31+
url_str.add(ext_cstr);
32+
url_str.toLowerCase();
2633
LOGI("Using url: %s", url_str.c_str());
2734
p_url->begin(url_str.c_str());
2835
return p_url;
2936
}
3037

3138
protected:
3239
const char *url_cstr;
40+
const char *ext_cstr;
3341
StrExt url_str;
3442
URLStream *p_url;
3543
};

0 commit comments

Comments
 (0)