| 238 | } |
| 239 | |
| 240 | engine::io::json::Value step_json( |
| 241 | const engine::runtime::TaskResult & result, |
| 242 | int request_index, |
| 243 | double wall_ms, |
| 244 | const std::vector<std::filesystem::path> & audio_paths) { |
| 245 | if (!result.audio_output.has_value()) { |
| 246 | throw std::runtime_error("Stable Audio warmbench expected audio output"); |
| 247 | } |
| 248 | std::vector<engine::io::json::Value> stems; |
| 249 | if (!result.named_audio_outputs.empty()) { |
| 250 | for (size_t i = 0; i < result.named_audio_outputs.size(); ++i) { |
| 251 | const auto & named = result.named_audio_outputs[i]; |
| 252 | engine::io::json::Value::Object stem{ |
| 253 | {"name", string(named.id)}, |
| 254 | {"summary", audio_summary_json(named.audio)}, |
| 255 | }; |
| 256 | if (i < audio_paths.size() && !audio_paths[i].empty()) { |
| 257 | stem.emplace("audio", string(audio_paths[i].string())); |
| 258 | } |
| 259 | stems.push_back(engine::io::json::Value::make_object(std::move(stem))); |
| 260 | } |
| 261 | } else { |
| 262 | engine::io::json::Value::Object stem{ |
| 263 | {"name", string("audio")}, |
| 264 | {"summary", audio_summary_json(*result.audio_output)}, |
| 265 | }; |
| 266 | if (!audio_paths.empty() && !audio_paths.front().empty()) { |
| 267 | stem.emplace("audio", string(audio_paths.front().string())); |
| 268 | } |
| 269 | stems.push_back(engine::io::json::Value::make_object(std::move(stem))); |
| 270 | } |
| 271 | return engine::io::json::Value::make_object({ |
| 272 | {"request_index", number(static_cast<double>(request_index))}, |
| 273 | {"stems", engine::io::json::Value::make_array(std::move(stems))}, |
| 274 | {"metrics", engine::io::json::Value::make_object({{"wall_ms", number(wall_ms)}})}, |
| 275 | }); |
| 276 | } |
| 277 | |
| 278 | } // namespace |
| 279 | |