Files
moloapp/tests/example/ai/audio/routes_test.cpp
T
retoorandClaude Sonnet 5.5 6d80dd0223 feat(clients): audio: ElevenLabs, AssemblyAI, Deepgram, Cartesia, Speechmatics, Hume
Table driven REST (509 rows verified against vendor specs by tools/check_spec.py),
WebSockets over the src/google/live client, neutral SpeechSynthesizer /
SpeechRecognizer seam, /ai/audio demo with dry runs, 110 package tests and 5
route tests. PlayHT has no public API; LeMUR is gone from AssemblyAI's spec.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 15:36:57 +01:00

67 lines
4.4 KiB
C++

// Routes: POST /ai/audio/{tts,stt,voices,call,session}
// Without a key a well formed, confirmed request is 503 not_configured; bad
// input is 422 and never reaches a provider; GET is 405. Nothing here
// touches the network.
#include <cstdlib>
#include "support/Assert.hpp"
using namespace molo::example::test;
namespace {
struct Route {
const char* path;
const char* valid;
const char* bad;
};
} // namespace
int main() {
for (const char* k : {"ELEVENLABS_API_KEY", "ASSEMBLYAI_API_KEY", "DEEPGRAM_API_KEY", "CARTESIA_API_KEY",
"SPEECHMATICS_API_KEY", "SPEECHMATICS_MANAGEMENT_TOKEN", "HUME_API_KEY"})
unsetenv(k);
Fixture f;
const Route routes[] = {
{"/ai/audio/tts", "{\"provider\":\"elevenlabs\",\"text\":\"hi\",\"voice\":\"v1\",\"confirm\":true}",
"{\"provider\":\"elevenlabs\",\"text\":\"\"}"},
{"/ai/audio/stt", "{\"provider\":\"deepgram\",\"url\":\"https://example.com/a.mp3\",\"confirm\":true}",
"{\"provider\":\"deepgram\"}"},
{"/ai/audio/voices", "{\"provider\":\"cartesia\"}", "{\"provider\":\"assemblyai\"}"},
{"/ai/audio/call", "{\"provider\":\"elevenlabs\",\"id\":\"get_models\"}", "{\"provider\":\"elevenlabs\",\"id\":\"nope\"}"},
{"/ai/audio/session", "{\"provider\":\"deepgram\",\"text\":\"hi\",\"confirm\":true}",
"{\"provider\":\"speechmatics\",\"text\":\"hi\"}"},
};
for (const Route& r : routes) {
std::string p = r.path;
auto ok = f.client->post(p, r.valid, "application/json");
check(ok.status == 503 && contains(ok.body, "not_configured"), p + ": no key is 503 not_configured");
auto bad = f.client->post(p, r.bad, "application/json");
check(bad.status == 422 && contains(bad.body, "validation_error"), p + ": bad input is 422");
check(f.client->post(p, "{not json", "application/json").status == 422, p + ": broken json is 422");
check(f.client->post(p, "[1]", "application/json").status == 422, p + ": non-object json is 422");
check(f.client->post(p, "{}", "application/json").status == 422, p + ": missing provider is 422");
check(f.client->get(p).status == 405, p + ": get is 405");
}
auto post = [&](const std::string& path, const std::string& body) { return f.client->post(path, body, "application/json"); };
check(post("/ai/audio/tts", "{\"provider\":\"nope\",\"text\":\"x\"}").status == 422, "unknown provider is 422");
check(post("/ai/audio/tts", "{\"provider\":\"assemblyai\",\"text\":\"x\"}").status == 422, "assemblyai has no synthesis");
check(post("/ai/audio/stt", "{\"provider\":\"hume\",\"url\":\"https://example.com/a.mp3\"}").status == 422, "hume has no recognition");
check(post("/ai/audio/stt", "{\"provider\":\"deepgram\",\"url\":\"ftp://x\"}").status == 422, "bad url is 422");
check(post("/ai/audio/stt", "{\"provider\":\"deepgram\",\"url\":\"https://x/a\",\"data_base64\":\"QUJD\"}").status == 422, "audio and url together is 422");
check(post("/ai/audio/stt", "{\"provider\":\"deepgram\",\"data_base64\":\"!!\"}").status == 422, "bad base64 is 422");
check(post("/ai/audio/tts", "{\"provider\":\"elevenlabs\",\"text\":\"x\",\"format\":\"ogg\"}").status == 422, "unknown format is 422");
check(post("/ai/audio/tts", "{\"provider\":\"elevenlabs\",\"text\":\"x\",\"speed\":9}").status == 422, "speed out of range is 422");
check(post("/ai/audio/call", "{\"provider\":\"elevenlabs\",\"id\":\"get_voice_by_id\",\"segments\":[\"../x\"]}").status == 422, "bad segment is 422");
check(post("/ai/audio/call", "{\"provider\":\"elevenlabs\",\"id\":\"get_voices\",\"query\":{\"zzz\":1}}").status == 422, "unknown query is 422");
check(post("/ai/audio/call", "{\"provider\":\"deepgram\",\"id\":\"keys_list\",\"segments\":[]}").status == 422, "wrong segment count is 422");
check(post("/ai/audio/call", "{\"provider\":\"elevenlabs\",\"id\":\"get_voice_by_id\",\"segments\":[\"v1\"]}").status == 503, "a read with a valid id reaches the key check");
check(post("/ai/audio/call", "{\"provider\":\"speechmatics\",\"id\":\"mgmt_projects_list\"}").status == 503, "management host needs its own token");
setenv("DEEPGRAM_API_KEY", "dg-test-key", 1);
Fixture g;
auto other = g.client->post("/ai/audio/call", "{\"provider\":\"hume\",\"id\":\"voices_list\"}", "application/json");
check(other.status == 503 && contains(other.body, "HUME_API_KEY"), "hume still needs HUME_API_KEY");
check(!contains(other.body, "dg-test-key"), "no key in an error");
unsetenv("DEEPGRAM_API_KEY");
return finish("ai/audio/routes");
}