diff --git a/src/audio/WaveFileReader.cpp b/src/audio/WaveFileReader.cpp index 45600fe..898c457 100644 --- a/src/audio/WaveFileReader.cpp +++ b/src/audio/WaveFileReader.cpp @@ -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(sampleIndex * channelCount * bytesPerSample)); this->sampleIndex = sampleIndex; diff --git a/src/main.cpp b/src/main.cpp index 35567cb..4416ca7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,20 +50,22 @@ ptree createXmlTree(const path& filePath, const Timeline& 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(".start", formatDuration(timedPhone.getStart())); - phoneElement.add(".duration", formatDuration(timedPhone.getLength())); + phoneElement.put(".start", formatDuration(timedPhone.getStart())); + phoneElement.put(".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(".start", formatDuration(timedShape.getStart())); - mouthCueElement.add(".duration", formatDuration(timedShape.getLength())); + mouthCueElement.put(".start", formatDuration(timedShape.getStart())); + mouthCueElement.put(".duration", formatDuration(timedShape.getLength())); } return tree; diff --git a/src/phoneExtraction.cpp b/src/phoneExtraction.cpp index e5fdf04..42b315e 100644 --- a/src/phoneExtraction.cpp +++ b/src/phoneExtraction.cpp @@ -288,6 +288,11 @@ Timeline detectPhones( boost::optional dialog, ProgressSink& progressSink) { + // Pocketsphinx doesn't like empty input + if (audioStream->getTruncatedRange().getLength() == centiseconds::zero()) { + return Timeline{}; + } + // Discard Pocketsphinx output err_set_logfp(nullptr);