Handling zero-length audio files
This commit is contained in:
parent
7bc4e37a1a
commit
90e1375f1b
|
@ -185,7 +185,7 @@ int WaveFileReader::getSampleIndex() {
|
|||
}
|
||||
|
||||
void WaveFileReader::seek(int sampleIndex) {
|
||||
if (sampleIndex < 0 || sampleIndex >= sampleCount) throw std::invalid_argument("sampleIndex out of range.");
|
||||
if (sampleIndex < 0 || sampleIndex > sampleCount) throw std::invalid_argument("sampleIndex out of range.");
|
||||
|
||||
file.seekg(dataOffset + static_cast<std::streamoff>(sampleIndex * channelCount * bytesPerSample));
|
||||
this->sampleIndex = sampleIndex;
|
||||
|
|
12
src/main.cpp
12
src/main.cpp
|
@ -50,20 +50,22 @@ ptree createXmlTree(const path& filePath, const Timeline<Phone>& phones, const T
|
|||
ptree tree;
|
||||
|
||||
// Add sound file path
|
||||
tree.add("rhubarbResult.info.soundFile", filePath.string());
|
||||
tree.put("rhubarbResult.info.soundFile", filePath.string());
|
||||
|
||||
// Add phones
|
||||
tree.put("rhubarbResult.phones", "");
|
||||
for (auto& timedPhone : phones) {
|
||||
ptree& phoneElement = tree.add("rhubarbResult.phones.phone", timedPhone.getValue());
|
||||
phoneElement.add("<xmlattr>.start", formatDuration(timedPhone.getStart()));
|
||||
phoneElement.add("<xmlattr>.duration", formatDuration(timedPhone.getLength()));
|
||||
phoneElement.put("<xmlattr>.start", formatDuration(timedPhone.getStart()));
|
||||
phoneElement.put("<xmlattr>.duration", formatDuration(timedPhone.getLength()));
|
||||
}
|
||||
|
||||
// Add mouth cues
|
||||
tree.put("rhubarbResult.mouthCues", "");
|
||||
for (auto& timedShape : shapes) {
|
||||
ptree& mouthCueElement = tree.add("rhubarbResult.mouthCues.mouthCue", timedShape.getValue());
|
||||
mouthCueElement.add("<xmlattr>.start", formatDuration(timedShape.getStart()));
|
||||
mouthCueElement.add("<xmlattr>.duration", formatDuration(timedShape.getLength()));
|
||||
mouthCueElement.put("<xmlattr>.start", formatDuration(timedShape.getStart()));
|
||||
mouthCueElement.put("<xmlattr>.duration", formatDuration(timedShape.getLength()));
|
||||
}
|
||||
|
||||
return tree;
|
||||
|
|
|
@ -288,6 +288,11 @@ Timeline<Phone> detectPhones(
|
|||
boost::optional<std::string> dialog,
|
||||
ProgressSink& progressSink)
|
||||
{
|
||||
// Pocketsphinx doesn't like empty input
|
||||
if (audioStream->getTruncatedRange().getLength() == centiseconds::zero()) {
|
||||
return Timeline<Phone>{};
|
||||
}
|
||||
|
||||
// Discard Pocketsphinx output
|
||||
err_set_logfp(nullptr);
|
||||
|
||||
|
|
Loading…
Reference in New Issue