diff --git a/src/parallel.h b/src/parallel.h index 4a6daa8..cca4164 100644 --- a/src/parallel.h +++ b/src/parallel.h @@ -2,7 +2,6 @@ #include #include "ProgressBar.h" -#include #include template @@ -11,6 +10,18 @@ void runParallel( TCollection& collection, int maxThreadCount) { + if (maxThreadCount < 1) { + throw std::invalid_argument(fmt::format("maxThreadCount cannot be {}.", maxThreadCount)); + } + + if (maxThreadCount == 1) { + // Process synchronously + for (auto& element : collection) { + processElement(element); + } + return; + } + using future_type = std::future; std::mutex mutex; diff --git a/src/phoneExtraction.cpp b/src/phoneExtraction.cpp index a40dadd..e028e57 100644 --- a/src/phoneExtraction.cpp +++ b/src/phoneExtraction.cpp @@ -444,7 +444,10 @@ BoundedTimeline detectPhones( // Don't waste time creating additional threads (and decoders!) if the recording is short static_cast(duration_cast(audioClip->getTruncatedRange().getLength()).count() / 5) }); - logging::debug("Speech recognition -- start"); + if (threadCount < 1) { + threadCount = 1; + } + logging::debugFormat("Speech recognition using {} threads -- start", threadCount); runParallel(processUtterance, utterances, threadCount, dialogProgressSink, getUtteranceProgressWeight); logging::debug("Speech recognition -- end"); }