| 901 | const auto text_out_option = workflow_optional_string(step, "text_out"); |
| 902 | const auto text_out = text_out_option.has_value() |
| 903 | ? resolve_workflow_path(*text_out_option, context) |
| 904 | : step_dir / (id + ".txt"); |
| 905 | if (!text_out.parent_path().empty()) { |
| 906 | std::filesystem::create_directories(text_out.parent_path()); |
| 907 | } |
| 908 | std::ofstream out(text_out); |
| 909 | out << text << "\n"; |
| 910 | context.values[id + ".text_path"] = text_out.string(); |
| 911 | std::cout << "text_out=" << text_out.string() << "\n"; |
| 912 | } |
| 913 | std::cout << "workflow_step=" << id << "\n"; |
| 914 | } |
| 915 | |
| 916 | void run_mix_audio_step( |
| 917 | const engine::io::json::Value & step, |
| 918 | WorkflowContext & context) { |
| 919 | const std::string id = workflow_string(step, "id"); |
| 920 | const auto * inputs_value = step.find("inputs"); |
| 921 | if (inputs_value == nullptr || !inputs_value->is_array()) { |
| 922 | throw std::runtime_error("mix_audio step requires inputs array: " + id); |
| 923 | } |
| 924 | std::vector<engine::audio::AudioMixInput> inputs; |
| 925 | for (const auto & item : inputs_value->as_array()) { |
| 926 | engine::audio::AudioMixInput input; |
| 927 | input.audio = engine::audio::read_wav_f32(resolve_workflow_path(workflow_string(item, "path"), context)); |
| 928 | input.gain = static_cast<float>(workflow_optional_number(item, "gain").value_or(1.0)); |
| 929 | if (const auto activity_ref = workflow_optional_string(item, "activity_ref")) { |
| 930 | input.activity_reference = engine::audio::read_wav_f32(resolve_workflow_path(*activity_ref, context)); |
| 931 | input.activity_threshold_dbfs = |
| 932 | static_cast<float>(workflow_optional_number(item, "activity_threshold_dbfs").value_or(-40.0)); |
| 933 | input.activity_window_seconds = workflow_optional_number(item, "activity_window_seconds").value_or(0.1); |
| 934 | input.activity_margin_seconds = workflow_optional_number(item, "activity_margin_seconds").value_or(0.35); |
| 935 | input.activity_fade_seconds = workflow_optional_number(item, "activity_fade_seconds").value_or(0.03); |
| 936 | } |
| 937 | inputs.push_back(std::move(input)); |
| 938 | } |
| 939 | const bool normalize = workflow_optional_bool(step, "normalize_peak", true); |
| 940 | const auto mixed = engine::audio::mix_audio_to_reference_shape(inputs, normalize); |
| 941 | const auto output = resolve_workflow_path(workflow_string(step, "output"), context); |
| 942 | if (!output.parent_path().empty()) { |
| 943 | std::filesystem::create_directories(output.parent_path()); |
no test coverage detected