MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / build_request_from_json

Function build_request_from_json

app/cli/request.cpp:91–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89 return engine::io::json::stringify(value);
90}
91
92std::unordered_map<std::string, std::string> json_options_map(const engine::io::json::Value * value) {
93 std::unordered_map<std::string, std::string> options;
94 if (value == nullptr || value->is_null()) {
95 return options;
96 }
97 for (const auto & [key, child] : value->as_object()) {
98 options[key] = json_option_string(child);
99 }
100 return options;
101}
102
103std::optional<std::string> json_optional_string(
104 const engine::io::json::Value & object,
105 const std::string & key) {
106 const auto * value = object.find(key);
107 if (value == nullptr || value->is_null()) {
108 return std::nullopt;
109 }
110 return value->as_string();
111}
112
113std::optional<float> json_optional_float(
114 const engine::io::json::Value & object,
115 const std::string & key) {
116 const auto * value = object.find(key);
117 if (value == nullptr || value->is_null()) {
118 return std::nullopt;
119 }
120 return value->as_f32();
121}
122
123engine::runtime::TaskRequest build_request_from_json(
124 const engine::io::json::Value & value,
125 const std::filesystem::path & base_dir) {
126 engine::runtime::TaskRequest request;
127 const std::string language = json_optional_string(value, "language").value_or("");
128 if (const auto text = json_optional_string(value, "text")) {
129 request.text_input = engine::runtime::Transcript{*text, language};
130 }
131 if (const auto audio = json_optional_string(value, "audio")) {
132 request.audio_input = read_audio_buffer(resolve_case_path(base_dir, *audio));
133 }
134
135 engine::runtime::VoiceCondition voice;
136 bool has_voice = false;
137 if (const auto voice_id = json_optional_string(value, "voice_id")) {
138 engine::runtime::VoiceReference reference;
139 reference.cached_voice_id = *voice_id;
140 voice.speaker = std::move(reference);
141 has_voice = true;
142 }
143 if (const auto voice_ref = json_optional_string(value, "voice_ref")) {
144 if (!voice.speaker.has_value()) {
145 voice.speaker = engine::runtime::VoiceReference{};
146 }
147 voice.speaker->audio = read_audio_buffer(resolve_case_path(base_dir, *voice_ref));
148 has_voice = true;

Callers 6

handle_generic_runMethod · 0.85
run_model_step_implFunction · 0.85
run_chunked_model_stepFunction · 0.85
run_model_step_foreachFunction · 0.85
mainFunction · 0.85

Calls 11

json_optional_stringFunction · 0.85
resolve_case_pathFunction · 0.85
json_optional_floatFunction · 0.85
json_options_mapFunction · 0.85
set_optionFunction · 0.85
path_arg_stringFunction · 0.85
read_audio_bufferFunction · 0.70
to_stringFunction · 0.50
findMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected