mirror of
https://github.com/78/xiaozhi-esp32.git
synced 2026-02-14 16:08:07 +00:00
Compare commits
2 Commits
fix_early_
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e34995944 | ||
|
|
fe66f39ecc |
@@ -6,6 +6,7 @@
|
||||
void NoAudioProcessor::Initialize(AudioCodec* codec, int frame_duration_ms, srmodel_list_t* models_list) {
|
||||
codec_ = codec;
|
||||
frame_samples_ = frame_duration_ms * 16000 / 1000;
|
||||
output_buffer_.reserve(frame_samples_);
|
||||
}
|
||||
|
||||
void NoAudioProcessor::Feed(std::vector<int16_t>&& data) {
|
||||
@@ -13,15 +14,25 @@ void NoAudioProcessor::Feed(std::vector<int16_t>&& data) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert stereo to mono if needed
|
||||
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);
|
||||
for (size_t i = 0, j = 0; i < mono_data.size(); ++i, j += 2) {
|
||||
mono_data[i] = data[j];
|
||||
for (size_t i = 0, j = 0; i < data.size() / 2; ++i, j += 2) {
|
||||
output_buffer_.push_back(data[j]);
|
||||
}
|
||||
output_callback_(std::move(mono_data));
|
||||
} else {
|
||||
output_callback_(std::move(data));
|
||||
output_buffer_.insert(output_buffer_.end(), data.begin(), data.end());
|
||||
}
|
||||
|
||||
// Output complete frames when buffer has enough data
|
||||
while (output_buffer_.size() >= (size_t)frame_samples_) {
|
||||
if (output_buffer_.size() == (size_t)frame_samples_) {
|
||||
output_callback_(std::move(output_buffer_));
|
||||
output_buffer_.clear();
|
||||
output_buffer_.reserve(frame_samples_);
|
||||
} else {
|
||||
output_callback_(std::vector<int16_t>(output_buffer_.begin(), output_buffer_.begin() + frame_samples_));
|
||||
output_buffer_.erase(output_buffer_.begin(), output_buffer_.begin() + frame_samples_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +42,7 @@ void NoAudioProcessor::Start() {
|
||||
|
||||
void NoAudioProcessor::Stop() {
|
||||
is_running_ = false;
|
||||
output_buffer_.clear();
|
||||
}
|
||||
|
||||
bool NoAudioProcessor::IsRunning() {
|
||||
|
||||
@@ -26,6 +26,7 @@ public:
|
||||
private:
|
||||
AudioCodec* codec_ = nullptr;
|
||||
int frame_samples_ = 0;
|
||||
std::vector<int16_t> output_buffer_;
|
||||
std::function<void(std::vector<int16_t>&& data)> output_callback_;
|
||||
std::function<void(bool speaking)> vad_state_change_callback_;
|
||||
std::atomic<bool> is_running_ = false;
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
"sdkconfig_append": [
|
||||
"CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y",
|
||||
"CONFIG_PARTITION_TABLE_CUSTOM_FILENAME=\"partitions/v2/16m.csv\"",
|
||||
"CONFIG_PM_ENABLE=y",
|
||||
"CONFIG_FREERTOS_USE_TICKLESS_IDLE=y",
|
||||
"CONFIG_SPIRAM_MODE_QUAD=y",
|
||||
"CONFIG_SPIRAM_SPEED_80M=y",
|
||||
|
||||
@@ -227,16 +227,19 @@ private:
|
||||
void InitializeBatteryMonitor() {
|
||||
adc_battery_monitor_ = new AdcBatteryMonitor(ADC_UNIT_1, ADC_CHANNEL_3, 5100000, 5100000, GPIO_NUM_NC);
|
||||
adc_battery_monitor_->OnChargingStatusChanged([this](bool is_charging) {
|
||||
if (is_charging) {
|
||||
power_save_timer_->SetEnabled(false);
|
||||
} else {
|
||||
power_save_timer_->SetEnabled(true);
|
||||
if (power_save_timer_ != nullptr){
|
||||
if (is_charging) {
|
||||
power_save_timer_->SetEnabled(false);
|
||||
} else {
|
||||
power_save_timer_->SetEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
void InitializePowerSaveTimer() {
|
||||
power_save_timer_ = new PowerSaveTimer(240, 300);
|
||||
power_save_timer_ = new PowerSaveTimer(240, -1, -1);
|
||||
power_save_timer_->OnEnterSleepMode([this]() {
|
||||
GetDisplay()->SetPowerSaveMode(true);
|
||||
});
|
||||
@@ -348,8 +351,8 @@ private:
|
||||
public:
|
||||
MovecallMoji2ESP32C5() : boot_button_(BOOT_BUTTON_GPIO) {
|
||||
InitializeCodecI2c();
|
||||
InitializeBatteryMonitor();
|
||||
InitializePowerSaveTimer();
|
||||
InitializeBatteryMonitor();
|
||||
InitializeSpi();
|
||||
InitializeSt77916Display();
|
||||
InitializeButtons();
|
||||
|
||||
@@ -174,11 +174,15 @@ void LvglDisplay::UpdateStatusBar(bool update_all) {
|
||||
lv_label_set_text(battery_label_, battery_icon_);
|
||||
}
|
||||
|
||||
if (low_battery_popup_ != nullptr) {
|
||||
// Check low battery popup only when clock tick event is triggered
|
||||
// Because when initializing, the battery level is not ready yet.
|
||||
if (low_battery_popup_ != nullptr && !update_all) {
|
||||
if (strcmp(icon, FONT_AWESOME_BATTERY_EMPTY) == 0 && discharging) {
|
||||
if (lv_obj_has_flag(low_battery_popup_, LV_OBJ_FLAG_HIDDEN)) { // Show if low battery popup is hidden
|
||||
lv_obj_remove_flag(low_battery_popup_, LV_OBJ_FLAG_HIDDEN);
|
||||
app.PlaySound(Lang::Sounds::OGG_LOW_BATTERY);
|
||||
app.Schedule([&app]() {
|
||||
app.PlaySound(Lang::Sounds::OGG_LOW_BATTERY);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Hide the low battery popup when the battery is not empty
|
||||
|
||||
Reference in New Issue
Block a user