esphome-api-client 0.5.0
Modern C++17 client for the ESPHome native API (plaintext + Noise)
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
esphome::api::VoiceAssistant Class Reference

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>

Inheritance diagram for esphome::api::VoiceAssistant:
Inheritance graph
[legend]
Collaboration diagram for esphome::api::VoiceAssistant:
Collaboration graph
[legend]

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
Clientclient_
 

Detailed Description

Drives the device's voice-assistant pipeline: subscribing to start/stop requests, relaying events and audio, announcing media, and managing the wake-word configuration.

Member Typedef Documentation

◆ AnnounceFinishedHandler

using esphome::api::VoiceAssistant::AnnounceFinishedHandler = std::function<void(bool )>

◆ AudioHandler

using esphome::api::VoiceAssistant::AudioHandler = std::function<void(const VoiceAudio&)>

◆ ConfigurationHandler

◆ EventHandler

using esphome::api::VoiceAssistant::EventHandler = std::function<void(const VoiceEvent&)>

◆ RequestHandler

using esphome::api::VoiceAssistant::RequestHandler = std::function<void(const VoiceRequest&)>

◆ TimerEventHandler

Constructor & Destructor Documentation

◆ VoiceAssistant()

esphome::api::VoiceAssistant::VoiceAssistant ( Client client)
inlineexplicit

Member Function Documentation

◆ announce()

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.

◆ on_announce_finished()

void esphome::api::VoiceAssistant::on_announce_finished ( AnnounceFinishedHandler  handler)

Register a callback fired when an announcement finishes.

◆ on_audio()

void esphome::api::VoiceAssistant::on_audio ( AudioHandler  handler)

Register a callback for inbound audio chunks (VoiceAssistantAudio).

◆ on_event()

void esphome::api::VoiceAssistant::on_event ( EventHandler  handler)

Register a callback for each pipeline event (VoiceAssistantEventResponse).

◆ on_timer_event()

void esphome::api::VoiceAssistant::on_timer_event ( TimerEventHandler  handler)

Register a callback for timer events (VoiceAssistantTimerEventResponse).

◆ request_configuration()

void esphome::api::VoiceAssistant::request_configuration ( ConfigurationHandler  handler)

Request the device's voice-assistant configuration.

handler receives the VoiceAssistantConfigurationResponse.

◆ send_audio()

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.

◆ send_response()

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.

◆ set_configuration()

void esphome::api::VoiceAssistant::set_configuration ( const std::vector< std::string > &  active_wake_words) const

Set the device's active wake words by id.

◆ subscribe()

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.


The documentation for this class was generated from the following file: