Skip to main content

Crate phonetisaurus_g2p

Crate phonetisaurus_g2p 

Source
Expand description

§Phonetisaurus-G2P

Phonemization in Rust using a finite state transducer (FST) trained with Phonetisaurus.

Allows easy usage of a Phonetisaurus-trained FST for grapheme-to-phoneme conversion. Based on rustfst, a Rust implementation of FSTs compatible with OpenFST models, and thus also with Phonetisaurus. In theory, this library can be used with all OpenFST models, but only Phonetisaurus was tested and some details might only be applicable for Phonetisaurus1.

Note that the API might slightly change in the future.

§Usage

Include the Phonetisaurus model in the binary:

use phonetisaurus_g2p::PhonetisaurusModel;

static PHONETISAURUS_MODEL: &[u8] = include_bytes!("model.fst");

fn main() {
    let phonemizer = PhonetisaurusModel::try_from(PHONETISAURUS_MODEL).unwrap();

    let result = phonemizer.phonemize_word("world").unwrap();
    assert_eq!(result.phonemes, "wˈɜɹld")
}

Or load it from disk during runtime:

use phonetisaurus_g2p::PhonetisaurusModel;
use std::path::Path;

fn main() {
    let phonemizer = PhonetisaurusModel::try_from(Path::new("model.fst")).unwrap();

    let result = phonemizer.phonemize_word("world").unwrap();
    assert_eq!(result.phonemes, "wˈɜɹld")
}

  1. For example, the “_” output symbol is skipped in this library, as are “|” chars within output symbols. 

Structs§

PhonetisaurusModel
Phonemizer struct.
PhonetizationResult
Result of a phonemization.