| 6 | namespace minitts::app { |
| 7 | namespace { |
| 8 | |
| 9 | engine::runtime::AudioBuffer concat_audio_outputs( |
| 10 | const std::vector<AppRequestResult> & results, |
| 11 | std::vector<AudioChapter> & chapters) { |
| 12 | engine::runtime::AudioBuffer merged; |
| 13 | for (const auto & item : results) { |
| 14 | if (!item.result.audio_output.has_value()) { |
| 15 | continue; |
| 16 | } |
| 17 | const auto & audio = *item.result.audio_output; |
| 18 | if (merged.sample_rate == 0) { |
| 19 | merged.sample_rate = audio.sample_rate; |
| 20 | merged.channels = audio.channels; |
| 21 | } |
| 22 | if (audio.sample_rate != merged.sample_rate || audio.channels != merged.channels) { |
| 23 | throw std::runtime_error("cannot merge batch audio outputs with different sample rates or channel counts"); |
| 24 | } |
| 25 | const int64_t start = static_cast<int64_t>(merged.samples.size() / static_cast<size_t>(merged.channels)); |
| 26 | merged.samples.insert(merged.samples.end(), audio.samples.begin(), audio.samples.end()); |
| 27 | const int64_t end = static_cast<int64_t>(merged.samples.size() / static_cast<size_t>(merged.channels)); |
| 28 | chapters.push_back(AudioChapter{item.id, start, end}); |
| 29 | } |
| 30 | if (merged.sample_rate == 0) { |
| 31 | throw std::runtime_error("batch audio merge requested but no request produced a primary audio output"); |
| 32 | } |
| 33 | return merged; |
| 34 | } |
| 35 | |
| 36 | } // namespace |
no test coverage detected