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

Function task_result_json

app/server/runtime.cpp:229–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

227 return response;
228}
229
230bool is_wav_upload_filename(const std::string & filename) {
231 std::string ext = std::filesystem::path(filename).extension().string();
232 for (char & ch : ext) {
233 ch = static_cast<char>(std::tolower(static_cast<unsigned char>(ch)));
234 }
235 return ext.empty() || ext == ".wav";
236}
237
238double elapsed_ms(Clock::time_point started) {
239 return std::chrono::duration<double, std::milli>(Clock::now() - started).count();
240}
241
242double audio_duration_ms(const engine::runtime::AudioBuffer & audio) {
243 if (audio.sample_rate <= 0 || audio.channels <= 0) {
244 return 0.0;
245 }
246 return 1000.0 * static_cast<double>(audio.samples.size()) /
247 static_cast<double>(audio.sample_rate * audio.channels);
248}
249
250double audio_rtf(double wall_ms, double duration_ms) {
251 return duration_ms > 0.0 ? wall_ms / duration_ms : 0.0;
252}
253
254std::string timing_json(double wall_ms) {
255 std::ostringstream out;
256 out << "{\"wall_ms\":" << wall_ms << "}";
257 return out.str();
258}
259
260std::string timing_json(double wall_ms, const engine::runtime::AudioBuffer & audio) {
261 const double duration_ms = audio_duration_ms(audio);
262 std::ostringstream out;
263 out << "{\"wall_ms\":" << wall_ms
264 << ",\"audio_duration_ms\":" << duration_ms
265 << ",\"rtf\":" << audio_rtf(wall_ms, duration_ms) << "}";
266 return out.str();
267}
268
269std::string ttft_timing_json(double ttft_ms) {
270 std::ostringstream out;
271 out << "{\"ttft_ms\":" << ttft_ms << "}";
272 return out.str();
273}
274
275bool stream_event_has_output(const engine::runtime::StreamEvent & event) {
276 return (event.partial_text.has_value() && !event.partial_text->text.empty()) ||
277 event.audio_output.has_value() ||
278 !event.named_audio_outputs.empty();
279}
280
281bool task_result_has_output(const engine::runtime::TaskResult & result) {
282 return result.text_output.has_value() ||
283 result.audio_output.has_value() ||
284 !result.named_audio_outputs.empty();
285}
286

Callers 1

handle_generic_runMethod · 0.85

Calls 7

encode_pcm16_wavFunction · 0.85
base64_encodeFunction · 0.85
timing_jsonFunction · 0.85
strMethod · 0.80
json_quoteFunction · 0.70
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected