forked from xiaozhi/xiaozhi-esp32
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7af366b7b2 | ||
|
|
ddbb24942d | ||
|
|
610a4a0703 | ||
|
|
7cd37427b2 | ||
|
|
2d772dad68 | ||
|
|
156eb15f58 |
@@ -4,7 +4,7 @@
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(PROJECT_VER "1.8.8")
|
||||
set(PROJECT_VER "1.8.9")
|
||||
|
||||
# Add this line to disable the specific warning
|
||||
add_compile_options(-Wno-missing-field-initializers)
|
||||
|
||||
@@ -130,7 +130,7 @@
|
||||
|
||||
## 大模型配置
|
||||
|
||||
如果你已经拥有一个的小智 AI 聊天机器人设备,并且已接入官方服务器,可以登录 [xiaozhi.me](https://xiaozhi.me) 控制台进行配置。
|
||||
如果你已经拥有一个小智 AI 聊天机器人设备,并且已接入官方服务器,可以登录 [xiaozhi.me](https://xiaozhi.me) 控制台进行配置。
|
||||
|
||||
👉 [后台操作视频教程(旧版界面)](https://www.bilibili.com/video/BV1jUCUY2EKM/)
|
||||
|
||||
|
||||
@@ -540,6 +540,12 @@ void AudioService::SetCallbacks(AudioServiceCallbacks& callbacks) {
|
||||
}
|
||||
|
||||
void AudioService::PlaySound(const std::string_view& ogg) {
|
||||
if (!codec_->output_enabled()) {
|
||||
esp_timer_stop(audio_power_timer_);
|
||||
esp_timer_start_periodic(audio_power_timer_, AUDIO_POWER_CHECK_INTERVAL_MS * 1000);
|
||||
codec_->EnableOutput(true);
|
||||
}
|
||||
|
||||
const uint8_t* buf = reinterpret_cast<const uint8_t*>(ogg.data());
|
||||
size_t size = ogg.size();
|
||||
size_t offset = 0;
|
||||
|
||||
@@ -64,7 +64,7 @@ BoxAudioCodec::BoxAudioCodec(void* i2c_master_handle, int input_sample_rate, int
|
||||
|
||||
es7210_codec_cfg_t es7210_cfg = {};
|
||||
es7210_cfg.ctrl_if = in_ctrl_if_;
|
||||
es7210_cfg.mic_selected = ES7120_SEL_MIC1 | ES7120_SEL_MIC2 | ES7120_SEL_MIC3 | ES7120_SEL_MIC4;
|
||||
es7210_cfg.mic_selected = ES7210_SEL_MIC1 | ES7210_SEL_MIC2 | ES7210_SEL_MIC3 | ES7210_SEL_MIC4;
|
||||
in_codec_if_ = es7210_codec_new(&es7210_cfg);
|
||||
assert(in_codec_if_ != NULL);
|
||||
|
||||
|
||||
@@ -13,11 +13,6 @@ void NoAudioProcessor::Feed(std::vector<int16_t>&& data) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.size() != frame_samples_) {
|
||||
ESP_LOGE(TAG, "Feed data size is not equal to frame size, feed size: %u, frame size: %u", data.size(), frame_samples_);
|
||||
return;
|
||||
}
|
||||
|
||||
if (codec_->input_channels() == 2) {
|
||||
// If input channels is 2, we need to fetch the left channel data
|
||||
auto mono_data = std::vector<int16_t>(data.size() / 2);
|
||||
|
||||
@@ -28,7 +28,7 @@ Esp32Camera::Esp32Camera(const camera_config_t& config) {
|
||||
memset(&preview_image_, 0, sizeof(preview_image_));
|
||||
preview_image_.header.magic = LV_IMAGE_HEADER_MAGIC;
|
||||
preview_image_.header.cf = LV_COLOR_FORMAT_RGB565;
|
||||
preview_image_.header.flags = LV_IMAGE_FLAGS_ALLOCATED | LV_IMAGE_FLAGS_MODIFIABLE;
|
||||
preview_image_.header.flags = 0;
|
||||
|
||||
switch (config.frame_size) {
|
||||
case FRAMESIZE_SVGA:
|
||||
|
||||
@@ -141,7 +141,7 @@ void ElectronEmojiDisplay::SetChatMessage(const char* role, const char* content)
|
||||
}
|
||||
|
||||
lv_label_set_text(chat_message_label_, content);
|
||||
lv_obj_clear_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
ESP_LOGI(TAG, "设置聊天消息 [%s]: %s", role, content);
|
||||
}
|
||||
@@ -163,7 +163,7 @@ void ElectronEmojiDisplay::SetIcon(const char* icon) {
|
||||
}
|
||||
|
||||
lv_label_set_text(chat_message_label_, icon_message.c_str());
|
||||
lv_obj_clear_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
ESP_LOGI(TAG, "设置图标: %s", icon);
|
||||
}
|
||||
|
||||
@@ -141,8 +141,7 @@ void AdcPdmAudioCodec::EnableInput(bool enable) {
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_codec_dev_open(input_dev_, &fs));
|
||||
} else {
|
||||
// ESP_ERROR_CHECK(esp_codec_dev_close(input_dev_));
|
||||
return;
|
||||
ESP_ERROR_CHECK(esp_codec_dev_close(input_dev_));
|
||||
}
|
||||
AudioCodec::EnableInput(enable);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <esp_log.h>
|
||||
#include "mmap_generate_emoji.h"
|
||||
#include "emoji_display.h"
|
||||
#include "assets/lang_config.h"
|
||||
|
||||
#include <esp_lcd_panel_io.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
@@ -146,9 +147,9 @@ void EmojiWidget::SetEmotion(const char* emotion)
|
||||
void EmojiWidget::SetStatus(const char* status)
|
||||
{
|
||||
if (player_) {
|
||||
if (strcmp(status, "聆听中...") == 0) {
|
||||
if (strcmp(status, Lang::Strings::LISTENING) == 0) {
|
||||
player_->StartPlayer(MMAP_EMOJI_ASKING_AAF, true, 15);
|
||||
} else if (strcmp(status, "待命") == 0) {
|
||||
} else if (strcmp(status, Lang::Strings::STANDBY) == 0) {
|
||||
player_->StartPlayer(MMAP_EMOJI_WAKE_AAF, true, 15);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "servo_dog_ctrl.h"
|
||||
#include "led_strip.h"
|
||||
#include "driver/rmt_tx.h"
|
||||
#include "device_state_event.h"
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
@@ -284,13 +285,14 @@ private:
|
||||
ESP_LOGI(TAG, "Create emoji widget, panel: %p, panel_io: %p", panel, panel_io);
|
||||
display_ = new anim::EmojiWidget(panel, panel_io);
|
||||
|
||||
#if CONFIG_ESP_CONSOLE_NONE
|
||||
servo_dog_ctrl_config_t config = {
|
||||
.fl_gpio_num = FL_GPIO_NUM,
|
||||
.fr_gpio_num = FR_GPIO_NUM,
|
||||
.bl_gpio_num = BL_GPIO_NUM,
|
||||
.br_gpio_num = BR_GPIO_NUM,
|
||||
};
|
||||
#if CONFIG_ESP_CONSOLE_NONE
|
||||
|
||||
servo_dog_ctrl_init(&config);
|
||||
#endif
|
||||
}
|
||||
@@ -378,7 +380,7 @@ private:
|
||||
int r = properties["r"].value<int>();
|
||||
int g = properties["g"].value<int>();
|
||||
int b = properties["b"].value<int>();
|
||||
|
||||
|
||||
led_on_ = true;
|
||||
SetLedColor(r, g, b);
|
||||
return true;
|
||||
@@ -395,6 +397,11 @@ public:
|
||||
InitializeSpi();
|
||||
InitializeLcdDisplay();
|
||||
InitializeTools();
|
||||
|
||||
DeviceStateEventManager::GetInstance().RegisterStateChangeCallback([this](DeviceState previous_state, DeviceState current_state) {
|
||||
ESP_LOGD(TAG, "Device state changed from %d to %d", previous_state, current_state);
|
||||
this->GetAudioCodec()->EnableOutput(current_state == kDeviceStateSpeaking);
|
||||
});
|
||||
}
|
||||
|
||||
virtual AudioCodec* GetAudioCodec() override
|
||||
|
||||
@@ -64,7 +64,7 @@ CoreS3AudioCodec::CoreS3AudioCodec(void* i2c_master_handle, int input_sample_rat
|
||||
|
||||
es7210_codec_cfg_t es7210_cfg = {};
|
||||
es7210_cfg.ctrl_if = in_ctrl_if_;
|
||||
es7210_cfg.mic_selected = ES7120_SEL_MIC1 | ES7120_SEL_MIC2 | ES7120_SEL_MIC3;
|
||||
es7210_cfg.mic_selected = ES7210_SEL_MIC1 | ES7210_SEL_MIC2 | ES7210_SEL_MIC3;
|
||||
in_codec_if_ = es7210_codec_new(&es7210_cfg);
|
||||
assert(in_codec_if_ != NULL);
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ Tab5AudioCodec::Tab5AudioCodec(void* i2c_master_handle, int input_sample_rate, i
|
||||
|
||||
es7210_codec_cfg_t es7210_cfg = {};
|
||||
es7210_cfg.ctrl_if = in_ctrl_if_;
|
||||
es7210_cfg.mic_selected = ES7120_SEL_MIC1 | ES7120_SEL_MIC2 | ES7120_SEL_MIC3 | ES7120_SEL_MIC4;
|
||||
es7210_cfg.mic_selected = ES7210_SEL_MIC1 | ES7210_SEL_MIC2 | ES7210_SEL_MIC3 | ES7210_SEL_MIC4;
|
||||
in_codec_if_ = es7210_codec_new(&es7210_cfg);
|
||||
assert(in_codec_if_ != NULL);
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ void OttoEmojiDisplay::SetChatMessage(const char* role, const char* content) {
|
||||
}
|
||||
|
||||
lv_label_set_text(chat_message_label_, content);
|
||||
lv_obj_clear_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
ESP_LOGI(TAG, "设置聊天消息 [%s]: %s", role, content);
|
||||
}
|
||||
@@ -164,7 +164,7 @@ void OttoEmojiDisplay::SetIcon(const char* icon) {
|
||||
}
|
||||
|
||||
lv_label_set_text(chat_message_label_, icon_message.c_str());
|
||||
lv_obj_clear_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
ESP_LOGI(TAG, "设置图标: %s", icon);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
|
||||
void SetupHighTempWarningPopup() {
|
||||
// 创建高温警告弹窗
|
||||
high_temp_popup_ = lv_obj_create(lv_scr_act()); // 使用当前屏幕
|
||||
high_temp_popup_ = lv_obj_create(lv_screen_active()); // 使用当前屏幕
|
||||
lv_obj_set_scrollbar_mode(high_temp_popup_, LV_SCROLLBAR_MODE_OFF);
|
||||
lv_obj_set_size(high_temp_popup_, LV_HOR_RES * 0.9, fonts_.text_font->line_height * 2);
|
||||
lv_obj_align(high_temp_popup_, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
|
||||
void ShowHighTempWarning() {
|
||||
if (high_temp_popup_ && lv_obj_has_flag(high_temp_popup_, LV_OBJ_FLAG_HIDDEN)) {
|
||||
lv_obj_clear_flag(high_temp_popup_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(high_temp_popup_, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ Display::Display() {
|
||||
Display *display = static_cast<Display*>(arg);
|
||||
DisplayLockGuard lock(display);
|
||||
lv_obj_add_flag(display->notification_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(display->status_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(display->status_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
},
|
||||
.arg = this,
|
||||
.dispatch_method = ESP_TIMER_TASK,
|
||||
@@ -67,7 +67,7 @@ void Display::SetStatus(const char* status) {
|
||||
return;
|
||||
}
|
||||
lv_label_set_text(status_label_, status);
|
||||
lv_obj_clear_flag(status_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(status_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(notification_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
last_status_update_time_ = std::chrono::system_clock::now();
|
||||
@@ -83,7 +83,7 @@ void Display::ShowNotification(const char* notification, int duration_ms) {
|
||||
return;
|
||||
}
|
||||
lv_label_set_text(notification_label_, notification);
|
||||
lv_obj_clear_flag(notification_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(notification_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(status_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
esp_timer_stop(notification_timer_);
|
||||
@@ -157,7 +157,7 @@ void Display::UpdateStatusBar(bool update_all) {
|
||||
if (low_battery_popup_ != nullptr) {
|
||||
if (strcmp(icon, FONT_AWESOME_BATTERY_EMPTY) == 0 && discharging) {
|
||||
if (lv_obj_has_flag(low_battery_popup_, LV_OBJ_FLAG_HIDDEN)) { // 如果低电量提示框隐藏,则显示
|
||||
lv_obj_clear_flag(low_battery_popup_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(low_battery_popup_, LV_OBJ_FLAG_HIDDEN);
|
||||
app.PlaySound(Lang::Sounds::OGG_LOW_BATTERY);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -105,7 +105,7 @@ SpiLcdDisplay::SpiLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_h
|
||||
ESP_LOGI(TAG, "Initialize LVGL port");
|
||||
lvgl_port_cfg_t port_cfg = ESP_LVGL_PORT_INIT_CONFIG();
|
||||
port_cfg.task_priority = 1;
|
||||
port_cfg.timer_period_ms = 50;
|
||||
port_cfg.timer_period_ms = 40;
|
||||
lvgl_port_init(&port_cfg);
|
||||
|
||||
ESP_LOGI(TAG, "Adding LCD display");
|
||||
@@ -814,11 +814,11 @@ void LcdDisplay::SetPreviewImage(const lv_img_dsc_t* img_dsc) {
|
||||
}
|
||||
|
||||
if (img_dsc != nullptr) {
|
||||
// zoom factor 0.5
|
||||
lv_image_set_scale(preview_image_, 128 * width_ / img_dsc->header.w);
|
||||
// 设置图片源并显示预览图片
|
||||
lv_image_set_src(preview_image_, img_dsc);
|
||||
lv_obj_clear_flag(preview_image_, LV_OBJ_FLAG_HIDDEN);
|
||||
// zoom factor 0.5
|
||||
lv_image_set_scale(preview_image_, 128 * width_ / img_dsc->header.w);
|
||||
lv_obj_remove_flag(preview_image_, LV_OBJ_FLAG_HIDDEN);
|
||||
// 隐藏emotion_label_
|
||||
if (emotion_label_ != nullptr) {
|
||||
lv_obj_add_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
@@ -827,7 +827,7 @@ void LcdDisplay::SetPreviewImage(const lv_img_dsc_t* img_dsc) {
|
||||
// 隐藏预览图片并显示emotion_label_
|
||||
lv_obj_add_flag(preview_image_, LV_OBJ_FLAG_HIDDEN);
|
||||
if (emotion_label_ != nullptr) {
|
||||
lv_obj_clear_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -883,7 +883,7 @@ void LcdDisplay::SetEmotion(const char* emotion) {
|
||||
|
||||
#if !CONFIG_USE_WECHAT_MESSAGE_STYLE
|
||||
// 显示emotion_label_,隐藏preview_image_
|
||||
lv_obj_clear_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
if (preview_image_ != nullptr) {
|
||||
lv_obj_add_flag(preview_image_, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
@@ -900,7 +900,7 @@ void LcdDisplay::SetIcon(const char* icon) {
|
||||
|
||||
#if !CONFIG_USE_WECHAT_MESSAGE_STYLE
|
||||
// 显示emotion_label_,隐藏preview_image_
|
||||
lv_obj_clear_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
if (preview_image_ != nullptr) {
|
||||
lv_obj_add_flag(preview_image_, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ OledDisplay::OledDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handl
|
||||
lvgl_port_cfg_t port_cfg = ESP_LVGL_PORT_INIT_CONFIG();
|
||||
port_cfg.task_priority = 1;
|
||||
port_cfg.task_stack = 6144;
|
||||
port_cfg.timer_period_ms = 50;
|
||||
port_cfg.timer_period_ms = 40;
|
||||
lvgl_port_init(&port_cfg);
|
||||
|
||||
ESP_LOGI(TAG, "Adding OLED display");
|
||||
@@ -112,7 +112,7 @@ void OledDisplay::SetChatMessage(const char* role, const char* content) {
|
||||
lv_obj_add_flag(content_right_, LV_OBJ_FLAG_HIDDEN);
|
||||
} else {
|
||||
lv_label_set_text(chat_message_label_, content_str.c_str());
|
||||
lv_obj_clear_flag(content_right_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(content_right_, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,27 +13,27 @@ dependencies:
|
||||
espressif/esp_io_expander_tca9554: ==2.0.0
|
||||
espressif/esp_lcd_panel_io_additions: ^1.0.1
|
||||
78/esp_lcd_nv3023: ~1.0.0
|
||||
78/esp-wifi-connect: ~2.5.0
|
||||
78/esp-wifi-connect: ~2.5.1
|
||||
78/esp-opus-encoder: ~2.4.1
|
||||
78/esp-ml307: ~3.2.6
|
||||
78/esp-ml307: ~3.2.8
|
||||
78/xiaozhi-fonts: ~1.4.0
|
||||
espressif/led_strip: ^2.5.5
|
||||
espressif/esp_codec_dev: ~1.3.6
|
||||
espressif/esp-sr: ==2.1.4
|
||||
espressif/led_strip: ~3.0.1
|
||||
espressif/esp_codec_dev: ~1.4.0
|
||||
espressif/esp-sr: ~2.1.5
|
||||
espressif/button: ~4.1.3
|
||||
espressif/knob: ^1.0.0
|
||||
espressif/esp32-camera: ^2.0.15
|
||||
espressif/esp32-camera: ~2.1.2
|
||||
espressif/esp_lcd_touch_ft5x06: ~1.0.7
|
||||
espressif/esp_lcd_touch_gt911: ^1
|
||||
espressif/esp_lcd_touch_gt1151: ^1
|
||||
waveshare/esp_lcd_touch_cst9217: ^1.0.3
|
||||
espressif/esp_lcd_touch_cst816s: ^1.0.6
|
||||
lvgl/lvgl: ~9.2.2
|
||||
lvgl/lvgl: ~9.3.0
|
||||
esp_lvgl_port: ~2.6.0
|
||||
espressif/esp_io_expander_tca95xx_16bit: ^2.0.0
|
||||
espressif2022/image_player: ==1.1.0~1
|
||||
espressif2022/esp_emote_gfx: ^1.0.0
|
||||
espressif/adc_mic: ^0.2.0
|
||||
espressif/adc_mic: ^0.2.1
|
||||
espressif/esp_mmap_assets: '>=1.2'
|
||||
txp666/otto-emoji-gif-component: ~1.0.2
|
||||
espressif/adc_battery_estimation: ^0.2.0
|
||||
|
||||
@@ -15,7 +15,7 @@ CircularStrip::CircularStrip(gpio_num_t gpio, uint8_t max_leds) : max_leds_(max_
|
||||
led_strip_config_t strip_config = {};
|
||||
strip_config.strip_gpio_num = gpio;
|
||||
strip_config.max_leds = max_leds_;
|
||||
strip_config.led_pixel_format = LED_PIXEL_FORMAT_GRB;
|
||||
strip_config.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB;
|
||||
strip_config.led_model = LED_MODEL_WS2812;
|
||||
|
||||
led_strip_rmt_config_t rmt_config = {};
|
||||
|
||||
@@ -18,7 +18,7 @@ SingleLed::SingleLed(gpio_num_t gpio) {
|
||||
led_strip_config_t strip_config = {};
|
||||
strip_config.strip_gpio_num = gpio;
|
||||
strip_config.max_leds = 1;
|
||||
strip_config.led_pixel_format = LED_PIXEL_FORMAT_GRB;
|
||||
strip_config.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB;
|
||||
strip_config.led_model = LED_MODEL_WS2812;
|
||||
|
||||
led_strip_rmt_config_t rmt_config = {};
|
||||
|
||||
@@ -55,13 +55,15 @@ std::unique_ptr<Http> Ota::SetupHttp() {
|
||||
|
||||
auto network = board.GetNetwork();
|
||||
auto http = network->CreateHttp(0);
|
||||
auto user_agent = std::string(BOARD_NAME "/") + app_desc->version;
|
||||
http->SetHeader("Activation-Version", has_serial_number_ ? "2" : "1");
|
||||
http->SetHeader("Device-Id", SystemInfo::GetMacAddress().c_str());
|
||||
http->SetHeader("Client-Id", board.GetUuid());
|
||||
if (has_serial_number_) {
|
||||
http->SetHeader("Serial-Number", serial_number_.c_str());
|
||||
ESP_LOGI(TAG, "Setup HTTP, User-Agent: %s, Serial-Number: %s", user_agent.c_str(), serial_number_.c_str());
|
||||
}
|
||||
http->SetHeader("User-Agent", std::string(BOARD_NAME "/") + app_desc->version);
|
||||
http->SetHeader("User-Agent", user_agent);
|
||||
http->SetHeader("Accept-Language", Lang::CODE);
|
||||
http->SetHeader("Content-Type", "application/json");
|
||||
|
||||
|
||||
29
scripts/ogg_converter/README.md
Normal file
29
scripts/ogg_converter/README.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# ogg_covertor 小智AI OGG 批量转换器
|
||||
|
||||
本脚本为OGG批量转换工具,支持将输入的音频文件转换为小智可使用的OGG格式
|
||||
基于Python第三方库`ffmpeg-python`实现
|
||||
支持OGG和音频之间的互转,响度调节等功能
|
||||
|
||||
# 创建并激活虚拟环境
|
||||
|
||||
```bash
|
||||
# 创建虚拟环境
|
||||
python -m venv venv
|
||||
# 激活虚拟环境
|
||||
source venv/bin/activate # Mac/Linux
|
||||
venv\Scripts\activate # Windows
|
||||
```
|
||||
|
||||
# 安装依赖
|
||||
|
||||
请在虚拟环境中执行
|
||||
|
||||
```bash
|
||||
pip install ffmpeg-python
|
||||
```
|
||||
|
||||
# 运行脚本
|
||||
```bash
|
||||
python ogg_covertor.py
|
||||
```
|
||||
|
||||
230
scripts/ogg_converter/xiaozhi_ogg_converter.py
Normal file
230
scripts/ogg_converter/xiaozhi_ogg_converter.py
Normal file
@@ -0,0 +1,230 @@
|
||||
import tkinter as tk
|
||||
from tkinter import ttk, filedialog, messagebox
|
||||
import os
|
||||
import threading
|
||||
import sys
|
||||
import ffmpeg
|
||||
|
||||
class AudioConverterApp:
|
||||
def __init__(self, master):
|
||||
self.master = master
|
||||
master.title("小智AI OGG音频批量转换工具")
|
||||
master.geometry("680x600") # 调整窗口高度
|
||||
|
||||
# 初始化变量
|
||||
self.mode = tk.StringVar(value="audio_to_ogg")
|
||||
self.output_dir = tk.StringVar()
|
||||
self.output_dir.set(os.path.abspath("output"))
|
||||
self.enable_loudnorm = tk.BooleanVar(value=True)
|
||||
self.target_lufs = tk.DoubleVar(value=-16.0)
|
||||
|
||||
# 创建UI组件
|
||||
self.create_widgets()
|
||||
self.redirect_output()
|
||||
|
||||
def create_widgets(self):
|
||||
# 模式选择
|
||||
mode_frame = ttk.LabelFrame(self.master, text="转换模式")
|
||||
mode_frame.grid(row=0, column=0, padx=10, pady=5, sticky="ew")
|
||||
|
||||
ttk.Radiobutton(mode_frame, text="音频转到OGG", variable=self.mode,
|
||||
value="audio_to_ogg", command=self.toggle_settings,
|
||||
width=12).grid(row=0, column=0, padx=5)
|
||||
ttk.Radiobutton(mode_frame, text="OGG转回音频", variable=self.mode,
|
||||
value="ogg_to_audio", command=self.toggle_settings,
|
||||
width=12).grid(row=0, column=1, padx=5)
|
||||
|
||||
# 响度设置
|
||||
self.loudnorm_frame = ttk.Frame(self.master)
|
||||
self.loudnorm_frame.grid(row=1, column=0, padx=10, pady=5, sticky="ew")
|
||||
|
||||
ttk.Checkbutton(self.loudnorm_frame, text="启用响度调整",
|
||||
variable=self.enable_loudnorm, width=15
|
||||
).grid(row=0, column=0, padx=2)
|
||||
ttk.Entry(self.loudnorm_frame, textvariable=self.target_lufs,
|
||||
width=6).grid(row=0, column=1, padx=2)
|
||||
ttk.Label(self.loudnorm_frame, text="LUFS").grid(row=0, column=2, padx=2)
|
||||
|
||||
# 文件选择
|
||||
file_frame = ttk.LabelFrame(self.master, text="输入文件")
|
||||
file_frame.grid(row=2, column=0, padx=10, pady=5, sticky="nsew")
|
||||
|
||||
# 文件操作按钮
|
||||
ttk.Button(file_frame, text="选择文件", command=self.select_files,
|
||||
width=12).grid(row=0, column=0, padx=5, pady=2)
|
||||
ttk.Button(file_frame, text="移除选中", command=self.remove_selected,
|
||||
width=12).grid(row=0, column=1, padx=5, pady=2)
|
||||
ttk.Button(file_frame, text="清空列表", command=self.clear_files,
|
||||
width=12).grid(row=0, column=2, padx=5, pady=2)
|
||||
|
||||
# 文件列表(使用Treeview)
|
||||
self.tree = ttk.Treeview(file_frame, columns=("selected", "filename"),
|
||||
show="headings", height=8)
|
||||
self.tree.heading("selected", text="选中", anchor=tk.W)
|
||||
self.tree.heading("filename", text="文件名", anchor=tk.W)
|
||||
self.tree.column("selected", width=60, anchor=tk.W)
|
||||
self.tree.column("filename", width=600, anchor=tk.W)
|
||||
self.tree.grid(row=1, column=0, columnspan=3, sticky="nsew", padx=5, pady=2)
|
||||
self.tree.bind("<ButtonRelease-1>", self.on_tree_click)
|
||||
|
||||
# 输出目录
|
||||
output_frame = ttk.LabelFrame(self.master, text="输出目录")
|
||||
output_frame.grid(row=3, column=0, padx=10, pady=5, sticky="ew")
|
||||
|
||||
ttk.Entry(output_frame, textvariable=self.output_dir, width=60
|
||||
).grid(row=0, column=0, padx=5, sticky="ew")
|
||||
ttk.Button(output_frame, text="浏览", command=self.select_output_dir,
|
||||
width=8).grid(row=0, column=1, padx=5)
|
||||
|
||||
# 转换按钮区域
|
||||
button_frame = ttk.Frame(self.master)
|
||||
button_frame.grid(row=4, column=0, padx=10, pady=10, sticky="ew")
|
||||
|
||||
ttk.Button(button_frame, text="转换全部文件", command=lambda: self.start_conversion(True),
|
||||
width=15).pack(side=tk.LEFT, padx=5)
|
||||
ttk.Button(button_frame, text="转换选中文件", command=lambda: self.start_conversion(False),
|
||||
width=15).pack(side=tk.LEFT, padx=5)
|
||||
|
||||
# 日志区域
|
||||
log_frame = ttk.LabelFrame(self.master, text="日志")
|
||||
log_frame.grid(row=5, column=0, padx=10, pady=5, sticky="nsew")
|
||||
|
||||
self.log_text = tk.Text(log_frame, height=14, width=80)
|
||||
self.log_text.pack(fill=tk.BOTH, expand=True)
|
||||
|
||||
# 配置布局权重
|
||||
self.master.columnconfigure(0, weight=1)
|
||||
self.master.rowconfigure(2, weight=1)
|
||||
self.master.rowconfigure(5, weight=3)
|
||||
file_frame.columnconfigure(0, weight=1)
|
||||
file_frame.rowconfigure(1, weight=1)
|
||||
|
||||
def toggle_settings(self):
|
||||
if self.mode.get() == "audio_to_ogg":
|
||||
self.loudnorm_frame.grid()
|
||||
else:
|
||||
self.loudnorm_frame.grid_remove()
|
||||
|
||||
def select_files(self):
|
||||
file_types = [
|
||||
("音频文件", "*.wav *.mogg *.ogg *.flac") if self.mode.get() == "audio_to_ogg"
|
||||
else ("ogg文件", "*.ogg")
|
||||
]
|
||||
|
||||
files = filedialog.askopenfilenames(filetypes=file_types)
|
||||
for f in files:
|
||||
self.tree.insert("", tk.END, values=("[ ]", os.path.basename(f)), tags=(f,))
|
||||
|
||||
def on_tree_click(self, event):
|
||||
"""处理复选框点击事件"""
|
||||
region = self.tree.identify("region", event.x, event.y)
|
||||
if region == "cell":
|
||||
col = self.tree.identify_column(event.x)
|
||||
item = self.tree.identify_row(event.y)
|
||||
if col == "#1": # 点击的是选中列
|
||||
current_val = self.tree.item(item, "values")[0]
|
||||
new_val = "[√]" if current_val == "[ ]" else "[ ]"
|
||||
self.tree.item(item, values=(new_val, self.tree.item(item, "values")[1]))
|
||||
|
||||
def remove_selected(self):
|
||||
"""移除选中的文件"""
|
||||
to_remove = []
|
||||
for item in self.tree.get_children():
|
||||
if self.tree.item(item, "values")[0] == "[√]":
|
||||
to_remove.append(item)
|
||||
for item in reversed(to_remove):
|
||||
self.tree.delete(item)
|
||||
|
||||
def clear_files(self):
|
||||
"""清空所有文件"""
|
||||
for item in self.tree.get_children():
|
||||
self.tree.delete(item)
|
||||
|
||||
def select_output_dir(self):
|
||||
path = filedialog.askdirectory()
|
||||
if path:
|
||||
self.output_dir.set(path)
|
||||
|
||||
def redirect_output(self):
|
||||
class StdoutRedirector:
|
||||
def __init__(self, text_widget):
|
||||
self.text_widget = text_widget
|
||||
self.original_stdout = sys.stdout
|
||||
|
||||
def write(self, message):
|
||||
self.text_widget.insert(tk.END, message)
|
||||
self.text_widget.see(tk.END)
|
||||
self.original_stdout.write(message)
|
||||
|
||||
def flush(self):
|
||||
self.original_stdout.flush()
|
||||
|
||||
sys.stdout = StdoutRedirector(self.log_text)
|
||||
|
||||
def start_conversion(self, convert_all):
|
||||
"""开始转换"""
|
||||
input_files = []
|
||||
for item in self.tree.get_children():
|
||||
if convert_all or self.tree.item(item, "values")[0] == "[√]":
|
||||
input_files.append(self.tree.item(item, "tags")[0])
|
||||
|
||||
if not input_files:
|
||||
msg = "没有找到可转换的文件" if convert_all else "没有选中任何文件"
|
||||
messagebox.showwarning("警告", msg)
|
||||
return
|
||||
|
||||
os.makedirs(self.output_dir.get(), exist_ok=True)
|
||||
|
||||
try:
|
||||
if self.mode.get() == "audio_to_ogg":
|
||||
target_lufs = self.target_lufs.get() if self.enable_loudnorm.get() else None
|
||||
thread = threading.Thread(target=self.convert_audio_to_ogg, args=(target_lufs, input_files))
|
||||
else:
|
||||
thread = threading.Thread(target=self.convert_ogg_to_audio, args=(input_files,))
|
||||
|
||||
thread.start()
|
||||
except Exception as e:
|
||||
print(f"转换初始化失败: {str(e)}")
|
||||
|
||||
def convert_audio_to_ogg(self, target_lufs, input_files):
|
||||
"""音频转到ogg转换逻辑"""
|
||||
for input_path in input_files:
|
||||
try:
|
||||
filename = os.path.basename(input_path)
|
||||
base_name = os.path.splitext(filename)[0]
|
||||
output_path = os.path.join(self.output_dir.get(), f"{base_name}.ogg")
|
||||
|
||||
print(f"正在转换: {filename}")
|
||||
(
|
||||
ffmpeg
|
||||
.input(input_path)
|
||||
.output(output_path, acodec='libopus', audio_bitrate='16k', ac=1, ar=16000, frame_duration=60)
|
||||
.run(overwrite_output=True)
|
||||
)
|
||||
print(f"转换成功: {filename}\n")
|
||||
except Exception as e:
|
||||
print(f"转换失败: {str(e)}\n")
|
||||
|
||||
def convert_ogg_to_audio(self, input_files):
|
||||
"""ogg转回音频转换逻辑"""
|
||||
for input_path in input_files:
|
||||
try:
|
||||
filename = os.path.basename(input_path)
|
||||
base_name = os.path.splitext(filename)[0]
|
||||
output_path = os.path.join(self.output_dir.get(), f"{base_name}.ogg")
|
||||
|
||||
print(f"正在转换: {filename}")
|
||||
(
|
||||
ffmpeg
|
||||
.input(input_path)
|
||||
.output(output_path, acodec='libopus', audio_bitrate='16k', ac=1, ar=16000, frame_duration=60)
|
||||
.run(overwrite_output=True)
|
||||
)
|
||||
print(f"转换成功: {filename}\n")
|
||||
except Exception as e:
|
||||
print(f"转换失败: {str(e)}\n")
|
||||
|
||||
if __name__ == "__main__":
|
||||
root = tk.Tk()
|
||||
app = AudioConverterApp(root)
|
||||
root.mainloop()
|
||||
@@ -47,6 +47,8 @@ CONFIG_LV_USE_CLIB_MALLOC=y
|
||||
CONFIG_LV_USE_CLIB_STRING=y
|
||||
CONFIG_LV_USE_CLIB_SPRINTF=y
|
||||
CONFIG_LV_USE_IMGFONT=y
|
||||
CONFIG_LV_USE_ASSERT_STYLE=y
|
||||
CONFIG_LV_USE_GIF=y
|
||||
|
||||
# Use compressed font
|
||||
CONFIG_LV_FONT_FMT_TXT_LARGE=y
|
||||
|
||||
Reference in New Issue
Block a user