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:
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
// Generative Language API (Gemini): models/{model}:generateContent.
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "google/endpoints.h"
|
||||
#include "google/service.h"
|
||||
#include "google/voice_io.h"
|
||||
|
||||
namespace molo::google {
|
||||
|
||||
struct ChatMessage {
|
||||
std::string role; // "user" or "model"
|
||||
std::string text;
|
||||
};
|
||||
|
||||
struct GenerationRequest {
|
||||
std::string model; // Empty: GOOGLE_GENAI_MODEL or the built-in default.
|
||||
std::string system;
|
||||
std::vector<ChatMessage> messages;
|
||||
int max_output_tokens = 300;
|
||||
double temperature = 0.7;
|
||||
// Reasoning tokens count against max_output_tokens on thinking models and
|
||||
// can truncate a spoken reply. -1: model default; 0: no thinking.
|
||||
int thinking_budget = -1;
|
||||
};
|
||||
|
||||
class Generative : public Service {
|
||||
public:
|
||||
explicit Generative(std::shared_ptr<GoogleClient> client,
|
||||
ServiceEndpoint endpoint = endpoints::generative());
|
||||
|
||||
static std::string default_model();
|
||||
static std::string default_stt_model(); // GOOGLE_STT_MODEL, else default_model().
|
||||
static std::string default_tts_model(); // GOOGLE_TTS_MODEL, else gemini-2.5-flash-tts.
|
||||
static constexpr const char* kDefaultTtsVoice = "Kore";
|
||||
|
||||
std::string generate(const GenerationRequest& request) const;
|
||||
// Audio in, text out (Gemini audio understanding). Empty string: no speech.
|
||||
std::string transcribe(const std::string& model, const std::string& audio,
|
||||
const std::string& mime,
|
||||
const std::string& language) const;
|
||||
// Text in, spoken WAV out (Gemini TTS models return raw 24 kHz PCM).
|
||||
Audio speak(const std::string& model, const std::string& text,
|
||||
const std::string& voice) const;
|
||||
|
||||
private:
|
||||
clients::body::Json generate_content(const std::string& model,
|
||||
const clients::body::Json& body) const;
|
||||
};
|
||||
|
||||
} // namespace molo::google
|
||||
Reference in New Issue
Block a user