Skip to main content

phonetisaurus_g2p/
lib.rs

1//! # Phonetisaurus-G2P
2//! Phonemization in Rust using a finite state transducer (FST) trained with [Phonetisaurus](https://github.com/AdolfVonKleist/Phonetisaurus).
3//!
4//! Allows easy usage of a Phonetisaurus-trained FST for grapheme-to-phoneme conversion. Based on [`rustfst`](https://docs.rs/rustfst/latest/rustfst/),
5//! a Rust implementation of FSTs compatible with OpenFST models, and thus also with Phonetisaurus. In theory, this library can be used with all
6//! OpenFST models, but only Phonetisaurus was tested and some details might only be applicable for Phonetisaurus[^note].
7//! [^note]: For example, the "_" output symbol is skipped in this library, as are "|" chars within output symbols.
8//!
9//! Note that the API might slightly change in the future.
10//!
11//! ## Usage
12//!
13//! Include the Phonetisaurus model in the binary:
14//! ```no_run
15//! use phonetisaurus_g2p::PhonetisaurusModel;
16//!
17//! static PHONETISAURUS_MODEL: &[u8] = include_bytes!("model.fst");
18//!
19//! fn main() {
20//!     let phonemizer = PhonetisaurusModel::try_from(PHONETISAURUS_MODEL).unwrap();
21//!
22//!     let result = phonemizer.phonemize_word("world").unwrap();
23//!     assert_eq!(result.phonemes, "wˈɜɹld")
24//! }
25//! ```
26//!
27//!
28//! Or load it from disk during runtime:
29//! ```no_run
30//! use phonetisaurus_g2p::PhonetisaurusModel;
31//! use std::path::Path;
32//!
33//! fn main() {
34//!     let phonemizer = PhonetisaurusModel::try_from(Path::new("model.fst")).unwrap();
35//!
36//!     let result = phonemizer.phonemize_word("world").unwrap();
37//!     assert_eq!(result.phonemes, "wˈɜɹld")
38//! }
39mod phonetisaurus_g2p;
40pub use phonetisaurus_g2p::*;