Thread count can be limited via command-line argument
This commit is contained in:
parent
206cde4658
commit
78027ea63c
|
@ -66,7 +66,7 @@ BoundedTimeline<void> webRtcDetectVoiceActivity(const AudioClip& audioClip, Prog
|
||||||
return activity;
|
return activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
BoundedTimeline<void> detectVoiceActivity(const AudioClip& inputAudioClip, ProgressSink& progressSink) {
|
BoundedTimeline<void> detectVoiceActivity(const AudioClip& inputAudioClip, int maxThreadCount, ProgressSink& progressSink) {
|
||||||
// Prepare audio for VAD
|
// Prepare audio for VAD
|
||||||
const unique_ptr<AudioClip> audioClip = inputAudioClip.clone() | resample(16000) | removeDCOffset();
|
const unique_ptr<AudioClip> audioClip = inputAudioClip.clone() | resample(16000) | removeDCOffset();
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ BoundedTimeline<void> detectVoiceActivity(const AudioClip& inputAudioClip, Progr
|
||||||
std::mutex activityMutex;
|
std::mutex activityMutex;
|
||||||
|
|
||||||
// Split audio into segments and perform parallel VAD
|
// Split audio into segments and perform parallel VAD
|
||||||
int segmentCount = getProcessorCoreCount();
|
const int segmentCount = maxThreadCount;
|
||||||
centiseconds audioLength = audioClip->getTruncatedRange().getLength();
|
centiseconds audioLength = audioClip->getTruncatedRange().getLength();
|
||||||
vector<TimeRange> audioSegments;
|
vector<TimeRange> audioSegments;
|
||||||
for (int i = 0; i < segmentCount; ++i) {
|
for (int i = 0; i < segmentCount; ++i) {
|
||||||
|
|
|
@ -3,4 +3,4 @@
|
||||||
#include <BoundedTimeline.h>
|
#include <BoundedTimeline.h>
|
||||||
#include <ProgressBar.h>
|
#include <ProgressBar.h>
|
||||||
|
|
||||||
BoundedTimeline<void> detectVoiceActivity(const AudioClip& audioClip, ProgressSink& progressSink);
|
BoundedTimeline<void> detectVoiceActivity(const AudioClip& audioClip, int maxThreadCount, ProgressSink& progressSink);
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "stringTools.h"
|
#include "stringTools.h"
|
||||||
#include <boost/range/adaptor/transformed.hpp>
|
#include <boost/range/adaptor/transformed.hpp>
|
||||||
#include <boost/filesystem/fstream.hpp>
|
#include <boost/filesystem/fstream.hpp>
|
||||||
|
#include "parallel.h"
|
||||||
|
|
||||||
using std::exception;
|
using std::exception;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
@ -115,6 +116,7 @@ int main(int argc, char *argv[]) {
|
||||||
tclap::ValuesConstraint<logging::Level> logLevelConstraint(logLevels);
|
tclap::ValuesConstraint<logging::Level> logLevelConstraint(logLevels);
|
||||||
tclap::ValueArg<logging::Level> logLevel("", "logLevel", "The minimum log level to log", false, logging::Level::Debug, &logLevelConstraint, cmd);
|
tclap::ValueArg<logging::Level> logLevel("", "logLevel", "The minimum log level to log", false, logging::Level::Debug, &logLevelConstraint, cmd);
|
||||||
tclap::ValueArg<string> logFileName("", "logFile", "The log file path.", false, string(), "string", cmd);
|
tclap::ValueArg<string> logFileName("", "logFile", "The log file path.", false, string(), "string", cmd);
|
||||||
|
tclap::ValueArg<int> maxThreadCount("", "threads", "The maximum number of worker threads to use.", false, getProcessorCoreCount(), "number", cmd);
|
||||||
tclap::ValueArg<string> dialogFile("d", "dialogFile", "A file containing the text of the dialog.", false, string(), "string", cmd);
|
tclap::ValueArg<string> dialogFile("d", "dialogFile", "A file containing the text of the dialog.", false, string(), "string", cmd);
|
||||||
auto exportFormats = vector<ExportFormat>(ExportFormatConverter::get().getValues());
|
auto exportFormats = vector<ExportFormat>(ExportFormatConverter::get().getValues());
|
||||||
tclap::ValuesConstraint<ExportFormat> exportFormatConstraint(exportFormats);
|
tclap::ValuesConstraint<ExportFormat> exportFormatConstraint(exportFormats);
|
||||||
|
@ -132,6 +134,9 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
// Parse command line
|
// Parse command line
|
||||||
cmd.parse(argc, argv);
|
cmd.parse(argc, argv);
|
||||||
|
if (maxThreadCount.getValue() < 1) {
|
||||||
|
throw std::runtime_error("Thread count must be 1 or higher.");
|
||||||
|
}
|
||||||
|
|
||||||
// Set up log file
|
// Set up log file
|
||||||
if (logFileName.isSet()) {
|
if (logFileName.isSet()) {
|
||||||
|
@ -151,6 +156,7 @@ int main(int argc, char *argv[]) {
|
||||||
phones = detectPhones(
|
phones = detectPhones(
|
||||||
*createAudioClip(inputFileName.getValue()),
|
*createAudioClip(inputFileName.getValue()),
|
||||||
dialogFile.isSet() ? readTextFile(path(dialogFile.getValue())) : boost::optional<u32string>(),
|
dialogFile.isSet() ? readTextFile(path(dialogFile.getValue())) : boost::optional<u32string>(),
|
||||||
|
maxThreadCount.getValue(),
|
||||||
progressBar);
|
progressBar);
|
||||||
}
|
}
|
||||||
std::cerr << "Done" << std::endl;
|
std::cerr << "Done" << std::endl;
|
||||||
|
|
|
@ -359,6 +359,7 @@ Timeline<void> getUnknownSounds(const Timeline<void>& utterances, const Timeline
|
||||||
BoundedTimeline<Phone> detectPhones(
|
BoundedTimeline<Phone> detectPhones(
|
||||||
const AudioClip& inputAudioClip,
|
const AudioClip& inputAudioClip,
|
||||||
optional<u32string> dialog,
|
optional<u32string> dialog,
|
||||||
|
int maxThreadCount,
|
||||||
ProgressSink& progressSink)
|
ProgressSink& progressSink)
|
||||||
{
|
{
|
||||||
ProgressMerger totalProgressMerger(progressSink);
|
ProgressMerger totalProgressMerger(progressSink);
|
||||||
|
@ -371,7 +372,7 @@ BoundedTimeline<Phone> detectPhones(
|
||||||
// Split audio into utterances
|
// Split audio into utterances
|
||||||
BoundedTimeline<void> utterances;
|
BoundedTimeline<void> utterances;
|
||||||
try {
|
try {
|
||||||
utterances = detectVoiceActivity(*audioClip, voiceActivationProgressSink);
|
utterances = detectVoiceActivity(*audioClip, maxThreadCount, voiceActivationProgressSink);
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
std::throw_with_nested(runtime_error("Error detecting segments of speech."));
|
std::throw_with_nested(runtime_error("Error detecting segments of speech."));
|
||||||
|
@ -437,8 +438,7 @@ BoundedTimeline<Phone> detectPhones(
|
||||||
try {
|
try {
|
||||||
// Determine how many parallel threads to use
|
// Determine how many parallel threads to use
|
||||||
int threadCount = std::min({
|
int threadCount = std::min({
|
||||||
// Don't use more threads than there are CPU cores
|
maxThreadCount,
|
||||||
getProcessorCoreCount(),
|
|
||||||
// Don't use more threads than there are utterances to be processed
|
// Don't use more threads than there are utterances to be processed
|
||||||
static_cast<int>(utterances.size()),
|
static_cast<int>(utterances.size()),
|
||||||
// Don't waste time creating additional threads (and decoders!) if the recording is short
|
// Don't waste time creating additional threads (and decoders!) if the recording is short
|
||||||
|
|
|
@ -8,4 +8,5 @@
|
||||||
BoundedTimeline<Phone> detectPhones(
|
BoundedTimeline<Phone> detectPhones(
|
||||||
const AudioClip& audioClip,
|
const AudioClip& audioClip,
|
||||||
boost::optional<std::u32string> dialog,
|
boost::optional<std::u32string> dialog,
|
||||||
|
int maxThreadCount,
|
||||||
ProgressSink& progressSink);
|
ProgressSink& progressSink);
|
||||||
|
|
Loading…
Reference in New Issue