[voice_assistant] Eliminate substr() allocations in text truncation (#11725)

This commit is contained in:
J. Nick Koston
2025-11-05 09:15:05 -06:00
committed by GitHub
parent 6b522dfee6
commit 6e2dbbf636

View File

@@ -657,7 +657,8 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
ESP_LOGW(TAG, "No text in STT_END event");
return;
} else if (text.length() > 500) {
text = text.substr(0, 497) + "...";
text.resize(497);
text += "...";
}
ESP_LOGD(TAG, "Speech recognised as: \"%s\"", text.c_str());
this->defer([this, text]() { this->stt_end_trigger_->trigger(text); });
@@ -714,7 +715,8 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
return;
}
if (text.length() > 500) {
text = text.substr(0, 497) + "...";
text.resize(497);
text += "...";
}
ESP_LOGD(TAG, "Response: \"%s\"", text.c_str());
this->defer([this, text]() {