Files
moloapp/src/vendors/audio/deepgram/speak.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

60 lines
2.1 KiB
C++

#include "vendors/audio/deepgram/speak.h"
namespace molo::audio::deepgram {
using C = DeepgramCalls;
Json Speak::build(const SpeakOptions& o) const {
require_text("text", o.text, DeepgramCaps::kMaxSpeakChars);
Json body = Json::object();
body.set("text", Json(o.text));
return body;
}
Query Speak::query(const SpeakOptions& o, bool v2) const {
Query q;
if (!o.model.empty()) {
if (!valid_token(o.model)) bad("model has characters Deepgram does not accept");
q.add("model", o.model);
}
if (!o.encoding.empty()) {
if (!valid_token(o.encoding)) bad("bad encoding");
q.add("encoding", o.encoding);
}
if (!o.container.empty()) {
if (!valid_token(o.container)) bad("bad container");
q.add("container", o.container);
}
if (o.sample_rate < 0 || o.sample_rate > 96000) bad("sample_rate must be 0 or up to 96000");
if (o.sample_rate > 0) q.add_int("sample_rate", o.sample_rate);
if (o.bit_rate < 0 || o.bit_rate > 1000000) bad("bit_rate is out of range");
if (o.bit_rate > 0) q.add_int("bit_rate", o.bit_rate);
if (o.speed < 0) bad("speed must not be negative");
if (o.speed > 0) q.add("speed", std::to_string(o.speed));
if (v2) {
q.add_if("expressivity", o.expressivity);
q.add_if("priority", o.priority);
} else if (!o.expressivity.empty() || !o.priority.empty()) {
bad("expressivity and priority belong to /v2/speak");
}
q.add_if("tag", o.tag);
q.add_if("callback", o.callback);
q.add_if("callback_method", o.callback_method);
if (o.mip_opt_out >= 0) q.add_bool("mip_opt_out", o.mip_opt_out == 1);
check_query(table_.get(v2 ? C::kSpeakV2 : C::kSpeak), q);
return q;
}
SpeakResult Speak::synthesize(const SpeakOptions& o, bool v2) {
Json body = build(o);
llm::RawResponse raw = call_raw(v2 ? C::kSpeakV2 : C::kSpeak, {}, &body, query(o, v2));
return SpeakResult{raw.body, raw.content_type};
}
ByteStreamer::Result Speak::stream(const SpeakOptions& o, const ChunkSink& sink, bool v2) {
Json body = build(o);
return call_stream(v2 ? C::kSpeakV2 : C::kSpeak, {}, &body, query(o, v2), sink);
}
} // namespace molo::audio::deepgram