| 227 | return response; |
| 228 | } |
| 229 | |
| 230 | bool 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 | |
| 238 | double elapsed_ms(Clock::time_point started) { |
| 239 | return std::chrono::duration<double, std::milli>(Clock::now() - started).count(); |
| 240 | } |
| 241 | |
| 242 | double 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 | |
| 250 | double audio_rtf(double wall_ms, double duration_ms) { |
| 251 | return duration_ms > 0.0 ? wall_ms / duration_ms : 0.0; |
| 252 | } |
| 253 | |
| 254 | std::string timing_json(double wall_ms) { |
| 255 | std::ostringstream out; |
| 256 | out << "{\"wall_ms\":" << wall_ms << "}"; |
| 257 | return out.str(); |
| 258 | } |
| 259 | |
| 260 | std::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 | |
| 269 | std::string ttft_timing_json(double ttft_ms) { |
| 270 | std::ostringstream out; |
| 271 | out << "{\"ttft_ms\":" << ttft_ms << "}"; |
| 272 | return out.str(); |
| 273 | } |
| 274 | |
| 275 | bool 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 | |
| 281 | bool 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 |
no test coverage detected