Files
moloapp/src/google/voice_io.h
T
retoorandClaude Sonnet 5.5 837de58136 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>
2026-10-24 04:05:41 +02:00

64 lines
1.9 KiB
C++

#pragma once
// The two speech seams of a voice pipeline. Backends implement them:
// classic Cloud TTS/STT (TextToSpeech, SpeechToText) or Gemini audio
// (GeminiSynthesizer, GeminiRecognizer). Callers never know which.
#include <string>
namespace molo::google {
enum class AudioEncoding { kMp3, kLinear16, kOggOpus };
const char* audio_encoding_name(AudioEncoding encoding); // Google enum name.
const char* audio_encoding_mime(AudioEncoding encoding);
struct SynthesisRequest {
std::string text;
bool ssml = false; // Classic Cloud TTS only.
std::string language = "nl-NL";
std::string voice; // Empty: backend default.
AudioEncoding encoding = AudioEncoding::kMp3; // Classic Cloud TTS only.
double speaking_rate = 1.0; // 0.25 .. 4.0, classic Cloud TTS only.
};
struct Audio {
std::string bytes;
std::string mime;
};
enum class SpeechEncoding { kWebmOpus, kOggOpus, kFlac, kLinear16, kMp3 };
const char* speech_encoding_name(SpeechEncoding encoding); // Google enum name.
const char* speech_encoding_mime(SpeechEncoding encoding); // Content type.
// Maps a browser/content type ("audio/webm;codecs=opus", "audio/ogg", ...)
// to an encoding. Returns false when unknown.
bool speech_encoding_from_mime(const std::string& mime, SpeechEncoding& out);
struct RecognitionRequest {
std::string audio; // Raw bytes.
SpeechEncoding encoding = SpeechEncoding::kWebmOpus;
std::string language = "nl-NL";
int sample_rate_hz = 0; // 0: taken from the container header.
bool punctuation = true;
};
struct Transcript {
std::string text;
double confidence = 0.0; // 0 when the backend does not report one.
};
class Synthesizer {
public:
virtual ~Synthesizer() = default;
virtual Audio synthesize(const SynthesisRequest& request) const = 0;
};
class Recognizer {
public:
virtual ~Recognizer() = default;
virtual Transcript recognize(const RecognitionRequest& request) const = 0;
};
} // namespace molo::google