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>
35 lines
3.2 KiB
C++
35 lines
3.2 KiB
C++
// 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");
|
|
}
|