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>
45 lines
2.0 KiB
C++
45 lines
2.0 KiB
C++
// Route: POST /voice/turn (Gemini audio backend: Vertex express key)
|
|
#include "support/GoogleRig.hpp"
|
|
|
|
using namespace molo::example::test;
|
|
|
|
int main() {
|
|
setenv("GOOGLE_GENAI_MODEL", "chat-m", 1);
|
|
setenv("GOOGLE_STT_MODEL", "stt-m", 1);
|
|
setenv("GOOGLE_TTS_MODEL", "tts-m", 1);
|
|
GoogleRig rig;
|
|
const std::string p = "/v1/publishers/google/models/";
|
|
auto text = [&](const std::string& model, const std::string& t) {
|
|
rig.mock->expect_response(
|
|
molo::clients::Method::kPost, p + model + ":generateContent",
|
|
GoogleRig::json("{\"candidates\":[{\"content\":{\"parts\":[{\"text\":\"" +
|
|
t + "\"}]}}]}"));
|
|
};
|
|
text("stt-m", "hallo daar");
|
|
text("chat-m", "Hoi!");
|
|
rig.mock->expect_response(
|
|
molo::clients::Method::kPost, p + "tts-m:generateContent",
|
|
GoogleRig::json(
|
|
"{\"candidates\":[{\"content\":{\"parts\":[{\"inlineData\":{\"mimeType\":"
|
|
"\"audio/L16;codec=pcm;rate=24000\",\"data\":\"" +
|
|
molo::security::crypto::Base64::encode("PCM") + "\"}}]}}]}"));
|
|
Fixture f(rig.client, molo::google::VoiceBackend::kVertex);
|
|
|
|
check(contains(f.client->get("/google/status").body, "\"backend\":\"vertex\""),
|
|
"status names the backend");
|
|
auto res = f.client->post("/voice/turn?cid=v1", "WEBM", "audio/webm;codecs=opus");
|
|
check(res.status == 200, "status 200");
|
|
check(contains(res.body, "\"transcript\":\"hallo daar\""), "transcript");
|
|
check(contains(res.body, "\"reply\":\"Hoi!\""), "reply");
|
|
check(contains(res.body, "\"mime\":\"audio/wav\""), "wav for the browser");
|
|
check(rig.mock->send_count() == 3, "three Gemini calls");
|
|
check(rig.mock->seen()[0].target.rfind(p, 0) == 0, "vertex endpoint used");
|
|
check(contains(rig.mock->seen()[0].body, "audio/webm"), "audio mime sent to Gemini");
|
|
check(rig.mock->seen()[0].headers.get_or("x-goog-api-key", "") == kTestKey,
|
|
"key in header");
|
|
unsetenv("GOOGLE_GENAI_MODEL");
|
|
unsetenv("GOOGLE_STT_MODEL");
|
|
unsetenv("GOOGLE_TTS_MODEL");
|
|
return finish("voice/turn vertex");
|
|
}
|