From 4088eb12a172a70e581f5fb627e505bacbe34029 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 11 May 2021 19:37:56 -0500 Subject: [PATCH] Add ability to detect screen readers. Windows-only for now, and requires the `tolk` feature. --- examples/hello_world.rs | 5 +++++ src/lib.rs | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index f737f3f..1db3ed3 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -12,6 +12,11 @@ use tts::*; fn main() -> Result<(), Error> { env_logger::init(); let mut tts = Tts::default()?; + if Tts::screen_reader_available() { + println!("A screen reader is available on this platform."); + } else { + println!("No screen reader is available on this platform."); + } let Features { utterance_callbacks, .. diff --git a/src/lib.rs b/src/lib.rs index 1901556..50af8ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -527,6 +527,23 @@ impl Tts { Err(Error::UnsupportedFeature) } } + + /* + * Returns `true` if a screen reader is available to provide speech. + */ + pub fn screen_reader_available() -> bool { + if cfg!(target_os = "windows") { + #[cfg(feature = "tolk")] + { + let tolk = tolk::Tolk::new(); + return tolk.detect_screen_reader().is_some(); + } + #[cfg(not(feature = "tolk"))] + return false; + } else { + false + } + } } impl Drop for Tts {