wetext_rs/lib.rs
1//! # WeText-RS: Text Normalization Library
2//!
3//! A Rust implementation of WeText for text normalization in TTS (Text-to-Speech) applications.
4//!
5//! ## Features
6//!
7//! - **Text Normalization (TN)**: Convert numbers, dates, currency to spoken form
8//! - **Inverse Text Normalization (ITN)**: Convert spoken form back to written form
9//! - **Multi-language support**: Chinese (zh), English (en), Japanese (ja)
10//!
11//! ## Example
12//!
13//! ```rust,ignore
14//! use wetext_rs::{Normalizer, NormalizerConfig, Language};
15//!
16//! let config = NormalizerConfig::new()
17//! .with_lang(Language::Zh);
18//!
19//! let mut normalizer = Normalizer::new("path/to/fsts", config);
20//! let result = normalizer.normalize("2024年1月15日").unwrap();
21//! println!("{}", result); // 二零二四年一月十五日
22//! ```
23
24mod config;
25mod contractions;
26mod error;
27mod normalizer;
28mod text_normalizer;
29mod token_parser;
30
31pub use config::{Language, NormalizerConfig, Operator};
32pub use error::{Result, WeTextError};
33pub use normalizer::Normalizer;
34
35/// Convenience function: normalize text with default configuration
36///
37/// # Arguments
38/// * `fst_dir` - Directory containing FST weight files
39/// * `text` - Text to normalize
40///
41/// # Returns
42/// Normalized text string
43///
44/// # Example
45/// ```rust,ignore
46/// let result = wetext_rs::normalize("path/to/fsts", "123").unwrap();
47/// assert_eq!(result, "一百二十三");
48/// ```
49pub fn normalize<P: AsRef<std::path::Path>>(fst_dir: P, text: &str) -> Result<String> {
50 let mut normalizer = Normalizer::with_defaults(fst_dir);
51 normalizer.normalize(text)
52}