feat(clients): google cloud voice: generic client, TTS, STT, Gemini audio, live voice page

src/google: GoogleClient over molo::clients (key in x-goog-api-key, never in
URLs), Service base, TextToSpeech, SpeechToText, Generative (replies, audio
in, audio out), Recognizer/Synthesizer seams with cloud, gemini and vertex
backends, VoicePipeline with bounded history. Example: /voice live
conversation page, /voice/{say,hear,turn,reset}, /google/status. Keys load
from env, .env.json.local, .env.json. Paid routes are excluded from locust.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 04:05:41 +02:00
co-authored by Claude Sonnet 5.5
parent dd773d3015
commit 837de58136
54 changed files with 3086 additions and 21 deletions
+55
View File
@@ -0,0 +1,55 @@
#include "google/credentials.h"
#include <cstdlib>
#include <fstream>
#include <sstream>
#include "clients/body/json.h"
namespace molo::google {
std::shared_ptr<clients::Auth> Credentials::api_key(std::string key) {
return std::make_shared<clients::ApiKeyAuth>(std::move(key), "x-goog-api-key");
}
std::shared_ptr<clients::Auth> Credentials::bearer(std::string token) {
return std::make_shared<clients::BearerAuth>(std::move(token));
}
namespace {
constexpr std::size_t kMaxConfigBytes = 64 * 1024;
// String value of `name` in a flat JSON object file, or empty (missing,
// oversized, malformed, or not a string: all treated as "not set").
std::string from_json_file(const char* path, const char* name) {
std::ifstream in(path, std::ios::binary);
if (!in) return "";
std::ostringstream text;
text << in.rdbuf();
if (text.str().size() > kMaxConfigBytes) return "";
try {
clients::body::Json doc = clients::body::Json::parse(text.str());
const clients::body::Json* v = doc.is_object() ? doc.find(name) : nullptr;
return v && v->is_string() ? v->as_string() : "";
} catch (const std::exception&) {
return "";
}
}
} // namespace
// Order: process environment, then .env.json.local (git-ignored, for
// secrets), then .env.json, both in the working directory.
std::string Credentials::env(const char* name) {
if (const char* v = std::getenv(name); v && *v) return v;
std::string local = from_json_file(".env.json.local", name);
if (!local.empty()) return local;
return from_json_file(".env.json", name);
}
std::shared_ptr<clients::Auth> Credentials::from_env(const char* name) {
std::string key = env(name);
if (key.empty()) return nullptr;
return api_key(std::move(key));
}
} // namespace molo::google