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

Function build_audio_dir_batch

app/cli/batch.cpp:205–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203}
204
205minitts::app::AppBatchRequest build_audio_dir_batch(
206 const std::filesystem::path & dir,
207 const engine::runtime::TaskRequest & base_request,
208 const std::string & audio_role) {
209 if (!std::filesystem::is_directory(dir)) {
210 throw std::runtime_error("--batch-audio-dir must be an existing directory: " + dir.string());
211 }
212 std::vector<std::filesystem::path> audio_paths;
213 for (const auto & entry : std::filesystem::directory_iterator(dir)) {
214 if (entry.is_regular_file() && is_wav_path(entry.path())) {
215 audio_paths.push_back(entry.path());
216 }
217 }
218 std::sort(audio_paths.begin(), audio_paths.end());
219 minitts::app::AppBatchRequest batch;
220 batch.requests.reserve(audio_paths.size());
221 for (const auto & path : audio_paths) {
222 auto request = base_request;
223 if (audio_role == "audio") {
224 request.audio_input = read_audio_buffer(path);
225 } else if (audio_role == "voice_ref") {
226 if (!request.voice.has_value()) {
227 request.voice = engine::runtime::VoiceCondition{};
228 }
229 if (!request.voice->speaker.has_value()) {
230 request.voice->speaker = engine::runtime::VoiceReference{};
231 }
232 request.voice->speaker->audio = read_audio_buffer(path);
233 } else if (audio_role == "source_audio" ||
234 audio_role == "target_voice" ||
235 audio_role == "prosody_ref" ||
236 audio_role == "style_ref") {
237 set_option(request.options, audio_role, path.string());
238 } else {
239 throw std::runtime_error(
240 "--batch-audio-role must be audio, voice_ref, source_audio, target_voice, prosody_ref, or style_ref");
241 }
242 batch.requests.push_back(minitts::app::AppRequest{path.stem().string(), std::move(request)});
243 }
244 if (batch.requests.empty()) {
245 throw std::runtime_error("--batch-audio-dir contains no .wav files: " + dir.string());
246 }
247 return batch;
248}
249
250} // namespace
251

Callers 1

Calls 7

set_optionFunction · 0.85
is_wav_pathFunction · 0.70
read_audio_bufferFunction · 0.70
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected