fix: resolve some audio issues on esp-hi (#1027)

* fix: resolve crash when closing codec dev on esp-hi

* fix: fix incorrect status display in non-zh-CN languages

* fix: reduce noise when not in Speaking state
This commit is contained in:
laride
2025-08-19 11:50:00 +08:00
committed by GitHub
parent 156eb15f58
commit 2d772dad68
5 changed files with 20 additions and 7 deletions

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -33,7 +33,7 @@ dependencies:
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