Skip to content

Commit

Permalink
Fix word boundaries in ctm dumps of lattices with subsampling (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimBe195 committed Mar 27, 2024
1 parent 1c02798 commit a942e39
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Flf/Traceback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class DumpTracebackNode : public FilterNode {
static const Core::ParameterBool paramDumpPhonemeAlignment;
static const Core::ParameterBool paramDumpSubwordAlignment;
static const Core::ParameterBool paramFillEmptySegments;
static const Core::ParameterFloat paramFrameShiftTime;

private:
Core::Channel dump_;
Expand All @@ -82,6 +83,7 @@ class DumpTracebackNode : public FilterNode {
bool dumpPhonemeAlignment_;
bool dumpSubwordAlignment_;
bool fillEmptySegments_;
float frameShiftTime_;
LatticeAlignmentBuilderRef alignmentBuilder_;

protected:
Expand Down Expand Up @@ -370,8 +372,8 @@ class DumpTracebackNode : public FilterNode {
verify(sr->nArcs() == 1);
const Arc& a = *sr->begin();
const Boundary &leftBoundary = boundaries.get(sr->id()), &rightBoundary = boundaries.get(a.target());
f32 wordBegin = f32(leftBoundary.time()) / 100.00;
f32 wordEnd = f32(rightBoundary.time()) / 100.00;
f32 wordBegin = f32(leftBoundary.time()) * frameShiftTime_;
f32 wordEnd = f32(rightBoundary.time()) * frameShiftTime_;
if (wordBegin < wordEnd) {
if (lAlphabet || lpAlphabet) {
std::string word;
Expand Down Expand Up @@ -580,6 +582,7 @@ class DumpTracebackNode : public FilterNode {
dumpPhonemeAlignment_ = paramDumpPhonemeAlignment(ctmConfig);
dumpSubwordAlignment_ = paramDumpSubwordAlignment(ctmConfig);
fillEmptySegments_ = paramFillEmptySegments(ctmConfig);
frameShiftTime_ = paramFrameShiftTime(ctmConfig);
if (dumpPhonemeAlignment_ || dumpSubwordAlignment_) {
createAlignmentBuilder(ctmConfig);
}
Expand Down Expand Up @@ -684,6 +687,10 @@ const Core::ParameterBool DumpTracebackNode::paramFillEmptySegments(
"fill-empty-segments",
"fill empty segments (can fix issues with sclite complaining about unsynchronized files if a segment is missing from the ctm file)",
false);
const Core::ParameterFloat DumpTracebackNode::paramFrameShiftTime(
"frame-shift-time",
"shift-time of frames of the lattice time axis in seconds. Defaults to 0.01 = 10ms. Important for correct word boundaries when subsampling is used.",
0.01);
NodeRef createDumpTracebackNode(const std::string& name, const Core::Configuration& config) {
return NodeRef(new DumpTracebackNode(name, config));
}
Expand Down

0 comments on commit a942e39

Please sign in to comment.