How to record to a REST endpoint, detect sound and add headers to URLStream? #654
Replies: 9 comments 5 replies
-
|
Beta Was this translation helpful? Give feedback.
-
I am struggling with the URLStream object to talk to a REST endpoint. Note the information in the log file "HTTP/1.1 403 No permission to access this outbound connection.", "Transfer-Encoding: chunked" and "CONTENT_LENGTH found in reply" using the code below:
I get the following error:
If I use this super simple code, I do get a response of a 123675 byte file, and I even tried to copy from the Stream object WiFiClient* stream to the EncodedAudioStream with no success. It compiled, but Arduino just crashed.
As you can see below:
|
Beta Was this translation helpful? Give feedback.
-
The strange thing is that you seem to receive an empty line, which is not really something valid and I did not handle in my code. Can you adjust your custom WiFiClient test program to print empty lines as well and share the complete result that you get ? |
Beta Was this translation helpful? Give feedback.
-
Remove the content length from the header and try with If no length is specified, no data is posted! ps. I just committed a change, because I think this is too restrictive, and your version should be processed as well. I also added a put and post version that accept the data from a stream: https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_http_request.html. This might be handy to submit some audio data. |
Beta Was this translation helpful? Give feedback.
-
With the latest code, the following is working for me. I tried to minimize the number of lines of code: #include "AudioTools.h"
#include "AudioLibs/AudioKit.h"
const char* speechKey = "....";
const char* url_str = "https://southcentralus.tts.speech.microsoft.com/cognitiveservices/v1";
const char *msg = "Hallo my name is Alice";
URLStream url("ssid", "pwd");
AudioKitStream i2s; // or I2SStream
WAVDecoder decoder(i2s); // decode wav to pcm and send it to I2S
EncodedAudioStream out(i2s, decoder); // Decoder stream
StreamCopy copier(out, url); // copy in to out
void setup(){
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Info);
// setup i2s
auto config = i2s.defaultConfig(TX_MODE);
config.sample_rate = 16000;
config.bits_per_sample = 16;
config.channels = 1;
i2s.begin(config);
// microsoft speach service xml
String xml = "<speak version='1.0' xml:lang='en-US'><voice xml:lang='en-US' xml:gender='Female' name='en-US-JennyNeural'>@01</voice></speak>";
// http parameters
xml.replace(String("@01"), String(msg));
url.addRequestHeader("Ocp-Apim-Subscription-Key", speechKey);
url.addRequestHeader("X-Microsoft-OutputFormat", "riff-16khz-16bit-mono-pcm");
url.addRequestHeader(USER_AGENT, "arduino");
url.begin(url_str, "audio/wav", POST, "application/ssml+xml", xml.c_str());
}
void loop(){
copier.copy();
} |
Beta Was this translation helpful? Give feedback.
-
Oh it would be cool if you you could add this example with some corresponding documentation into this folder https://github.com/pschatzmann/arduino-audio-tools/tree/main/examples/examples-tts It would really help to describe the steps how to set this up in Azure. I requested a userid, but it quickly turned out to be much too complicated if one sees this for the first time. |
Beta Was this translation helpful? Give feedback.
-
Great example thanks for your contribution @ksaye and also thanks for the great lib @pschatzmann |
Beta Was this translation helpful? Give feedback.
-
I would recommend to stick with WAV. However you can replace the WAVDecoder with a MP3 decoder: Just read the documentation in the Wiki. |
Beta Was this translation helpful? Give feedback.
-
Is there a example of using Azure speech to text with this library? I see t mentioned in the issue |
Beta Was this translation helpful? Give feedback.
-
Great product and love the Header only implementation.
I need to perform some "speech to text" (S2T) and "text to speech" (TTS) using the Azure Speech service, which I can post to via a REST call.
I see a few challenges and would love any suggestions.
Beta Was this translation helpful? Give feedback.
All reactions