Add ability to detect screen readers. Windows-only for now, and requires the `tolk` feature.

This commit is contained in:
Nolan Darilek 2021-05-11 19:37:56 -05:00
parent 7b8da53d81
commit 4088eb12a1
2 changed files with 22 additions and 0 deletions

View File

@ -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,
..

View File

@ -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 {