Skip to content

Commit 5bdb074

Browse files
committed
Audiokit button example
1 parent 511e2e6 commit 5bdb074

File tree

3 files changed

+75
-12
lines changed

3 files changed

+75
-12
lines changed
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
/**
2-
* @file streams-i2s-csv.ino
2+
* @file streams-audiokit-csv.ino
33
* @author Phil Schatzmann
4-
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-stream/stream-i2s-csv/README.md
4+
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-stream/stream-audiokit-csv/README.md
55
*
66
* @author Phil Schatzmann
77
* @copyright GPLv3
88
*/
99

1010

1111
#include "AudioTools.h"
12+
#include "AudioDevices/ESP32AudioKit/AudioKit.h"
1213

1314
using namespace audio_tools;
1415

15-
I2SStream i2sStream; // Access I2S as stream
16+
AudioKitStream kit; // Access I2S as stream
1617
CsvStream<int32_t> csvStream(Serial);
17-
StreamCopy copier(csvStream, i2sStream); // copy i2sStream to csvStream
18+
StreamCopy copier(csvStream, kit); // copy kit to csvStream
1819

1920
// Arduino Setup
2021
void setup(void) {
2122
Serial.begin(115200);
2223
AudioLogger::instance().begin(Serial, AudioLogger::Info);
2324

24-
auto cfg = i2sStream.defaultConfig(RX_MODE);
25-
cfg.bits_per_sample = 32;
26-
cfg.channels = 2;
27-
cfg.sample_rate = 44100;
28-
cfg.is_master = true;
29-
cfg.i2s_format = I2S_MSB_FORMAT; // or try with I2S_LSB_FORMAT
30-
i2sStream.begin(cfg);
25+
auto cfg = kit.defaultConfig(RX_MODE);
26+
cfg.input_device = ADC_INPUT_MIC2;
27+
kit.begin(cfg);
3128

3229
// make sure that we have the correct channels set up
3330
csvStream.begin(cfg);
@@ -37,4 +34,4 @@ void setup(void) {
3734
// Arduino loop - copy data
3835
void loop() {
3936
copier.copy();
40-
}
37+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# AudioActions
2+
3+
Originally I was of the opinion that the program logic for __reading of the GPIO pins__ and the processing of the related actions should belong into a specific __Arduino sketch__ and should not be part of an Audio Framework.
4+
5+
The [Audio Kit](https://docs.ai-thinker.com/en/esp32-audio-kit) made me revise this because I think that an Arduino Sketch should be __as concise as possible__. For this I have created the AudioActions class which has been integrated into the AudioKit.
6+
7+
Since the Audio Kit does not have any display, I think to use TTS is a good choice.
8+
You just need to define you __handler methods__ (button1, button2...) and assign them to the __GPIO pins__.
9+
10+
11+
### Dependencies
12+
13+
You need to install the following libraries:
14+
15+
- [FLITE](https://github.com/pschatzmann/arduino-flite)
16+
- [Arduino Audio Tolls](https://github.com/pschatzmann/arduino-audio-tools)
17+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @file stream-pins-audiokit.ino
3+
* @brief see
4+
* https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-stream/stream-pins-audiokit/README.md
5+
* @author Phil Schatzmann
6+
* @copyright Copyright (c) 2021
7+
*/
8+
9+
#include "AudioDevices/ESP32AudioKit/AudioKit.h"
10+
#include "AudioTools.h"
11+
#include "flite_arduino.h"
12+
13+
using namespace audio_tools;
14+
15+
AudioKitStream kit;
16+
Flite flite(kit);
17+
18+
void button1() { flite.say("Button One"); }
19+
void button2() { flite.say("Button Two"); }
20+
void button3() { flite.say("Button Three"); }
21+
void button4() { flite.say("Button Four"); }
22+
23+
// Arduino setup
24+
void setup() {
25+
Serial.begin(115200);
26+
27+
auto cfg = kit.defaultConfig();
28+
cfg.bits_per_sample = 16;
29+
cfg.channels = 1;
30+
cfg.sample_rate = 8000;
31+
kit.begin(cfg);
32+
33+
// Assign pins to methods
34+
kit.addAction(PIN_KEY1, button1);
35+
kit.addAction(PIN_KEY2, button2);
36+
kit.addAction(PIN_KEY3, button3);
37+
kit.addAction(PIN_KEY4, button4);
38+
39+
// example with lambda expression
40+
auto up = []() { flite.say("Volume up"); };
41+
kit.addAction(PIN_KEY5, up);
42+
auto down = []() { flite.say("Volume down"); };
43+
kit.addAction(PIN_KEY6, down);
44+
45+
flite.say("Please push a button");
46+
}
47+
48+
// Arduino Loop
49+
void loop() { kit.processActions(); }

0 commit comments

Comments
 (0)