feat(clients): cloudai: Translation, Vision, Language, Video, Document AI, Speech v2, long audio TTS
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
#include "google/cloudai/long_audio.h"
|
||||
|
||||
#include "google/cloudai/caps.h"
|
||||
#include "google/errors.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
using clients::body::Json;
|
||||
|
||||
Json LongAudio::request_body(const LongAudioRequest& r) const {
|
||||
if (r.text.empty()) throw GoogleError::invalid("text is empty");
|
||||
if (r.text.size() > CloudAiCaps::kMaxLongAudioChars) throw GoogleError::invalid("text over 1,000,000 bytes");
|
||||
if (!valid_enum("AudioConfig.audioEncoding", r.encoding)) throw GoogleError::invalid("unknown audioEncoding");
|
||||
Json in = Json::object();
|
||||
in.set(r.ssml ? "ssml" : "text", Json(r.text));
|
||||
Json voice = Json::object();
|
||||
voice.set("languageCode", Json(checked_language_code(r.language, "language")));
|
||||
if (!r.voice_name.empty()) {
|
||||
if (r.voice_name.size() > 128 || !valid_name_segment(r.voice_name))
|
||||
throw GoogleError::invalid("voice name has illegal characters");
|
||||
voice.set("name", Json(r.voice_name));
|
||||
}
|
||||
Json audio = Json::object();
|
||||
audio.set("audioEncoding", Json(r.encoding));
|
||||
Json b = Json::object();
|
||||
b.set("input", in);
|
||||
b.set("voice", voice);
|
||||
b.set("audioConfig", audio);
|
||||
b.set("outputGcsUri", Json(checked_gcs_uri(r.output_uri, "outputUri")));
|
||||
return b;
|
||||
}
|
||||
|
||||
Operation LongAudio::synthesize_start(const LongAudioRequest& r) const {
|
||||
Json b = request_body(r);
|
||||
return start(Call::kTtsLocationsSynthesizeLongAudio, parent(), &b);
|
||||
}
|
||||
|
||||
Operation LongAudio::get_operation(const std::string& name) const {
|
||||
return operation(Call::kTtsLocationsOperationsGet, name);
|
||||
}
|
||||
|
||||
Json LongAudio::list_operations() const {
|
||||
return list(Call::kTtsLocationsOperationsList, parent(), "operations");
|
||||
}
|
||||
|
||||
Json LongAudio::voices(const std::string& language) const {
|
||||
Query q;
|
||||
if (!language.empty()) q.emplace_back("languageCode", checked_language_code(language, "language"));
|
||||
return invoke(Call::kTtsVoicesList, "", nullptr, q);
|
||||
}
|
||||
|
||||
void LongAudio::cancel_operation(const std::string& name) const {
|
||||
invoke(Call::kTtsOperationsCancel, name);
|
||||
}
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
Reference in New Issue
Block a user