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>
This commit is contained in:
2026-10-25 15:36:57 +01:00
co-authored by Claude Sonnet 5.5
parent 3db67fcf1f
commit 6d80dd0223
132 changed files with 14060 additions and 3 deletions
+34
View File
@@ -0,0 +1,34 @@
// Dry runs: anything that generates audio, writes or deletes does not run
// without "confirm":true, and answers 200 with a preview even without a key.
#include <cstdlib>
#include "support/Assert.hpp"
using namespace molo::example::test;
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;
auto post = [&](const std::string& path, const std::string& body) { return f.client->post(path, body, "application/json"); };
auto tts = post("/ai/audio/tts", "{\"provider\":\"elevenlabs\",\"text\":\"Hello. This is a test.\",\"voice\":\"v1\"}");
check(tts.status == 200 && contains(tts.body, "\"dry_run\":true"), "tts without confirm is a dry run");
check(contains(tts.body, "\"chunks\":1") && contains(tts.body, "confirm"), "dry run reports chunks and how to run it");
auto stt = post("/ai/audio/stt", "{\"provider\":\"assemblyai\",\"url\":\"https://example.com/a.mp3\"}");
check(stt.status == 200 && contains(stt.body, "\"dry_run\":true"), "stt without confirm is a dry run");
auto session = post("/ai/audio/session", "{\"provider\":\"hume\",\"text\":\"hi\"}");
check(session.status == 200 && contains(session.body, "\"dry_run\":true"), "streaming session without confirm is a dry run");
auto write = post("/ai/audio/call", "{\"provider\":\"elevenlabs\",\"id\":\"text_to_speech_full\",\"segments\":[\"v1\"],\"body\":{\"text\":\"x\"}}");
check(write.status == 200 && contains(write.body, "\"dry_run\":true") && contains(write.body, "POST /v1/text-to-speech/v1"), "generation call is a dry run with the path");
auto del = post("/ai/audio/call", "{\"provider\":\"elevenlabs\",\"id\":\"delete_voice\",\"segments\":[\"v1\"]}");
check(del.status == 200 && contains(del.body, "\"dry_run\":true") && contains(del.body, "DELETE /v1/voices/v1"), "delete is a dry run");
auto job = post("/ai/audio/call", "{\"provider\":\"speechmatics\",\"id\":\"jobs_delete\",\"segments\":[\"job1\"],\"query\":{\"force\":true}}");
check(job.status == 200 && contains(job.body, "force=true"), "speechmatics delete previews its query");
check(post("/ai/audio/call", "{\"provider\":\"elevenlabs\",\"id\":\"delete_voice\",\"segments\":[\"v1\"],\"confirm\":true}").status == 503, "confirmed delete needs the key");
check(post("/ai/audio/tts", "{\"provider\":\"elevenlabs\",\"text\":\"x\",\"voice\":\"v1\",\"confirm\":true}").status == 503, "confirmed tts needs the key");
check(post("/ai/audio/call", "{\"provider\":\"elevenlabs\",\"id\":\"delete_voice\",\"segments\":[\"a/b\"]}").status == 422, "bad id is 422 before the dry run");
check(post("/ai/audio/call", "{\"provider\":\"elevenlabs\",\"id\":\"text_to_speech_full\",\"segments\":[\"v1\"],\"body\":{\"nope\":1}}").status == 422, "bad body field is 422 before the dry run");
check(post("/ai/audio/call", "{\"provider\":\"elevenlabs\",\"id\":\"text_to_speech_full\",\"segments\":[\"v1\"]}").status == 422, "missing required body is 422");
return finish("ai/audio/confirm");
}
+34
View File
@@ -0,0 +1,34 @@
// Local routes: POST /ai/audio/split and /ai/audio/ws/preview. No key, no network.
#include <cstdlib>
#include "support/Assert.hpp"
using namespace molo::example::test;
int main() {
Fixture f;
auto post = [&](const std::string& path, const std::string& body) { return f.client->post(path, body, "application/json"); };
auto split = post("/ai/audio/split", "{\"text\":\"One sentence. Another sentence. A third one.\",\"max_chars\":20}");
check(split.status == 200 && contains(split.body, "\"count\":3"), "splits at sentence ends");
check(contains(split.body, "One sentence."), "chunks are returned");
check(post("/ai/audio/split", "{\"text\":\"\"}").status == 422, "empty text is 422");
check(post("/ai/audio/split", "{\"text\":\"x\",\"max_chars\":0}").status == 422, "max_chars 0 is 422");
check(post("/ai/audio/split", "{\"text\":\"x\",\"max_chars\":100001}").status == 422, "max_chars over the cap is 422");
std::string many;
for (int i = 0; i < 100; ++i) many += "word. ";
check(post("/ai/audio/split", "{\"text\":\"" + many + "\",\"max_chars\":6}").status == 422, "more than 64 chunks is 422");
auto el = post("/ai/audio/ws/preview", "{\"provider\":\"elevenlabs\",\"channel\":\"tts-stream-input\",\"params\":{\"voice_id\":\"v1\",\"model_id\":\"eleven_flash_v2_5\"}}");
check(el.status == 200 && contains(el.body, "wss://api.elevenlabs.io/v1/text-to-speech/v1/stream-input?model_id=eleven_flash_v2_5"), "elevenlabs url");
check(contains(el.body, "never in the URL") && !contains(el.body, "preview-only"), "no credential in the preview");
auto dg = post("/ai/audio/ws/preview", "{\"provider\":\"deepgram\",\"channel\":\"listen-v1\",\"params\":{\"model\":\"nova-3\"}}");
check(dg.status == 200 && contains(dg.body, "wss://api.deepgram.com/v1/listen?model=nova-3"), "deepgram url");
check(contains(post("/ai/audio/ws/preview", "{\"provider\":\"speechmatics\",\"channel\":\"realtime\"}").body, "rt.speechmatics.com/v2"), "speechmatics url");
check(contains(post("/ai/audio/ws/preview", "{\"provider\":\"cartesia\",\"channel\":\"tts-websocket\"}").body, "cartesia_version=2026-08-14"), "cartesia pins the version");
check(contains(post("/ai/audio/ws/preview", "{\"provider\":\"hume\",\"channel\":\"evi-chat\",\"params\":{\"config_id\":\"cfg1\"}}").body, "wss://api.hume.ai/v0/evi/chat?config_id=cfg1"), "hume evi url");
check(contains(post("/ai/audio/ws/preview", "{\"provider\":\"assemblyai\",\"channel\":\"streaming\",\"params\":{\"sample_rate\":\"16000\"}}").body, "streaming.assemblyai.com/v3/ws?sample_rate=16000"), "assemblyai url");
check(post("/ai/audio/ws/preview", "{\"provider\":\"elevenlabs\",\"channel\":\"nope\"}").status == 422, "unknown channel is 422");
check(post("/ai/audio/ws/preview", "{\"provider\":\"elevenlabs\",\"channel\":\"tts-stream-input\",\"params\":{\"voice_id\":\"../x\"}}").status == 422, "bad voice id is 422");
check(post("/ai/audio/ws/preview", "{\"provider\":\"deepgram\",\"channel\":\"listen-v1\",\"params\":{\"nonsense\":\"1\"}}").status == 422, "unknown stream parameter is 422");
check(f.client->get("/ai/audio/split").status == 405 && f.client->get("/ai/audio/ws/preview").status == 405, "get is 405");
return finish("ai/audio/local");
}
+21
View File
@@ -0,0 +1,21 @@
// Route: GET /ai/audio (page, no credential needed)
#include "support/Assert.hpp"
using namespace molo::example::test;
int main() {
Fixture f;
auto res = f.client->get("/ai/audio");
check(res.status == 200, "status 200");
check(contains(res.headers.get("Content-Type"), "text/html"), "html");
check(contains(res.body, "Audio") && contains(res.body, "viewport"), "page and mobile viewport");
check(contains(res.body, "/embedded/ai_audio.js"), "script wired");
check(contains(res.body, "<select id=\"au-route\""), "route picker is a dropdown, not a button group");
check(contains(res.body, "<select id=\"au-provider\""), "provider picker is a dropdown");
check(f.client->post("/ai/audio", "{}", "application/json").status == 405, "post is 405");
auto js = f.client->get("/embedded/ai_audio.js");
check(js.status == 200 && contains(js.body, "/ai/audio/"), "script is served");
auto idx = f.client->get("/");
check(idx.status == 200 && contains(idx.body, "/ai/audio"), "matrix lists the page");
return finish("ai/audio/page");
}
+66
View File
@@ -0,0 +1,66 @@
// 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");
}
+35
View File
@@ -0,0 +1,35 @@
// Routes: GET /ai/audio/status and /ai/audio/calls
#include <cstdlib>
#include "support/Assert.hpp"
using namespace molo::example::test;
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;
auto res = f.client->get("/ai/audio/status");
check(res.status == 200, "status 200");
check(contains(res.body, "\"name\":\"elevenlabs\"") && contains(res.body, "\"name\":\"hume\""), "lists the providers");
check(contains(res.body, "\"key_configured\":false"), "reports no keys");
check(contains(res.body, "ELEVENLABS_API_KEY") && contains(res.body, "SPEECHMATICS_MANAGEMENT_TOKEN"), "names the variables");
check(contains(res.body, "\"calls_total\":509"), "counts the calls");
check(contains(res.body, "playht") && contains(res.body, "do not resolve"), "says why PlayHT is absent");
check(!contains(res.body, "Bearer"), "no credential in the body");
setenv("DEEPGRAM_API_KEY", "dg-test-key", 1);
Fixture g;
auto on = g.client->get("/ai/audio/status");
check(contains(on.body, "\"key_configured\":true"), "reports a configured key");
check(!contains(on.body, "dg-test-key"), "never echoes the key");
unsetenv("DEEPGRAM_API_KEY");
auto calls = f.client->get("/ai/audio/calls?provider=deepgram");
check(calls.status == 200, "calls 200");
check(contains(calls.body, "/v1/listen") && contains(calls.body, "\"provider\":\"deepgram\""), "lists the deepgram table");
check(!contains(calls.body, "elevenlabs"), "filters by provider");
check(contains(f.client->get("/ai/audio/calls?provider=elevenlabs").body, "/v1/text-to-speech/{voice_id}"), "elevenlabs rows");
check(f.client->post("/ai/audio/status", "{}", "application/json").status == 405, "status post is 405");
check(f.client->post("/ai/audio/calls", "{}", "application/json").status == 405, "calls post is 405");
return finish("ai/audio/status");
}