Skip to main content

espeak_ng_data_dicts/
lib.rs

1//! Language dictionaries for eSpeak NG (all languages except Russian), embedded at compile time.
2//!
3//! Contains 113 compiled language dictionaries for eSpeak NG 1.52.0:
4//! Afrikaans, Amharic, Arabic, Basque, Bengali, Bulgarian, Cantonese,
5//! Catalan, Chinese (Mandarin), Croatian, Czech, Danish, Dutch, English,
6//! Esperanto, Estonian, Finnish, French, Galician, German, Greek, …
7//! and many more.
8//!
9//! The Russian dictionary is published separately as
10//! [`espeak-ng-data-dict-ru`](https://crates.io/crates/espeak-ng-data-dict-ru)
11//! because of its size (~8 MB).
12//!
13//! ## Usage
14//!
15//! ```rust,no_run
16//! use std::path::Path;
17//!
18//! let data_dir = Path::new("/tmp/espeak-data");
19//! espeak_ng_data_dicts::install(data_dir).unwrap();
20//! ```
21
22include!(concat!(env!("OUT_DIR"), "/files.rs"));
23
24/// Install all embedded language dictionaries into `dest_dir`.
25pub fn install(dest_dir: &std::path::Path) -> std::io::Result<()> {
26    for (rel_path, data) in ALL_FILES {
27        let dest = dest_dir.join(rel_path);
28        if let Some(parent) = dest.parent() {
29            std::fs::create_dir_all(parent)?;
30        }
31        std::fs::write(dest, data)?;
32    }
33    Ok(())
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn all_files_nonempty() {
42        assert!(!ALL_FILES.is_empty(), "ALL_FILES must not be empty");
43        for (path, data) in ALL_FILES {
44            assert!(!data.is_empty(), "embedded file {path:?} is empty");
45        }
46    }
47}