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>
57 lines
2.5 KiB
C++
57 lines
2.5 KiB
C++
// Route: POST /voice/say (text to spoken mp3 through Google TTS)
|
|
#include "support/GoogleRig.hpp"
|
|
|
|
using namespace molo::example::test;
|
|
|
|
int main() {
|
|
GoogleRig rig;
|
|
rig.tts("FAKE-MP3-BYTES");
|
|
Fixture f(rig.client);
|
|
auto res = f.client->post("/voice/say",
|
|
"{\"text\":\"hallo wereld\",\"lang\":\"nl-NL\"}",
|
|
"application/json");
|
|
check(res.status == 200, "status 200");
|
|
check(res.headers.get("Content-Type") == "audio/mpeg", "audio/mpeg");
|
|
check(res.body == "FAKE-MP3-BYTES", "decoded audio returned");
|
|
auto seen = rig.mock->seen();
|
|
check(seen.size() == 1 && contains(seen[0].body, "hallo wereld"),
|
|
"side effect: text sent upstream");
|
|
check(seen[0].headers.get_or("x-goog-api-key", "") == kTestKey,
|
|
"key sent in header");
|
|
check(seen[0].target.find(kTestKey) == std::string::npos, "key not in url");
|
|
|
|
check(f.client->post("/voice/say", "{\"text\":\"\"}", "application/json").status == 422,
|
|
"empty text is 422");
|
|
check(f.client->post("/voice/say", "{\"text\":\"x\",\"lang\":\"dutch\"}",
|
|
"application/json").status == 422,
|
|
"bad language is 422");
|
|
check(f.client->post("/voice/say",
|
|
"{\"text\":\"x\",\"voice\":\"a b;c\"}",
|
|
"application/json").status == 422,
|
|
"bad voice name is 422");
|
|
std::string long_text(5001, 'a');
|
|
check(f.client->post("/voice/say", "{\"text\":\"" + long_text + "\"}",
|
|
"application/json").status == 422,
|
|
"text over the 5000 char cap is 422");
|
|
check(rig.mock->send_count() == 1, "rejected input never reached Google");
|
|
check(f.client->get("/voice/say").status == 405, "get is 405");
|
|
|
|
GoogleRig failing;
|
|
failing.upstream_error("/v1/text:synthesize", 403, "PERMISSION_DENIED",
|
|
"API not enabled");
|
|
Fixture g(failing.client);
|
|
auto bad = g.client->post("/voice/say", "{\"text\":\"x\"}", "application/json");
|
|
check(bad.status == 502, "upstream failure is 502");
|
|
check(contains(bad.body, "google_error") && contains(bad.body, "PERMISSION_DENIED"),
|
|
"google status surfaced");
|
|
check(!contains(bad.body, kTestKey), "key never in an error");
|
|
|
|
GoogleRig none(false);
|
|
Fixture h(none.client);
|
|
auto nc = h.client->post("/voice/say", "{\"text\":\"x\"}", "application/json");
|
|
check(nc.status == 503 && contains(nc.body, "google_not_configured"),
|
|
"no key is a loud 503");
|
|
check(none.mock->send_count() == 0, "no network without a key");
|
|
return finish("voice/say");
|
|
}
|