#fst #linguistics #phonetisaurus #g2p #phonemizer

phonetisaurus-g2p

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

2 releases

Uses new Rust 2024

new 0.1.1 Apr 8, 2025
0.1.0 Apr 8, 2025

#28 in #fst

39 downloads per month

MIT license

11KB
106 lines

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 Phonetisaurus.

Note that the API might slightly change in the future.

Usage

To use the crate, add the following to your Cargo.toml:

[dependencies]
phonetisaurus-g2p = "0.1.1"

Then, you can include the model file in your binary and run it:

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;

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")
}

License

phonetisaurus-g2p-rs is licensed under the MIT License.

Dependencies

~7MB
~134K SLoC