Replies: 2 comments 1 reply
-
I'm having the same problem, did you come across a solution? |
Beta Was this translation helpful? Give feedback.
0 replies
-
It might help to change the i2sPort, by default it is I2S_NUM_0, so that input and output use different ports |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone !
I tried to use MAX98357A and INMP441 on my ESP32-S3-WROOM-1 (N16R8) and faced with drivers conflict:
"CONFLICT! The new i2s driver can't work along with the legacy i2s driver"
Device just doing circle reboot with this message.
How can I fix this ?
Example of simple code:
`
#include <driver/i2s.h>
#include <FS.h>
#include <LittleFS.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include "Audio.h"
SET_LOOP_TASK_STACK_SIZE(16 * 1024); // 16KB
// ===================================================================
// ==========================Конфигурация I2S=========================
// ===================================================================
#define MAX98357A_I2S_DOUT 37
#define MAX98357A_I2S_BCLK 36
#define MAX98357A_I2S_LRC 35
Audio audio;
// Размер аудиобуфера в PSRAM (например, 64 KB)
const size_t audioBufferSize = 64 * 1024;
uint8_t* audioBufferPSRAM = nullptr; // Указатель на аудиобуфер в PSRAM
const char *ssid = "SSID"; // Your SSID
const char password = "PASS"; // Your PASS
#define SERVER_URL "<SERVER_URL" // Change the IP Address According To Your Server's config
const char encrypted_api_key = "API-KEY";
#define I2S_WS 15
#define I2S_SD 13
#define I2S_SCK 2
#define I2S_PORT I2S_NUM_0
#define I2S_SAMPLE_RATE (16000)
#define I2S_SAMPLE_BITS (16)
#define I2S_READ_LEN (16 * 1024)
#define I2S_CHANNEL_NUM (1)
#define SILENCE_THRESHOLD 100 // Adjust this value based on your needs
#define SILENCE_DURATION 500 // Duration to consider as silence (in milliseconds)
#define FLASH_RECORD_SIZE_MAX (I2S_CHANNEL_NUM * I2S_SAMPLE_RATE * I2S_SAMPLE_BITS / 8 * 60) // Max size for 60 seconds
File file;
const char filename[] = "/audio.wav";
const int headerSize = 44;
bool isWIFIConnected;
void setup() {
Serial.begin(115200);
LittleFS.begin(); // Initialize LittleFS
i2sInit();
xTaskCreate(wifiConnect, "wifi_Connect", 4096, NULL, 1, NULL);
xTaskCreate(i2s_adc, "i2s_adc", 4096, NULL, 2, NULL);
delay(500);
if (psramFound()) {
Serial.println("PSRAM found and ready to use");
} else {
Serial.println("No PSRAM found");
}
// Попытка выделить буфер в PSRAM
audioBufferPSRAM = (uint8_t*)heap_caps_malloc(audioBufferSize, MALLOC_CAP_SPIRAM);
if (audioBufferPSRAM == nullptr) {
Serial.println("Error: Failed to allocate audio buffer in PSRAM");
} else {
Serial.println("Audio buffer allocated in PSRAM");
}
audio.connecttospeech("TESTING TESTING", "en");
waitForSpeechEnd();
}
void loop() {
// Main loop can be empty or used for other tasks
}
// Функция для ожидания завершения озвучки
void waitForSpeechEnd() {
while (audio.isRunning()) {
audio.loop(); // Продолжаем проигрывание текущего аудио
yield(); // Даем время для завершения
}
}
void initFile() {
LittleFS.remove(filename); // Remove file if it exists
file = LittleFS.open(filename, "w"); // Open file for writing
if (!file) {
Serial.println("File is not available!");
return;
}
}
void handleSilence(unsigned long& silenceStart, bool& isSilent, char *i2s_read_buff, uint8_t *flash_write_buff, size_t& flash_wr_size) {
Serial.println(" *** Detected Silence, waiting for speech to resume *** ");
unsigned long waitStart = millis();
}
void i2sInit() {
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = I2S_SAMPLE_RATE,
.bits_per_sample = i2s_bits_per_sample_t(I2S_SAMPLE_BITS),
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 8,
.dma_buf_len = 1024,
.use_apll = false,
.tx_desc_auto_clear = true,
.fixed_mclk = 0
};
}
void i2s_adc_data_scale(uint8_t *d_buff, uint8_t *s_buff, uint32_t len) {
uint32_t j = 0;
uint32_t dac_value = 0;
for (int i = 0; i < len; i += 2) {
dac_value = ((((uint16_t)(s_buff[i + 1] & 0xf) << 8) | ((s_buff[i + 0]))));
d_buff[j++] = 0;
d_buff[j++] = dac_value * 256 / 2048;
}
}
void i2s_adc(void *arg) {
size_t flash_wr_size = 0; // Ensure this is size_t
size_t uint8_ts_read;
}
void wavHeader(uint8_t *header, int wavSize) {
header[0] = 'R';
header[1] = 'I';
header[2] = 'F';
header[3] = 'F';
unsigned int fileSize = wavSize + headerSize - 8;
header[4] = (uint8_t)(fileSize & 0xFF);
header[5] = (uint8_t)((fileSize >> 8) & 0xFF);
header[6] = (uint8_t)((fileSize >> 16) & 0xFF);
header[7] = (uint8_t)((fileSize >> 24) & 0xFF);
header[8] = 'W';
header[9] = 'A';
header[10] = 'V';
header[11] = 'E';
header[12] = 'f';
header[13] = 'm';
header[14] = 't';
header[15] = ' ';
header[16] = 0x10;
header[17] = 0x00;
header[18] = 0x00;
header[19] = 0x00;
header[20] = 0x01;
header[21] = 0x00;
header[22] = 0x01;
header[23] = 0x00;
header[24] = 0x80;
header[25] = 0x3E;
header[26] = 0x00;
header[27] = 0x00;
header[28] = 0x00;
header[29] = 0x7D;
header[30] = 0x01;
header[31] = 0x00;
header[32] = 0x02;
header[33] = 0x00;
header[34] = 0x10;
header[35] = 0x00;
header[36] = 'd';
header[37] = 'a';
header[38] = 't';
header[39] = 'a';
header[40] = (uint8_t)(wavSize & 0xFF);
header[41] = (uint8_t)((wavSize >> 8) & 0xFF);
header[42] = (uint8_t)((wavSize >> 16) & 0xFF);
header[43] = (uint8_t)((wavSize >> 24) & 0xFF);
}
void uploadFile() {
Serial.println("Uploading audio file...");
WiFiClient client;
HTTPClient http;
http.begin(client, SERVER_URL);
http.addHeader("X-API-KEY", encrypted_api_key);
http.addHeader("Content-Type", "audio/wav");
File uploadFile = LittleFS.open(filename, "r"); // Открытие файла для чтения
if (!uploadFile) {
Serial.println("Failed to open file for reading");
return;
}
int httpResponseCode = http.sendRequest("POST", &uploadFile, uploadFile.size());
if (httpResponseCode > 0) {
Serial.printf("File uploaded successfully, response code: %d\n", httpResponseCode);
} else {
Serial.printf("Error uploading file: %s\n", http.errorToString(httpResponseCode).c_str());
}
uploadFile.close();
http.end();
}
void listFiles(void) {
Serial.println(F("\r\nListing LittleFS files:"));
static const char line[] PROGMEM = "=================================================";
Serial.println(FPSTR(line));
Serial.println(F(" File name Size"));
Serial.println(FPSTR(line));
fs::File root = LittleFS.open("/");
if (!root) {
Serial.println(F("Failed to open directory"));
return;
}
if (!root.isDirectory()) {
Serial.println(F("Not a directory"));
return;
}
fs::File file = root.openNextFile();
while (file) {
if (file.isDirectory()) {
Serial.print("DIR : ");
String fileName = file.name();
Serial.print(fileName);
} else {
String fileName = file.name();
Serial.print(" " + fileName);
int spaces = 33 - fileName.length();
if (spaces < 1) spaces = 1;
while (spaces--) Serial.print(" ");
Serial.print(file.size());
Serial.println(" uint8_ts");
}
file = root.openNextFile();
}
Serial.println(FPSTR(line));
}
void wifiConnect(void *arg) {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
isWIFIConnected = true;
vTaskDelete(NULL); // Delete the task once connected
}
`
Beta Was this translation helpful? Give feedback.
All reactions