1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-28 21:53:48 +00:00

Remote wake word support for voice assistant (#5229)

This commit is contained in:
Jesse Hills
2023-10-10 19:52:42 +13:00
committed by GitHub
parent 6b96089f02
commit 511af5845e
13 changed files with 744 additions and 211 deletions

View File

@@ -1413,6 +1413,18 @@ message SubscribeVoiceAssistantRequest {
bool subscribe = 1;
}
enum VoiceAssistantRequestFlag {
VOICE_ASSISTANT_REQUEST_NONE = 0;
VOICE_ASSISTANT_REQUEST_USE_VAD = 1;
VOICE_ASSISTANT_REQUEST_USE_WAKE_WORD = 2;
}
message VoiceAssistantAudioSettings {
uint32 noise_suppression_level = 1;
uint32 auto_gain = 2;
float volume_multiplier = 3;
}
message VoiceAssistantRequest {
option (id) = 90;
option (source) = SOURCE_SERVER;
@@ -1420,7 +1432,8 @@ message VoiceAssistantRequest {
bool start = 1;
string conversation_id = 2;
bool use_vad = 3;
uint32 flags = 3;
VoiceAssistantAudioSettings audio_settings = 4;
}
message VoiceAssistantResponse {
@@ -1442,6 +1455,10 @@ enum VoiceAssistantEvent {
VOICE_ASSISTANT_INTENT_END = 6;
VOICE_ASSISTANT_TTS_START = 7;
VOICE_ASSISTANT_TTS_END = 8;
VOICE_ASSISTANT_WAKE_WORD_START = 9;
VOICE_ASSISTANT_WAKE_WORD_END = 10;
VOICE_ASSISTANT_STT_VAD_START = 11;
VOICE_ASSISTANT_STT_VAD_END = 12;
}
message VoiceAssistantEventData {

View File

@@ -907,21 +907,22 @@ BluetoothConnectionsFreeResponse APIConnection::subscribe_bluetooth_connections_
#endif
#ifdef USE_VOICE_ASSISTANT
bool APIConnection::request_voice_assistant(bool start, const std::string &conversation_id, bool use_vad) {
bool APIConnection::request_voice_assistant(const VoiceAssistantRequest &msg) {
if (!this->voice_assistant_subscription_)
return false;
VoiceAssistantRequest msg;
msg.start = start;
msg.conversation_id = conversation_id;
msg.use_vad = use_vad;
return this->send_voice_assistant_request(msg);
}
void APIConnection::on_voice_assistant_response(const VoiceAssistantResponse &msg) {
if (voice_assistant::global_voice_assistant != nullptr) {
if (msg.error) {
voice_assistant::global_voice_assistant->failed_to_start();
return;
}
struct sockaddr_storage storage;
socklen_t len = sizeof(storage);
this->helper_->getpeername((struct sockaddr *) &storage, &len);
voice_assistant::global_voice_assistant->start(&storage, msg.port);
voice_assistant::global_voice_assistant->start_streaming(&storage, msg.port);
}
};
void APIConnection::on_voice_assistant_event_response(const VoiceAssistantEventResponse &msg) {

View File

@@ -124,7 +124,7 @@ class APIConnection : public APIServerConnection {
void subscribe_voice_assistant(const SubscribeVoiceAssistantRequest &msg) override {
this->voice_assistant_subscription_ = msg.subscribe;
}
bool request_voice_assistant(bool start, const std::string &conversation_id, bool use_vad);
bool request_voice_assistant(const VoiceAssistantRequest &msg);
void on_voice_assistant_response(const VoiceAssistantResponse &msg) override;
void on_voice_assistant_event_response(const VoiceAssistantEventResponse &msg) override;
#endif

View File

@@ -3,8 +3,6 @@
#include "api_pb2.h"
#include "esphome/core/log.h"
#include <cinttypes>
namespace esphome {
namespace api {
@@ -410,6 +408,20 @@ const char *proto_enum_to_string<enums::BluetoothDeviceRequestType>(enums::Bluet
}
#endif
#ifdef HAS_PROTO_MESSAGE_DUMP
template<> const char *proto_enum_to_string<enums::VoiceAssistantRequestFlag>(enums::VoiceAssistantRequestFlag value) {
switch (value) {
case enums::VOICE_ASSISTANT_REQUEST_NONE:
return "VOICE_ASSISTANT_REQUEST_NONE";
case enums::VOICE_ASSISTANT_REQUEST_USE_VAD:
return "VOICE_ASSISTANT_REQUEST_USE_VAD";
case enums::VOICE_ASSISTANT_REQUEST_USE_WAKE_WORD:
return "VOICE_ASSISTANT_REQUEST_USE_WAKE_WORD";
default:
return "UNKNOWN";
}
}
#endif
#ifdef HAS_PROTO_MESSAGE_DUMP
template<> const char *proto_enum_to_string<enums::VoiceAssistantEvent>(enums::VoiceAssistantEvent value) {
switch (value) {
case enums::VOICE_ASSISTANT_ERROR:
@@ -430,6 +442,14 @@ template<> const char *proto_enum_to_string<enums::VoiceAssistantEvent>(enums::V
return "VOICE_ASSISTANT_TTS_START";
case enums::VOICE_ASSISTANT_TTS_END:
return "VOICE_ASSISTANT_TTS_END";
case enums::VOICE_ASSISTANT_WAKE_WORD_START:
return "VOICE_ASSISTANT_WAKE_WORD_START";
case enums::VOICE_ASSISTANT_WAKE_WORD_END:
return "VOICE_ASSISTANT_WAKE_WORD_END";
case enums::VOICE_ASSISTANT_STT_VAD_START:
return "VOICE_ASSISTANT_STT_VAD_START";
case enums::VOICE_ASSISTANT_STT_VAD_END:
return "VOICE_ASSISTANT_STT_VAD_END";
default:
return "UNKNOWN";
}
@@ -524,12 +544,12 @@ void HelloRequest::dump_to(std::string &out) const {
out.append("\n");
out.append(" api_version_major: ");
sprintf(buffer, "%" PRIu32, this->api_version_major);
sprintf(buffer, "%u", this->api_version_major);
out.append(buffer);
out.append("\n");
out.append(" api_version_minor: ");
sprintf(buffer, "%" PRIu32, this->api_version_minor);
sprintf(buffer, "%u", this->api_version_minor);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -574,12 +594,12 @@ void HelloResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("HelloResponse {\n");
out.append(" api_version_major: ");
sprintf(buffer, "%" PRIu32, this->api_version_major);
sprintf(buffer, "%u", this->api_version_major);
out.append(buffer);
out.append("\n");
out.append(" api_version_minor: ");
sprintf(buffer, "%" PRIu32, this->api_version_minor);
sprintf(buffer, "%u", this->api_version_minor);
out.append(buffer);
out.append("\n");
@@ -785,17 +805,17 @@ void DeviceInfoResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" webserver_port: ");
sprintf(buffer, "%" PRIu32, this->webserver_port);
sprintf(buffer, "%u", this->webserver_port);
out.append(buffer);
out.append("\n");
out.append(" legacy_bluetooth_proxy_version: ");
sprintf(buffer, "%" PRIu32, this->legacy_bluetooth_proxy_version);
sprintf(buffer, "%u", this->legacy_bluetooth_proxy_version);
out.append(buffer);
out.append("\n");
out.append(" bluetooth_proxy_feature_flags: ");
sprintf(buffer, "%" PRIu32, this->bluetooth_proxy_feature_flags);
sprintf(buffer, "%u", this->bluetooth_proxy_feature_flags);
out.append(buffer);
out.append("\n");
@@ -808,7 +828,7 @@ void DeviceInfoResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" voice_assistant_version: ");
sprintf(buffer, "%" PRIu32, this->voice_assistant_version);
sprintf(buffer, "%u", this->voice_assistant_version);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -900,7 +920,7 @@ void ListEntitiesBinarySensorResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -968,7 +988,7 @@ void BinarySensorStateResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("BinarySensorStateResponse {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -1071,7 +1091,7 @@ void ListEntitiesCoverResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -1161,7 +1181,7 @@ void CoverStateResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("CoverStateResponse {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -1244,7 +1264,7 @@ void CoverCommandRequest::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("CoverCommandRequest {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -1364,7 +1384,7 @@ void ListEntitiesFanResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -1389,7 +1409,7 @@ void ListEntitiesFanResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" supported_speed_count: ");
sprintf(buffer, "%" PRId32, this->supported_speed_count);
sprintf(buffer, "%d", this->supported_speed_count);
out.append(buffer);
out.append("\n");
@@ -1456,7 +1476,7 @@ void FanStateResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("FanStateResponse {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -1477,7 +1497,7 @@ void FanStateResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" speed_level: ");
sprintf(buffer, "%" PRId32, this->speed_level);
sprintf(buffer, "%d", this->speed_level);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -1557,7 +1577,7 @@ void FanCommandRequest::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("FanCommandRequest {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -1598,7 +1618,7 @@ void FanCommandRequest::dump_to(std::string &out) const {
out.append("\n");
out.append(" speed_level: ");
sprintf(buffer, "%" PRId32, this->speed_level);
sprintf(buffer, "%d", this->speed_level);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -1712,7 +1732,7 @@ void ListEntitiesLightResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -1866,7 +1886,7 @@ void LightStateResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("LightStateResponse {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -2089,7 +2109,7 @@ void LightCommandRequest::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("LightCommandRequest {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -2187,7 +2207,7 @@ void LightCommandRequest::dump_to(std::string &out) const {
out.append("\n");
out.append(" transition_length: ");
sprintf(buffer, "%" PRIu32, this->transition_length);
sprintf(buffer, "%u", this->transition_length);
out.append(buffer);
out.append("\n");
@@ -2196,7 +2216,7 @@ void LightCommandRequest::dump_to(std::string &out) const {
out.append("\n");
out.append(" flash_length: ");
sprintf(buffer, "%" PRIu32, this->flash_length);
sprintf(buffer, "%u", this->flash_length);
out.append(buffer);
out.append("\n");
@@ -2304,7 +2324,7 @@ void ListEntitiesSensorResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -2325,7 +2345,7 @@ void ListEntitiesSensorResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" accuracy_decimals: ");
sprintf(buffer, "%" PRId32, this->accuracy_decimals);
sprintf(buffer, "%d", this->accuracy_decimals);
out.append(buffer);
out.append("\n");
@@ -2389,7 +2409,7 @@ void SensorStateResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("SensorStateResponse {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -2478,7 +2498,7 @@ void ListEntitiesSwitchResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -2541,7 +2561,7 @@ void SwitchStateResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("SwitchStateResponse {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -2580,7 +2600,7 @@ void SwitchCommandRequest::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("SwitchCommandRequest {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -2654,7 +2674,7 @@ void ListEntitiesTextSensorResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -2720,7 +2740,7 @@ void TextSensorStateResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("TextSensorStateResponse {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -3027,7 +3047,7 @@ void GetTimeResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("GetTimeResponse {\n");
out.append(" epoch_seconds: ");
sprintf(buffer, "%" PRIu32, this->epoch_seconds);
sprintf(buffer, "%u", this->epoch_seconds);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -3111,7 +3131,7 @@ void ListEntitiesServicesResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -3205,7 +3225,7 @@ void ExecuteServiceArgument::dump_to(std::string &out) const {
out.append("\n");
out.append(" legacy_int: ");
sprintf(buffer, "%" PRId32, this->legacy_int);
sprintf(buffer, "%d", this->legacy_int);
out.append(buffer);
out.append("\n");
@@ -3219,7 +3239,7 @@ void ExecuteServiceArgument::dump_to(std::string &out) const {
out.append("\n");
out.append(" int_: ");
sprintf(buffer, "%" PRId32, this->int_);
sprintf(buffer, "%d", this->int_);
out.append(buffer);
out.append("\n");
@@ -3231,7 +3251,7 @@ void ExecuteServiceArgument::dump_to(std::string &out) const {
for (const auto &it : this->int_array) {
out.append(" int_array: ");
sprintf(buffer, "%" PRId32, it);
sprintf(buffer, "%d", it);
out.append(buffer);
out.append("\n");
}
@@ -3282,7 +3302,7 @@ void ExecuteServiceRequest::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("ExecuteServiceRequest {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -3358,7 +3378,7 @@ void ListEntitiesCameraResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -3424,7 +3444,7 @@ void CameraImageResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("CameraImageResponse {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -3616,7 +3636,7 @@ void ListEntitiesClimateResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -3804,7 +3824,7 @@ void ClimateStateResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("ClimateStateResponse {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -3992,7 +4012,7 @@ void ClimateCommandRequest::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("ClimateCommandRequest {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -4175,7 +4195,7 @@ void ListEntitiesNumberResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -4262,7 +4282,7 @@ void NumberStateResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("NumberStateResponse {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -4300,7 +4320,7 @@ void NumberCommandRequest::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("NumberCommandRequest {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -4382,7 +4402,7 @@ void ListEntitiesSelectResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -4454,7 +4474,7 @@ void SelectStateResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("SelectStateResponse {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -4497,7 +4517,7 @@ void SelectCommandRequest::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("SelectCommandRequest {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -4591,7 +4611,7 @@ void ListEntitiesLockResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -4662,7 +4682,7 @@ void LockStateResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("LockStateResponse {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -4717,7 +4737,7 @@ void LockCommandRequest::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("LockCommandRequest {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -4804,7 +4824,7 @@ void ListEntitiesButtonResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -4850,7 +4870,7 @@ void ButtonCommandRequest::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("ButtonCommandRequest {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -4925,7 +4945,7 @@ void ListEntitiesMediaPlayerResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -4994,7 +5014,7 @@ void MediaPlayerStateResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("MediaPlayerStateResponse {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -5073,7 +5093,7 @@ void MediaPlayerCommandRequest::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("MediaPlayerCommandRequest {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -5122,7 +5142,7 @@ void SubscribeBluetoothLEAdvertisementsRequest::dump_to(std::string &out) const
__attribute__((unused)) char buffer[64];
out.append("SubscribeBluetoothLEAdvertisementsRequest {\n");
out.append(" flags: ");
sprintf(buffer, "%" PRIu32, this->flags);
sprintf(buffer, "%u", this->flags);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -5169,7 +5189,7 @@ void BluetoothServiceData::dump_to(std::string &out) const {
for (const auto &it : this->legacy_data) {
out.append(" legacy_data: ");
sprintf(buffer, "%" PRIu32, it);
sprintf(buffer, "%u", it);
out.append(buffer);
out.append("\n");
}
@@ -5249,7 +5269,7 @@ void BluetoothLEAdvertisementResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" rssi: ");
sprintf(buffer, "%" PRId32, this->rssi);
sprintf(buffer, "%d", this->rssi);
out.append(buffer);
out.append("\n");
@@ -5272,7 +5292,7 @@ void BluetoothLEAdvertisementResponse::dump_to(std::string &out) const {
}
out.append(" address_type: ");
sprintf(buffer, "%" PRIu32, this->address_type);
sprintf(buffer, "%u", this->address_type);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -5322,12 +5342,12 @@ void BluetoothLERawAdvertisement::dump_to(std::string &out) const {
out.append("\n");
out.append(" rssi: ");
sprintf(buffer, "%" PRId32, this->rssi);
sprintf(buffer, "%d", this->rssi);
out.append(buffer);
out.append("\n");
out.append(" address_type: ");
sprintf(buffer, "%" PRIu32, this->address_type);
sprintf(buffer, "%u", this->address_type);
out.append(buffer);
out.append("\n");
@@ -5410,7 +5430,7 @@ void BluetoothDeviceRequest::dump_to(std::string &out) const {
out.append("\n");
out.append(" address_type: ");
sprintf(buffer, "%" PRIu32, this->address_type);
sprintf(buffer, "%u", this->address_type);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -5458,12 +5478,12 @@ void BluetoothDeviceConnectionResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" mtu: ");
sprintf(buffer, "%" PRIu32, this->mtu);
sprintf(buffer, "%u", this->mtu);
out.append(buffer);
out.append("\n");
out.append(" error: ");
sprintf(buffer, "%" PRId32, this->error);
sprintf(buffer, "%d", this->error);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -5523,7 +5543,7 @@ void BluetoothGATTDescriptor::dump_to(std::string &out) const {
}
out.append(" handle: ");
sprintf(buffer, "%" PRIu32, this->handle);
sprintf(buffer, "%u", this->handle);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -5579,12 +5599,12 @@ void BluetoothGATTCharacteristic::dump_to(std::string &out) const {
}
out.append(" handle: ");
sprintf(buffer, "%" PRIu32, this->handle);
sprintf(buffer, "%u", this->handle);
out.append(buffer);
out.append("\n");
out.append(" properties: ");
sprintf(buffer, "%" PRIu32, this->properties);
sprintf(buffer, "%u", this->properties);
out.append(buffer);
out.append("\n");
@@ -5641,7 +5661,7 @@ void BluetoothGATTService::dump_to(std::string &out) const {
}
out.append(" handle: ");
sprintf(buffer, "%" PRIu32, this->handle);
sprintf(buffer, "%u", this->handle);
out.append(buffer);
out.append("\n");
@@ -5748,7 +5768,7 @@ void BluetoothGATTReadRequest::dump_to(std::string &out) const {
out.append("\n");
out.append(" handle: ");
sprintf(buffer, "%" PRIu32, this->handle);
sprintf(buffer, "%u", this->handle);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -5793,7 +5813,7 @@ void BluetoothGATTReadResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" handle: ");
sprintf(buffer, "%" PRIu32, this->handle);
sprintf(buffer, "%u", this->handle);
out.append(buffer);
out.append("\n");
@@ -5847,7 +5867,7 @@ void BluetoothGATTWriteRequest::dump_to(std::string &out) const {
out.append("\n");
out.append(" handle: ");
sprintf(buffer, "%" PRIu32, this->handle);
sprintf(buffer, "%u", this->handle);
out.append(buffer);
out.append("\n");
@@ -5889,7 +5909,7 @@ void BluetoothGATTReadDescriptorRequest::dump_to(std::string &out) const {
out.append("\n");
out.append(" handle: ");
sprintf(buffer, "%" PRIu32, this->handle);
sprintf(buffer, "%u", this->handle);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -5934,7 +5954,7 @@ void BluetoothGATTWriteDescriptorRequest::dump_to(std::string &out) const {
out.append("\n");
out.append(" handle: ");
sprintf(buffer, "%" PRIu32, this->handle);
sprintf(buffer, "%u", this->handle);
out.append(buffer);
out.append("\n");
@@ -5977,7 +5997,7 @@ void BluetoothGATTNotifyRequest::dump_to(std::string &out) const {
out.append("\n");
out.append(" handle: ");
sprintf(buffer, "%" PRIu32, this->handle);
sprintf(buffer, "%u", this->handle);
out.append(buffer);
out.append("\n");
@@ -6026,7 +6046,7 @@ void BluetoothGATTNotifyDataResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" handle: ");
sprintf(buffer, "%" PRIu32, this->handle);
sprintf(buffer, "%u", this->handle);
out.append(buffer);
out.append("\n");
@@ -6065,12 +6085,12 @@ void BluetoothConnectionsFreeResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("BluetoothConnectionsFreeResponse {\n");
out.append(" free: ");
sprintf(buffer, "%" PRIu32, this->free);
sprintf(buffer, "%u", this->free);
out.append(buffer);
out.append("\n");
out.append(" limit: ");
sprintf(buffer, "%" PRIu32, this->limit);
sprintf(buffer, "%u", this->limit);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -6109,12 +6129,12 @@ void BluetoothGATTErrorResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" handle: ");
sprintf(buffer, "%" PRIu32, this->handle);
sprintf(buffer, "%u", this->handle);
out.append(buffer);
out.append("\n");
out.append(" error: ");
sprintf(buffer, "%" PRId32, this->error);
sprintf(buffer, "%d", this->error);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -6148,7 +6168,7 @@ void BluetoothGATTWriteResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" handle: ");
sprintf(buffer, "%" PRIu32, this->handle);
sprintf(buffer, "%u", this->handle);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -6182,7 +6202,7 @@ void BluetoothGATTNotifyResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" handle: ");
sprintf(buffer, "%" PRIu32, this->handle);
sprintf(buffer, "%u", this->handle);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -6225,7 +6245,7 @@ void BluetoothDevicePairingResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" error: ");
sprintf(buffer, "%" PRId32, this->error);
sprintf(buffer, "%d", this->error);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -6268,7 +6288,7 @@ void BluetoothDeviceUnpairingResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" error: ");
sprintf(buffer, "%" PRId32, this->error);
sprintf(buffer, "%d", this->error);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -6317,7 +6337,7 @@ void BluetoothDeviceClearCacheResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" error: ");
sprintf(buffer, "%" PRId32, this->error);
sprintf(buffer, "%d", this->error);
out.append(buffer);
out.append("\n");
out.append("}");
@@ -6344,6 +6364,56 @@ void SubscribeVoiceAssistantRequest::dump_to(std::string &out) const {
out.append("}");
}
#endif
bool VoiceAssistantAudioSettings::decode_varint(uint32_t field_id, ProtoVarInt value) {
switch (field_id) {
case 1: {
this->noise_suppression_level = value.as_uint32();
return true;
}
case 2: {
this->auto_gain = value.as_uint32();
return true;
}
default:
return false;
}
}
bool VoiceAssistantAudioSettings::decode_32bit(uint32_t field_id, Proto32Bit value) {
switch (field_id) {
case 3: {
this->volume_multiplier = value.as_float();
return true;
}
default:
return false;
}
}
void VoiceAssistantAudioSettings::encode(ProtoWriteBuffer buffer) const {
buffer.encode_uint32(1, this->noise_suppression_level);
buffer.encode_uint32(2, this->auto_gain);
buffer.encode_float(3, this->volume_multiplier);
}
#ifdef HAS_PROTO_MESSAGE_DUMP
void VoiceAssistantAudioSettings::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("VoiceAssistantAudioSettings {\n");
out.append(" noise_suppression_level: ");
sprintf(buffer, "%u", this->noise_suppression_level);
out.append(buffer);
out.append("\n");
out.append(" auto_gain: ");
sprintf(buffer, "%u", this->auto_gain);
out.append(buffer);
out.append("\n");
out.append(" volume_multiplier: ");
sprintf(buffer, "%g", this->volume_multiplier);
out.append(buffer);
out.append("\n");
out.append("}");
}
#endif
bool VoiceAssistantRequest::decode_varint(uint32_t field_id, ProtoVarInt value) {
switch (field_id) {
case 1: {
@@ -6351,7 +6421,7 @@ bool VoiceAssistantRequest::decode_varint(uint32_t field_id, ProtoVarInt value)
return true;
}
case 3: {
this->use_vad = value.as_bool();
this->flags = value.as_uint32();
return true;
}
default:
@@ -6364,6 +6434,10 @@ bool VoiceAssistantRequest::decode_length(uint32_t field_id, ProtoLengthDelimite
this->conversation_id = value.as_string();
return true;
}
case 4: {
this->audio_settings = value.as_message<VoiceAssistantAudioSettings>();
return true;
}
default:
return false;
}
@@ -6371,7 +6445,8 @@ bool VoiceAssistantRequest::decode_length(uint32_t field_id, ProtoLengthDelimite
void VoiceAssistantRequest::encode(ProtoWriteBuffer buffer) const {
buffer.encode_bool(1, this->start);
buffer.encode_string(2, this->conversation_id);
buffer.encode_bool(3, this->use_vad);
buffer.encode_uint32(3, this->flags);
buffer.encode_message<VoiceAssistantAudioSettings>(4, this->audio_settings);
}
#ifdef HAS_PROTO_MESSAGE_DUMP
void VoiceAssistantRequest::dump_to(std::string &out) const {
@@ -6385,8 +6460,13 @@ void VoiceAssistantRequest::dump_to(std::string &out) const {
out.append("'").append(this->conversation_id).append("'");
out.append("\n");
out.append(" use_vad: ");
out.append(YESNO(this->use_vad));
out.append(" flags: ");
sprintf(buffer, "%u", this->flags);
out.append(buffer);
out.append("\n");
out.append(" audio_settings: ");
this->audio_settings.dump_to(out);
out.append("\n");
out.append("}");
}
@@ -6414,7 +6494,7 @@ void VoiceAssistantResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("VoiceAssistantResponse {\n");
out.append(" port: ");
sprintf(buffer, "%" PRIu32, this->port);
sprintf(buffer, "%u", this->port);
out.append(buffer);
out.append("\n");
@@ -6577,7 +6657,7 @@ void ListEntitiesAlarmControlPanelResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -6602,7 +6682,7 @@ void ListEntitiesAlarmControlPanelResponse::dump_to(std::string &out) const {
out.append("\n");
out.append(" supported_features: ");
sprintf(buffer, "%" PRIu32, this->supported_features);
sprintf(buffer, "%u", this->supported_features);
out.append(buffer);
out.append("\n");
@@ -6645,7 +6725,7 @@ void AlarmControlPanelStateResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("AlarmControlPanelStateResponse {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");
@@ -6695,7 +6775,7 @@ void AlarmControlPanelCommandRequest::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("AlarmControlPanelCommandRequest {\n");
out.append(" key: ");
sprintf(buffer, "%" PRIu32, this->key);
sprintf(buffer, "%u", this->key);
out.append(buffer);
out.append("\n");

View File

@@ -165,6 +165,11 @@ enum BluetoothDeviceRequestType : uint32_t {
BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT_V3_WITHOUT_CACHE = 5,
BLUETOOTH_DEVICE_REQUEST_TYPE_CLEAR_CACHE = 6,
};
enum VoiceAssistantRequestFlag : uint32_t {
VOICE_ASSISTANT_REQUEST_NONE = 0,
VOICE_ASSISTANT_REQUEST_USE_VAD = 1,
VOICE_ASSISTANT_REQUEST_USE_WAKE_WORD = 2,
};
enum VoiceAssistantEvent : uint32_t {
VOICE_ASSISTANT_ERROR = 0,
VOICE_ASSISTANT_RUN_START = 1,
@@ -175,6 +180,10 @@ enum VoiceAssistantEvent : uint32_t {
VOICE_ASSISTANT_INTENT_END = 6,
VOICE_ASSISTANT_TTS_START = 7,
VOICE_ASSISTANT_TTS_END = 8,
VOICE_ASSISTANT_WAKE_WORD_START = 9,
VOICE_ASSISTANT_WAKE_WORD_END = 10,
VOICE_ASSISTANT_STT_VAD_START = 11,
VOICE_ASSISTANT_STT_VAD_END = 12,
};
enum AlarmControlPanelState : uint32_t {
ALARM_STATE_DISARMED = 0,
@@ -1651,11 +1660,26 @@ class SubscribeVoiceAssistantRequest : public ProtoMessage {
protected:
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
};
class VoiceAssistantAudioSettings : public ProtoMessage {
public:
uint32_t noise_suppression_level{0};
uint32_t auto_gain{0};
float volume_multiplier{0.0f};
void encode(ProtoWriteBuffer buffer) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP
void dump_to(std::string &out) const override;
#endif
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
};
class VoiceAssistantRequest : public ProtoMessage {
public:
bool start{false};
std::string conversation_id{};
bool use_vad{false};
uint32_t flags{0};
VoiceAssistantAudioSettings audio_settings{};
void encode(ProtoWriteBuffer buffer) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP
void dump_to(std::string &out) const override;

View File

@@ -1,13 +1,13 @@
#include "api_server.h"
#include <cerrno>
#include "api_connection.h"
#include "esphome/components/network/util.h"
#include "esphome/core/application.h"
#include "esphome/core/defines.h"
#include "esphome/core/hal.h"
#include "esphome/core/log.h"
#include "esphome/core/util.h"
#include "esphome/core/version.h"
#include "esphome/core/hal.h"
#include "esphome/components/network/util.h"
#include <cerrno>
#ifdef USE_LOGGER
#include "esphome/components/logger/logger.h"
@@ -323,16 +323,24 @@ void APIServer::on_shutdown() {
}
#ifdef USE_VOICE_ASSISTANT
bool APIServer::start_voice_assistant(const std::string &conversation_id, bool use_vad) {
bool APIServer::start_voice_assistant(const std::string &conversation_id, uint32_t flags,
const api::VoiceAssistantAudioSettings &audio_settings) {
VoiceAssistantRequest msg;
msg.start = true;
msg.conversation_id = conversation_id;
msg.flags = flags;
msg.audio_settings = audio_settings;
for (auto &c : this->clients_) {
if (c->request_voice_assistant(true, conversation_id, use_vad))
if (c->request_voice_assistant(msg))
return true;
}
return false;
}
void APIServer::stop_voice_assistant() {
VoiceAssistantRequest msg;
msg.start = false;
for (auto &c : this->clients_) {
if (c->request_voice_assistant(false, "", false))
if (c->request_voice_assistant(msg))
return;
}
}

View File

@@ -1,16 +1,16 @@
#pragma once
#include "api_noise_context.h"
#include "api_pb2.h"
#include "api_pb2_service.h"
#include "esphome/components/socket/socket.h"
#include "esphome/core/component.h"
#include "esphome/core/controller.h"
#include "esphome/core/defines.h"
#include "esphome/core/log.h"
#include "esphome/components/socket/socket.h"
#include "api_pb2.h"
#include "api_pb2_service.h"
#include "list_entities.h"
#include "subscribe_state.h"
#include "user_services.h"
#include "api_noise_context.h"
#include <vector>
@@ -81,7 +81,8 @@ class APIServer : public Component, public Controller {
#endif
#ifdef USE_VOICE_ASSISTANT
bool start_voice_assistant(const std::string &conversation_id, bool use_vad);
bool start_voice_assistant(const std::string &conversation_id, uint32_t flags,
const api::VoiceAssistantAudioSettings &audio_settings);
void stop_voice_assistant();
#endif