diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-07-19 13:59:30 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-07-19 13:59:30 +1000 |
| commit | 9475d10d1000c7e21a7ea311b0c8ee6a72ef46c4 (patch) | |
| tree | 099258a8107f75f14cf5b2f451f1d4008da1dfa4 /src/tangara/tts/provider.cpp | |
| parent | 370d1853b5d099de28c032def4ce3e53b7d735ad (diff) | |
| download | tangara-fw-9475d10d1000c7e21a7ea311b0c8ee6a72ef46c4.tar.gz | |
WIP initial tts player wiring
Diffstat (limited to 'src/tangara/tts/provider.cpp')
| -rw-r--r-- | src/tangara/tts/provider.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/tangara/tts/provider.cpp b/src/tangara/tts/provider.cpp index 7d33bae6..24229233 100644 --- a/src/tangara/tts/provider.cpp +++ b/src/tangara/tts/provider.cpp @@ -5,21 +5,40 @@ */ #include "tts/provider.hpp" +#include <stdint.h> +#include <ios> #include <optional> +#include <sstream> #include <string> #include <variant> +#include "drivers/storage.hpp" #include "esp_log.h" +#include "komihash.h" #include "tts/events.hpp" namespace tts { [[maybe_unused]] static constexpr char kTag[] = "tts"; +static const char* kTtsPath = "/.tangara-tts/"; + +static auto textToFile(const std::string& text) -> std::optional<std::string> { + uint64_t hash = komihash(text.data(), text.size(), 0); + std::stringstream stream; + stream << drivers::kStoragePath << kTtsPath; + stream << std::hex << hash; + return stream.str(); +} + Provider::Provider() {} +auto Provider::player(std::unique_ptr<Player> p) -> void { + player_ = std::move(p); +} + auto Provider::feed(const Event& e) -> void { if (std::holds_alternative<SimpleEvent>(e)) { // ESP_LOGI(kTag, "context changed"); @@ -31,6 +50,10 @@ auto Provider::feed(const Event& e) -> void { // ESP_LOGI(kTag, "new selection: '%s', interactive? %i", // ev.new_selection->description.value_or("").c_str(), // ev.new_selection->is_interactive); + std::string new_desc = ev.new_selection->description.value_or(""); + if (player_) { + player_->playFile(textToFile(new_desc).value_or("")); + } } } } |
