Skip to main content

Alignment

Struct Alignment 

Source
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

Source

pub fn num_frames(&self) -> usize

The number of frames aligned.

Source

pub fn num_phones(&self) -> usize

The number of phones in the reference this came from.

Source

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.

Source

pub fn frames(&self) -> impl ExactSizeIterator<Item = Option<usize>> + '_

The whole alignment, one entry per frame.

Source

pub fn cost(&self) -> f32

The alignment’s total cost: the acoustic scores of every frame, plus the cost of each phone given up.

Source

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.

Source

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.

Source

pub fn skipped(&self) -> Vec<usize>

The positions that took a skip transition and received no frame.

Source

pub fn acoustic_costs<'a, A>( &'a self, chain: &'a AlignChain, dense: &'a DenseFst<'a, A>, ) -> impl ExactSizeIterator<Item = f32> + 'a
where A: Arc + 'a, A::Weight: FromScore,

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.

Source

pub fn mean_acoustic_cost<A>( &self, chain: &AlignChain, dense: &DenseFst<'_, A>, ) -> f32
where A: Arc, A::Weight: FromScore,

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Alignment

Source§

fn clone(&self) -> Alignment

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Alignment

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Alignment

Source§

fn eq(&self, other: &Alignment) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Alignment

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.