Skip to content

Commit 511e2e6

Browse files
committed
FLITE for audiokit
1 parent 561c327 commit 511e2e6

File tree

4 files changed

+56
-13
lines changed

4 files changed

+56
-13
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Using FLITE Speach to Text
2+
3+
I am providing a simple sketch which generates sound data with the Flite text to speach engine.
4+
You need to install https://github.com/pschatzmann/arduino-flite
5+
6+
The output goes to a ‘AI Thinker Audio Kit’.
7+
8+
<img src="https://pschatzmann.github.io/arduino-audio-tools/resources/audio-toolkit.png" alt="Audio Kit" />
9+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
@file streams-flite-audiokit.ino
3+
4+
@author Phil Schatzmann
5+
@copyright GPLv3
6+
7+
*/
8+
9+
#include "flite_arduino.h"
10+
#include "AudioTools.h"
11+
#include "AudioDevices/ESP32AudioKit/AudioKit.h"
12+
13+
using namespace audio_tools;
14+
15+
AudioKitStream kit;
16+
Flite flite(kit);
17+
18+
const char* alice = "Hallo my name is FLITE";
19+
20+
void setup(){
21+
Serial.begin(115200);
22+
auto cfg = kit.defaultConfig();
23+
cfg.bits_per_sample = 16;
24+
cfg.channels = 1;
25+
cfg.sample_rate = 8000;
26+
kit.begin(cfg);
27+
28+
flite.say(alice);
29+
}
30+
31+
void loop() {
32+
}

examples/examples-webserver/streams-flite-webserver_wav/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Using SAM Speach to Text
1+
# Using FLITE Speach to Text
22

33
I am providing a simple sketch which generates sound data with the Flite text to speach engine.
44
You need to install https://github.com/pschatzmann/arduino-flite

src/AudioDevices/ESP32AudioKit/AudioKit.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ static AudioKitStream *pt_AudioKitStream = nullptr;
358358
* @brief ESP32 Audio Kit using the ESP8388 DAC and ADC
359359
*
360360
*/
361-
class AudioKitStream : public AudioStream {
361+
class AudioKitStream : public AudioStreamX {
362362
public:
363363
/// Default Constructor
364364
AudioKitStream() { pt_AudioKitStream = this; };
@@ -462,6 +462,8 @@ class AudioKitStream : public AudioStream {
462462
LOGE("start failed");
463463
result = false;
464464
}
465+
466+
active = result;
465467
return result;
466468
}
467469

@@ -472,35 +474,34 @@ class AudioKitStream : public AudioStream {
472474
LOGI(LOG_METHOD);
473475
setPAPower(false);
474476
stop(module_value);
477+
active = false;
475478
}
476479

477480
/// Writes the audio data to I2S
478481
virtual size_t write(const uint8_t *buffer, size_t size) {
479482
LOGD(LOG_METHOD);
483+
if (!active){
484+
LOGE("you did not start the AudioKitStream with begin");
485+
return 0;
486+
}
480487
return i2s.writeBytes(buffer, size);
481488
}
482489

483490
/// Reads the audio data
484491
virtual size_t readBytes(uint8_t *data, size_t length) override {
492+
if (!active){
493+
LOGE("you did not start the AudioKitStream with begin");
494+
return 0;
495+
}
485496
return i2s.readBytes(data, length);
486497
}
487498

488-
/// not supported
489-
virtual size_t write(uint8_t) { return 0; }
490-
491-
/// not supported
492-
virtual int read() { return -1; }
493-
494-
/// not supported
495-
virtual int peek() { return -1; }
496-
497499
/// Provides the available audio data
498500
virtual int available() override { return i2s.available(); }
499501

500502
/// Provides the available audio data
501503
virtual int availableForWrite() override { return i2s.availableForWrite(); }
502504

503-
void flush() override {}
504505

505506
/**
506507
* @brief Reconfigure audio information
@@ -750,9 +751,10 @@ class AudioKitStream : public AudioStream {
750751
ConfigES8388 cfg;
751752
es_module_t module_value;
752753
I2SBase i2s;
753-
bool actualPower;
754754
AudioActions actions;
755755
int actionVolume = 0;
756+
bool actualPower;
757+
bool active;
756758

757759
/// init i2c with different possible pins
758760
esp_err_t i2c_init(void) {

0 commit comments

Comments
 (0)