1
0
mirror of https://github.com/ndarilek/tts-rs.git synced 2024-11-23 02:59:37 +00:00

Get Tolk working again.

Two Tolk instances were being created. One checked for the presence of a screen reader. The other actually performed the speech, and was returned as part of the `TTS` instance.

Unfortunately, Tolk doesn't seem to appreciate being called twice. So here we check if a screen reader is detected and, if one is, return the instance that did the detection. Otherwise, error out and return the WinRT backend.
This commit is contained in:
Nolan Darilek 2020-06-11 13:00:24 -05:00
parent e0863c7b6a
commit 4f011e6895
2 changed files with 15 additions and 11 deletions

View File

@ -7,11 +7,14 @@ use crate::{Backend, Error, Features};
pub struct Tolk(TolkPtr);
impl Tolk {
pub fn new() -> Self {
pub fn new() -> Option<Self> {
info!("Initializing Tolk backend");
let tolk = TolkPtr::new();
tolk.try_sapi(true);
Tolk(tolk)
if tolk.detect_screen_reader().is_some() {
Some(Tolk(tolk))
} else {
None
}
}
}

View File

@ -93,7 +93,11 @@ impl TTS {
#[cfg(windows)]
Backends::Tolk => {
let tts = backends::Tolk::new();
Ok(TTS(Box::new(tts)))
if let Some(tts) = tts {
Ok(TTS(Box::new(tts)))
} else {
Err(Error::NoneError)
}
}
#[cfg(windows)]
Backends::WinRT => {
@ -107,13 +111,10 @@ impl TTS {
#[cfg(target_os = "linux")]
let tts = TTS::new(Backends::SpeechDispatcher);
#[cfg(windows)]
let tts = {
let tolk = tolk::Tolk::new();
if tolk.detect_screen_reader().is_some() {
TTS::new(Backends::Tolk)
} else {
TTS::new(Backends::WinRT)
}
let tts = if let Some(tts) = TTS::new(Backends::Tolk).ok() {
Ok(tts)
} else {
TTS::new(Backends::WinRT)
};
#[cfg(target_arch = "wasm32")]
let tts = TTS::new(Backends::Web);