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,40 @@
|
||||
// Route: POST /voice/hear (audio bytes to transcript through Google STT)
|
||||
#include "support/GoogleRig.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
GoogleRig rig;
|
||||
rig.stt("goedemorgen");
|
||||
Fixture f(rig.client);
|
||||
auto res = f.client->post("/voice/hear?lang=nl-NL", "WEBM-AUDIO-BYTES",
|
||||
"audio/webm;codecs=opus");
|
||||
check(res.status == 200, "status 200");
|
||||
check(contains(res.headers.get("Content-Type"), "application/json"), "json");
|
||||
check(contains(res.body, "\"text\":\"goedemorgen\""), "transcript returned");
|
||||
auto seen = rig.mock->seen();
|
||||
check(seen.size() == 1 && contains(seen[0].body, "WEBM_OPUS") &&
|
||||
contains(seen[0].body, "nl-NL"),
|
||||
"side effect: encoding and language sent upstream");
|
||||
check(!contains(seen[0].body, "WEBM-AUDIO-BYTES"), "audio is base64, not raw");
|
||||
|
||||
check(f.client->post("/voice/hear", "xx", "video/mp4").status == 415,
|
||||
"unknown media type is 415");
|
||||
check(f.client->post("/voice/hear", "", "audio/webm").status == 422,
|
||||
"empty audio is 422");
|
||||
check(f.client->post("/voice/hear?lang=zz", "xx", "audio/webm").status == 422,
|
||||
"bad language is 422");
|
||||
std::string big(1024 * 1024 + 8192, 'a');
|
||||
check(f.client->post("/voice/hear", big, "audio/webm").status == 413,
|
||||
"body over the 1 MiB cap is 413");
|
||||
check(rig.mock->send_count() == 1, "rejected input never reached Google");
|
||||
check(f.client->get("/voice/hear").status == 405, "get is 405");
|
||||
|
||||
GoogleRig failing;
|
||||
failing.upstream_error("/v1/speech:recognize", 429, "RESOURCE_EXHAUSTED", "quota");
|
||||
Fixture g(failing.client);
|
||||
auto bad = g.client->post("/voice/hear", "xx", "audio/webm");
|
||||
check(bad.status == 502 && contains(bad.body, "RESOURCE_EXHAUSTED"),
|
||||
"quota error surfaced as 502");
|
||||
return finish("voice/hear");
|
||||
}
|
||||
Reference in New Issue
Block a user