如何将
来自“https://translate.google.com/tra ... amp;q=hello%20world”的响应作为 mp3 文件写入 SPIFFS 并能够回放。有没有将 mp3 内容保存到 SPIFFS 的示例?
我已经试过了,但没有播放音频
代码:
全选 http.begin(tts.c_str());
// Send HTTP GET request
int httpResponseCode = http.GET();
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
int len = http.getSize();
uint8_t buff[len] = {0};
WiFiClient *stream = http.getStreamPtr();
while(http.connected() && (len > 0 || len == -1)) {
size_t size = stream->available();
if(size) {
int c = stream->readBytes(buff, ((size > sizeof(buff)) ? sizeof(buff) : size));
}
delay(1);
}
File file = SPIFFS.open("/helloworld.mp3", "w");
file.write(buff, len);
file.close();
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
http.end();