|
esphome-api-client 0.5.0
Modern C++17 client for the ESPHome native API (plaintext + Noise)
|
Drives the device's voice-assistant pipeline: subscribing to start/stop requests, relaying events and audio, announcing media, and managing the wake-word configuration. More...
#include <voice_assistant.hpp>


Public Types | |
| using | RequestHandler = std::function< void(const VoiceRequest &)> |
| using | EventHandler = std::function< void(const VoiceEvent &)> |
| using | AudioHandler = std::function< void(const VoiceAudio &)> |
| using | AnnounceFinishedHandler = std::function< void(bool)> |
| using | ConfigurationHandler = std::function< void(const VoiceConfiguration &)> |
| using | TimerEventHandler = std::function< void(const VoiceTimerEvent &)> |
Public Member Functions | |
| VoiceAssistant (Client &client) | |
| void | subscribe (VoiceAssistantSubscribeFlag flags, RequestHandler handler, bool subscribe=true) |
| Subscribe to (or unsubscribe from) the device's voice-assistant requests. | |
| void | on_event (EventHandler handler) |
| Register a callback for each pipeline event (VoiceAssistantEventResponse). | |
| void | send_response (std::uint32_t port, bool error=false) const |
Reply to a start request, telling the device which UDP port to stream audio to (0 when streaming over the API), or that an error occurred. | |
| void | on_audio (AudioHandler handler) |
| Register a callback for inbound audio chunks (VoiceAssistantAudio). | |
| void | send_audio (ByteView data, bool end=false) const |
Stream an audio chunk to the device. Set end on the final chunk. | |
| void | announce (const std::string &media_id, const std::string &text={}, const std::string &preannounce_media_id={}, bool start_conversation=false) const |
| Ask the device to announce media and/or text. | |
| void | on_announce_finished (AnnounceFinishedHandler handler) |
| Register a callback fired when an announcement finishes. | |
| void | request_configuration (ConfigurationHandler handler) |
| Request the device's voice-assistant configuration. | |
| void | set_configuration (const std::vector< std::string > &active_wake_words) const |
| Set the device's active wake words by id. | |
| void | on_timer_event (TimerEventHandler handler) |
| Register a callback for timer events (VoiceAssistantTimerEventResponse). | |
Public Member Functions inherited from esphome::api::Subsystem | |
| Subsystem (Client &client) | |
Additional Inherited Members | |
Protected Attributes inherited from esphome::api::Subsystem | |
| Client & | client_ |
Drives the device's voice-assistant pipeline: subscribing to start/stop requests, relaying events and audio, announcing media, and managing the wake-word configuration.
| using esphome::api::VoiceAssistant::AnnounceFinishedHandler = std::function<void(bool )> |
| using esphome::api::VoiceAssistant::AudioHandler = std::function<void(const VoiceAudio&)> |
| using esphome::api::VoiceAssistant::ConfigurationHandler = std::function<void(const VoiceConfiguration&)> |
| using esphome::api::VoiceAssistant::EventHandler = std::function<void(const VoiceEvent&)> |
| using esphome::api::VoiceAssistant::RequestHandler = std::function<void(const VoiceRequest&)> |
| using esphome::api::VoiceAssistant::TimerEventHandler = std::function<void(const VoiceTimerEvent&)> |
|
inlineexplicit |
| void esphome::api::VoiceAssistant::announce | ( | const std::string & | media_id, |
| const std::string & | text = {}, |
||
| const std::string & | preannounce_media_id = {}, |
||
| bool | start_conversation = false |
||
| ) | const |
Ask the device to announce media and/or text.
start_conversation begins a pipeline run once the announcement finishes.
| void esphome::api::VoiceAssistant::on_announce_finished | ( | AnnounceFinishedHandler | handler | ) |
Register a callback fired when an announcement finishes.
| void esphome::api::VoiceAssistant::on_audio | ( | AudioHandler | handler | ) |
Register a callback for inbound audio chunks (VoiceAssistantAudio).
| void esphome::api::VoiceAssistant::on_event | ( | EventHandler | handler | ) |
Register a callback for each pipeline event (VoiceAssistantEventResponse).
| void esphome::api::VoiceAssistant::on_timer_event | ( | TimerEventHandler | handler | ) |
Register a callback for timer events (VoiceAssistantTimerEventResponse).
| void esphome::api::VoiceAssistant::request_configuration | ( | ConfigurationHandler | handler | ) |
Request the device's voice-assistant configuration.
handler receives the VoiceAssistantConfigurationResponse.
| void esphome::api::VoiceAssistant::send_audio | ( | ByteView | data, |
| bool | end = false |
||
| ) | const |
Stream an audio chunk to the device. Set end on the final chunk.
| void esphome::api::VoiceAssistant::send_response | ( | std::uint32_t | port, |
| bool | error = false |
||
| ) | const |
Reply to a start request, telling the device which UDP port to stream audio to (0 when streaming over the API), or that an error occurred.
| void esphome::api::VoiceAssistant::set_configuration | ( | const std::vector< std::string > & | active_wake_words | ) | const |
Set the device's active wake words by id.
| void esphome::api::VoiceAssistant::subscribe | ( | VoiceAssistantSubscribeFlag | flags, |
| RequestHandler | handler, | ||
| bool | subscribe = true |
||
| ) |
Subscribe to (or unsubscribe from) the device's voice-assistant requests.
flags selects optional features such as API audio. handler receives each VoiceRequest the device sends.