1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-29 22:24:26 +00:00

Speaker support (#4743)

This commit is contained in:
Jesse Hills
2023-05-08 10:36:17 +12:00
committed by GitHub
parent 3498aade85
commit ce8a77c765
17 changed files with 622 additions and 19 deletions

View File

@@ -2,23 +2,44 @@
#include "esphome/core/automation.h"
#include "esphome/core/component.h"
#include "esphome/core/defines.h"
#include "esphome/core/helpers.h"
#include "esphome/components/api/api_pb2.h"
#include "esphome/components/api/api_server.h"
#include "esphome/components/microphone/microphone.h"
#ifdef USE_SPEAKER
#include "esphome/components/speaker/speaker.h"
#endif
#include "esphome/components/socket/socket.h"
namespace esphome {
namespace voice_assistant {
// Version 1: Initial version
// Version 2: Adds raw speaker support
static const uint32_t INITIAL_VERSION = 1;
static const uint32_t SPEAKER_SUPPORT = 2;
class VoiceAssistant : public Component {
public:
void setup() override;
void loop() override;
float get_setup_priority() const override;
void start(struct sockaddr_storage *addr, uint16_t port);
void set_microphone(microphone::Microphone *mic) { this->mic_ = mic; }
#ifdef USE_SPEAKER
void set_speaker(speaker::Speaker *speaker) { this->speaker_ = speaker; }
#endif
uint32_t get_version() const {
#ifdef USE_SPEAKER
if (this->speaker_ != nullptr)
return SPEAKER_SUPPORT;
#endif
return INITIAL_VERSION;
}
void request_start();
void signal_stop();
@@ -44,6 +65,9 @@ class VoiceAssistant : public Component {
Trigger<std::string, std::string> *error_trigger_ = new Trigger<std::string, std::string>();
microphone::Microphone *mic_{nullptr};
#ifdef USE_SPEAKER
speaker::Speaker *speaker_{nullptr};
#endif
bool running_{false};
};