mirror of
https://github.com/ndarilek/tts-rs.git
synced 2024-11-22 22: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:
parent
e0863c7b6a
commit
4f011e6895
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
17
src/lib.rs
17
src/lib.rs
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user