Fixed infinite loop with short recordings

This commit is contained in:
Daniel Wolf 2016-08-11 15:45:16 +02:00
parent 78027ea63c
commit 81111ef96a
2 changed files with 16 additions and 2 deletions

View File

@ -2,7 +2,6 @@
#include <functional>
#include "ProgressBar.h"
#include <boost/optional/optional.hpp>
#include <gsl_util.h>
template<typename TCollection>
@ -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<void>;
std::mutex mutex;

View File

@ -444,7 +444,10 @@ BoundedTimeline<Phone> detectPhones(
// Don't waste time creating additional threads (and decoders!) if the recording is short
static_cast<int>(duration_cast<std::chrono::seconds>(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");
}