diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cd46db1..f1c5fa1f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.16) -set(PROJECT_VER "0.7.1") +set(PROJECT_VER "0.7.2") include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(xiaozhi) diff --git a/main/application.cc b/main/application.cc index a7036aa4..31c3061d 100644 --- a/main/application.cc +++ b/main/application.cc @@ -149,7 +149,7 @@ void Application::Start() { auto codec = board.GetAudioCodec(); opus_decode_sample_rate_ = codec->output_sample_rate(); opus_decoder_ = opus_decoder_create(opus_decode_sample_rate_, 1, NULL); - opus_encoder_.Configure(codec->input_sample_rate(), 1); + opus_encoder_.Configure(16000, 1); if (codec->input_sample_rate() != 16000) { input_resampler_.Configure(codec->input_sample_rate(), 16000); reference_resampler_.Configure(codec->input_sample_rate(), 16000); @@ -236,6 +236,17 @@ void Application::Start() { }, "check_new_version", 4096 * 2, this, 1, NULL); #ifdef CONFIG_USE_AFE_SR + audio_processor_.Initialize(codec->input_channels(), codec->input_reference()); + audio_processor_.OnOutput([this](std::vector&& data) { + Schedule([this, data = std::move(data)]() { + if (chat_state_ == kChatStateListening) { + std::lock_guard lock(mutex_); + audio_encode_queue_.emplace_back(std::move(data)); + cv_.notify_all(); + } + }); + }); + wake_word_detect_.Initialize(codec->input_channels(), codec->input_reference()); wake_word_detect_.OnVadStateChange([this](bool speaking) { Schedule([this, speaking]() { @@ -284,17 +295,6 @@ void Application::Start() { }); }); wake_word_detect_.StartDetection(); - - audio_processor_.Initialize(codec->input_channels(), codec->input_reference()); - audio_processor_.OnOutput([this](std::vector&& data) { - Schedule([this, data = std::move(data)]() { - if (chat_state_ == kChatStateListening) { - std::lock_guard lock(mutex_); - audio_encode_queue_.emplace_back(std::move(data)); - cv_.notify_all(); - } - }); - }); #endif chat_state_ = kChatStateIdle; diff --git a/main/boards/esp-box-3/config.h b/main/boards/esp-box-3/config.h index a7656cde..a1255732 100644 --- a/main/boards/esp-box-3/config.h +++ b/main/boards/esp-box-3/config.h @@ -5,7 +5,7 @@ #define AUDIO_INPUT_SAMPLE_RATE 16000 #define AUDIO_OUTPUT_SAMPLE_RATE 16000 -#define AUDIO_DEFAULT_OUTPUT_VOLUME 90 +#define AUDIO_DEFAULT_OUTPUT_VOLUME 80 #define AUDIO_INPUT_REFERENCE true diff --git a/main/boards/lichuang-dev/config.h b/main/boards/lichuang-dev/config.h index 57581bef..ee55ac98 100644 --- a/main/boards/lichuang-dev/config.h +++ b/main/boards/lichuang-dev/config.h @@ -5,7 +5,7 @@ #define AUDIO_INPUT_SAMPLE_RATE 24000 #define AUDIO_OUTPUT_SAMPLE_RATE 24000 -#define AUDIO_DEFAULT_OUTPUT_VOLUME 90 +#define AUDIO_DEFAULT_OUTPUT_VOLUME 80 #define AUDIO_INPUT_REFERENCE true diff --git a/main/boards/lichuang-dev/lichuang_dev_board.cc b/main/boards/lichuang-dev/lichuang_dev_board.cc index e133f435..a0949ad9 100644 --- a/main/boards/lichuang-dev/lichuang_dev_board.cc +++ b/main/boards/lichuang-dev/lichuang_dev_board.cc @@ -109,7 +109,7 @@ public: audio_codec = new BoxAudioCodec(i2c_bus_, AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE, AUDIO_I2S_GPIO_MCLK, AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN, GPIO_NUM_NC, AUDIO_CODEC_ES8311_ADDR, AUDIO_CODEC_ES7210_ADDR, AUDIO_INPUT_REFERENCE); - // audio_codec->SetOutputVolume(AUDIO_DEFAULT_OUTPUT_VOLUME); + audio_codec->SetOutputVolume(AUDIO_DEFAULT_OUTPUT_VOLUME); } return audio_codec; } diff --git a/main/display/st7789_display.cc b/main/display/st7789_display.cc index e38574e7..a43047d6 100644 --- a/main/display/st7789_display.cc +++ b/main/display/st7789_display.cc @@ -48,8 +48,8 @@ St7789Display::St7789Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_h .mirror_y = mirror_y_, }, .flags = { - .buff_dma = 0, - .buff_spiram = 1, + .buff_dma = 1, + .buff_spiram = 0, .sw_rotate = 0, .full_refresh = 0, .direct_mode = 0, diff --git a/main/ota.cc b/main/ota.cc index cefb660c..ef9ed78f 100644 --- a/main/ota.cc +++ b/main/ota.cc @@ -152,6 +152,7 @@ void Ota::Upgrade(const std::string& firmware_url) { size_t total_read = 0, recent_read = 0; auto last_calc_time = esp_timer_get_time(); while (true) { + taskYIELD(); // Avoid watchdog timeout int ret = http->Read(buffer, sizeof(buffer)); if (ret < 0) { ESP_LOGE(TAG, "Failed to read HTTP data: %s", esp_err_to_name(ret)); diff --git a/main/wake_word_detect.cc b/main/wake_word_detect.cc index c120fed6..2d73636a 100644 --- a/main/wake_word_detect.cc +++ b/main/wake_word_detect.cc @@ -26,6 +26,9 @@ WakeWordDetect::~WakeWordDetect() { if (wake_word_encode_task_stack_ != nullptr) { free(wake_word_encode_task_stack_); } + if (audio_detection_task_stack_ != nullptr) { + heap_caps_free(audio_detection_task_stack_); + } vEventGroupDelete(event_group_); } @@ -77,11 +80,13 @@ void WakeWordDetect::Initialize(int channels, bool reference) { afe_detection_data_ = esp_afe_sr_v1.create_from_config(&afe_config); - xTaskCreate([](void* arg) { + const size_t audio_detection_task_stack_size = 4096 * 2; + audio_detection_task_stack_ = (StackType_t*)heap_caps_malloc(audio_detection_task_stack_size, MALLOC_CAP_SPIRAM); + xTaskCreateStatic([](void* arg) { auto this_ = (WakeWordDetect*)arg; this_->AudioDetectionTask(); vTaskDelete(NULL); - }, "audio_detection", 4096 * 2, this, 1, NULL); + }, "audio_detection", audio_detection_task_stack_size, this, 1, audio_detection_task_stack_, &audio_detection_task_buffer_); } void WakeWordDetect::OnWakeWordDetected(std::function callback) { diff --git a/main/wake_word_detect.h b/main/wake_word_detect.h index fdf13c83..53cbb481 100644 --- a/main/wake_word_detect.h +++ b/main/wake_word_detect.h @@ -40,6 +40,10 @@ private: int channels_; bool reference_; + TaskHandle_t audio_detection_task_ = nullptr; + StaticTask_t audio_detection_task_buffer_; + StackType_t* audio_detection_task_stack_ = nullptr; + TaskHandle_t wake_word_encode_task_ = nullptr; StaticTask_t wake_word_encode_task_buffer_; StackType_t* wake_word_encode_task_stack_ = nullptr; diff --git a/release.py b/release.py new file mode 100644 index 00000000..d035e5ca --- /dev/null +++ b/release.py @@ -0,0 +1,48 @@ +import sys +import os +import json + + +def get_board_type(): + with open("build/compile_commands.json") as f: + data = json.load(f) + for item in data: + if not item["file"].endswith("main.cc"): + continue + command = item["command"] + # extract -DBOARD_TYPE=xxx + board_type = command.split("-DBOARD_TYPE=\\\"")[1].split("\\\"")[0].strip() + return board_type + return None + +def get_project_version(): + with open("CMakeLists.txt") as f: + for line in f: + if line.startswith("set(PROJECT_VER"): + return line.split("\"")[1].split("\"")[0].strip() + return None + +def merge_bin(): + if os.system("idf.py merge-bin") != 0: + print("merge bin failed") + sys.exit(1) + +def zip_bin(board_type, project_version): + if not os.path.exists("releases"): + os.makedirs("releases") + output_path = f"releases/v{project_version}_{board_type}.zip" + if os.path.exists(output_path): + os.remove(output_path) + if os.system(f"zip -j {output_path} build/merged-binary.bin") != 0: + print("zip bin failed") + sys.exit(1) + print(f"zip bin to {output_path} done") + + +if __name__ == "__main__": + merge_bin() + board_type = get_board_type() + print("board type:", board_type) + project_version = get_project_version() + print("project version:", project_version) + zip_bin(board_type, project_version) diff --git a/versions.py b/versions.py index ff8cd474..9bf271ce 100644 --- a/versions.py +++ b/versions.py @@ -64,6 +64,8 @@ def get_board_name(folder): return "bread-compact-wifi" elif "KevinBox1" in basename: return "kevin-box-1" + if basename.startswith("v0.7"): + return basename.split("_")[1] raise Exception(f"Unknown board name: {basename}") def read_binary(dir_path):