Skip to content

Commit 7103467

Browse files
committed
Rollback AduioESP8266 change
1 parent fe5116a commit 7103467

File tree

5 files changed

+131
-9
lines changed

5 files changed

+131
-9
lines changed

examples/streams-a2dp-i2s/streams-a2dp-i2s.ino

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
/**
21
/**
32
* @file streams-a2dp-i2s.ino
43
* @author Phil Schatzmann
54
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/streams-a2dp-i2s/README.md
65
*
76
* @author Phil Schatzmann
87
* @copyright GPLv3
9-
*
108
*/
119
#include "AudioTools.h"
1210
#include "AudioA2DP.h"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
I tried to feed the WAV web server with a POST call to a webservice which returns a WAV file.
3+
This is not working: For some reason the connection is break up and I could not find out why.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "AudioTools.h"
2+
#include "AudioServer.h"
3+
4+
using namespace audio_tools;
5+
6+
AudioServer server("ssid","password");
7+
UrlStream url;
8+
StreamCopy copier;
9+
10+
// Callback which provides the audio data to Server
11+
void outputData(Stream &out){
12+
Serial.println("providing data...");
13+
14+
// get sound data from Rhasspy
15+
url.begin("http://192.168.1.37:12101/api/text-to-speech", UrlStream::POST, "text/plain","Hallo, my name is Alice");
16+
size_t byte_count = url.available();
17+
Serial.print("No of bytes received: ");
18+
Serial.println(byte_count);
19+
20+
copier.begin(out, url);
21+
copier.copyAll();
22+
23+
Serial.println("Copy done");
24+
25+
}
26+
27+
void setup(){
28+
Serial.begin(115200);
29+
// start server
30+
server.begin(outputData, "audio/wav");
31+
}
32+
33+
34+
// Arduino loop
35+
void loop() {
36+
// Handle new connections
37+
server.doLoop();
38+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* @file test-memory_wav-serial.ino
3+
* @author Phil Schatzmann
4+
* @brief decode WAV stream from url and output it on I2S
5+
* @version 0.1
6+
* @date 2021-96-25
7+
*
8+
* @copyright Copyright (c) 2021
9+
10+
*/
11+
#include "AudioTools.h"
12+
#include "CodecWAV.h"
13+
14+
using namespace audio_tools;
15+
16+
// UrlStream -copy-> AudioOutputStream -> WAVDecoder -> I2S
17+
URLStream url;
18+
I2SStream i2s; // I2S stream
19+
WAVDecoder decoder(i2s); // decode wav to pcm and send it to I2S
20+
AudioOutputStream out(decoder); // output to decoder
21+
StreamCopy copier(out, url); // copy in to out
22+
23+
24+
void setup(){
25+
Serial.begin(115200);
26+
AudioLogger::instance().begin(Serial, AudioLogger::Debug);
27+
28+
// url.begin("http://pi.local:5002//api/tts?text=hallo my name is sam")
29+
// url.begin("http://192.168.1.37:12101/api/text-to-speech?play=false", UrlStream::POST, "text/plain","Hallo, my name is Alice");
30+
31+
I2SConfig config = out.defaultConfig(TX_MODE);
32+
config.sample_rate = 16000;
33+
config.bits_per_sample = 32;
34+
config.channels = 1;
35+
36+
i2s.begin(config);
37+
38+
}
39+
40+
void loop(){
41+
if (wav) {
42+
copier.copy();
43+
} else {
44+
stop();
45+
}
46+
}

src/AudioESP8266.h

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,69 @@
11
#pragma once
22

3-
#ifdef USE_ESP8266_AUDIO
4-
5-
// support for the ESP8266 Audio Library
63
#include "AudioTools.h"
4+
#ifdef USE_ESP8266_AUDIO
75
#include "AudioOutput.h"
86
#include "SoundData.h"
97

8+
namespace audio_tools {
109

11-
class AudioOutputWithCallback : public AudioOutput, public CallbackStream<Channels> {
10+
/**
11+
* @brief ESP8266Audio AudioOutput class which stores the data in a temporary buffer.
12+
* The buffer can be consumed e.g. by a callback function by calling read();
13+
* @author Phil Schatzmann
14+
* @copyright GPLv3
15+
*/
16+
class AudioOutputWithCallback : public AudioOutput, public BufferedStream {
1217
public:
1318
// Default constructor
14-
AudioOutputWithCallback(int bufferSize, int bufferCount ):CallbackStream<Channels>(bufferSize) {
19+
AudioOutputWithCallback(int bufferSize, int bufferCount ):BufferedStream(bufferSize) {
20+
callback_buffer_ptr = new NBuffer<Channels>(bufferSize, bufferCount);
21+
}
22+
23+
virtual ~AudioOutputWithCallback() {
24+
delete callback_buffer_ptr;
25+
}
26+
27+
/// Activates the output
28+
virtual bool begin() {
29+
active = true;
30+
return true;
1531
}
1632

17-
/// Additinal method for ESP8266 Audio Framework - puts the sample into a buffer
33+
/// puts the sample into a buffer
1834
virtual bool ConsumeSample(int16_t sample[2]) {
1935
Channels c;
2036
c.channel1 = sample[0];
2137
c.channel2 = sample[1];
2238
return callback_buffer_ptr->write(c);
2339
};
40+
41+
/// stops the processing
42+
virtual bool stop() {
43+
active = false;
44+
return true;
45+
};
2446

2547
/// Provides the data from the internal buffer to the callback
2648
size_t read(Channels *src, size_t len){
2749
return active ? this->callback_buffer_ptr->readArray(src, len) : 0;
2850
}
2951

52+
53+
protected:
54+
NBuffer<Channels> *callback_buffer_ptr;
55+
bool active;
56+
57+
virtual size_t writeExt(const uint8_t* data, size_t len) {
58+
return callback_buffer_ptr->writeArray((Channels*)data, len/sizeof(Channels));
59+
}
60+
61+
virtual size_t readExt( uint8_t *data, size_t len) {
62+
return callback_buffer_ptr->readArray((Channels*)data, len/sizeof(Channels));;
63+
}
64+
65+
};
3066

3167
}
32-
#endif
68+
69+
#endif

0 commit comments

Comments
 (0)