Skip to main content

espeak_ng_data_phonemes/
lib.rs

1//! Core eSpeak NG phoneme data, embedded at compile time.
2//!
3//! Contains the binary phoneme tables, language definitions, and voice
4//! definitions shared by all languages:
5//!
6//! | File | Description |
7//! |------|-------------|
8//! | `phondata` | Formant frame sequences and WAV samples |
9//! | `phonindex` | Phoneme bytecode index |
10//! | `phontab` | Phoneme name/attribute table |
11//! | `intonations` | Intonation contour data |
12//! | `lang/*` | Language definition files (145 languages) |
13//! | `voices/*` | Voice definition files (200 voices) |
14//! | `mbrola_ph/*` | MBROLA phoneme mappings |
15//!
16//! ## Usage
17//!
18//! ```rust,no_run
19//! use std::path::Path;
20//!
21//! // Install all files into a directory (e.g. a temp dir)
22//! let data_dir = Path::new("/tmp/espeak-data");
23//! std::fs::create_dir_all(data_dir).unwrap();
24//! espeak_ng_data_phonemes::install(data_dir).unwrap();
25//! ```
26
27// Generated by build.rs — contains `ALL_FILES: &[(&str, &[u8])]`.
28include!(concat!(env!("OUT_DIR"), "/files.rs"));
29
30/// Install all embedded data files into `dest_dir`.
31///
32/// Creates any missing subdirectories.  Existing files are silently
33/// overwritten.  This is idempotent — calling it multiple times on the
34/// same directory is safe.
35///
36/// # Errors
37/// Returns an [`std::io::Error`] if a directory cannot be created or a
38/// file cannot be written.
39pub fn install(dest_dir: &std::path::Path) -> std::io::Result<()> {
40    for (rel_path, data) in ALL_FILES {
41        let dest = dest_dir.join(rel_path);
42        if let Some(parent) = dest.parent() {
43            std::fs::create_dir_all(parent)?;
44        }
45        std::fs::write(dest, data)?;
46    }
47    Ok(())
48}
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn all_files_nonempty() {
56        assert!(!ALL_FILES.is_empty(), "ALL_FILES must not be empty");
57        for (path, data) in ALL_FILES {
58            assert!(!data.is_empty(), "embedded file {path:?} is empty");
59        }
60    }
61}