pub struct Alignment { /* private fields */ }Expand description
Which phone each frame sounded.
Frames the reference does not account for sound nothing, and belong to no
phone; see spans for why that convention and not the other.
Implementations§
Source§impl Alignment
impl Alignment
Sourcepub fn num_frames(&self) -> usize
pub fn num_frames(&self) -> usize
The number of frames aligned.
Sourcepub fn num_phones(&self) -> usize
pub fn num_phones(&self) -> usize
The number of phones in the reference this came from.
Sourcepub fn sounding(&self, frame: usize) -> Option<usize>
pub fn sounding(&self, frame: usize) -> Option<usize>
The position sounding in frame, or None for a frame that sounded
nothing.
§Panics
If frame is past the last one.
Sourcepub fn frames(&self) -> impl ExactSizeIterator<Item = Option<usize>> + '_
pub fn frames(&self) -> impl ExactSizeIterator<Item = Option<usize>> + '_
The whole alignment, one entry per frame.
Sourcepub fn cost(&self) -> f32
pub fn cost(&self) -> f32
The alignment’s total cost: the acoustic scores of every frame, plus the cost of each phone given up.
Sourcepub fn spans(&self) -> Vec<Option<Range<usize>>>
pub fn spans(&self) -> Vec<Option<Range<usize>>>
The frames each position occupies, as [first frame sounding it, last frame sounding it + 1), or None for a position no frame sounded.
Frames assigned to the blank belong to no phone. In particular, trailing silence is not included in the last phone’s span.
Sourcepub fn group_spans(
&self,
sizes: &[usize],
) -> Result<Vec<Option<Range<usize>>>, OpenFstError>
pub fn group_spans( &self, sizes: &[usize], ) -> Result<Vec<Option<Range<usize>>>, OpenFstError>
The frames each group of consecutive positions occupies, given how many positions each group holds.
The reference is flat, so a word is a run of positions, and this is how word times come out of a phone alignment: pass the phone count of each word. A group takes its first sounding frame to its last, ignoring the blanks in between, since a word does not stop existing because it has a pause in the middle of it.
A group whose phones were all skipped has no span.
§Errors
Sizes that do not add up to the number of phones aligned.
Sourcepub fn skipped(&self) -> Vec<usize>
pub fn skipped(&self) -> Vec<usize>
The positions that took a skip transition and received no frame.
Sourcepub fn acoustic_costs<'a, A>(
&'a self,
chain: &'a AlignChain,
dense: &'a DenseFst<'a, A>,
) -> impl ExactSizeIterator<Item = f32> + 'a
pub fn acoustic_costs<'a, A>( &'a self, chain: &'a AlignChain, dense: &'a DenseFst<'a, A>, ) -> impl ExactSizeIterator<Item = f32> + 'a
What each frame paid the acoustic model, in order.
Recomputed from the matrix rather than remembered: a frame that sounded
nothing paid the blank column, one that sounded position p paid p’s.
mean_acoustic_cost is available precisely
because the alignment can say this without searching again.
§Panics
If chain is not the one this was aligned against, or dense not the
matrix it was aligned to.
Sourcepub fn mean_acoustic_cost<A>(
&self,
chain: &AlignChain,
dense: &DenseFst<'_, A>,
) -> f32
pub fn mean_acoustic_cost<A>( &self, chain: &AlignChain, dense: &DenseFst<'_, A>, ) -> f32
The mean of acoustic_costs, or 0.0 for no
frames.
Scores are negative log probabilities, so smaller is better. Do not use this value to choose skip costs: allowing more skips can only reduce the acoustic portion of the score.
Sourcepub fn from_path(chain: &AlignChain, path: &Path) -> Result<Self, OpenFstError>
pub fn from_path(chain: &AlignChain, path: &Path) -> Result<Self, OpenFstError>
Reads an alignment back from a Path through
AlignChain::against.
align is this on the path best_path returns. It is separate
because the path is the more general answer: a caller may want the
transitions themselves, or may have solved the chain alongside a
topology of their own.
§Errors
A code the chain has no transition for, which means the path came from a different trellis.
Sourcepub fn from_output_labels<L: ArcLabel>(
chain: &AlignChain,
labels: &[L],
cost: f32,
) -> Result<Self, OpenFstError>
pub fn from_output_labels<L: ArcLabel>( chain: &AlignChain, labels: &[L], cost: f32, ) -> Result<Self, OpenFstError>
Reads an alignment back from a path through
AlignChain::to_fst.
The chain’s arcs all carry an output label, so a decoded path’s labels
are one per frame. That turns
lattice_decode and
n_best over the chain into alternative
alignments; align returns the best one directly.
§Errors
A label naming no position, which means the path did not come from this chain.