mirror of
https://github.com/ndarilek/tts-rs.git
synced 2024-11-23 06:49:38 +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);
|
pub struct Tolk(TolkPtr);
|
||||||
|
|
||||||
impl Tolk {
|
impl Tolk {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Option<Self> {
|
||||||
info!("Initializing Tolk backend");
|
info!("Initializing Tolk backend");
|
||||||
let tolk = TolkPtr::new();
|
let tolk = TolkPtr::new();
|
||||||
tolk.try_sapi(true);
|
if tolk.detect_screen_reader().is_some() {
|
||||||
Tolk(tolk)
|
Some(Tolk(tolk))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
src/lib.rs
11
src/lib.rs
|
@ -93,7 +93,11 @@ impl TTS {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
Backends::Tolk => {
|
Backends::Tolk => {
|
||||||
let tts = backends::Tolk::new();
|
let tts = backends::Tolk::new();
|
||||||
|
if let Some(tts) = tts {
|
||||||
Ok(TTS(Box::new(tts)))
|
Ok(TTS(Box::new(tts)))
|
||||||
|
} else {
|
||||||
|
Err(Error::NoneError)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
Backends::WinRT => {
|
Backends::WinRT => {
|
||||||
|
@ -107,13 +111,10 @@ impl TTS {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
let tts = TTS::new(Backends::SpeechDispatcher);
|
let tts = TTS::new(Backends::SpeechDispatcher);
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
let tts = {
|
let tts = if let Some(tts) = TTS::new(Backends::Tolk).ok() {
|
||||||
let tolk = tolk::Tolk::new();
|
Ok(tts)
|
||||||
if tolk.detect_screen_reader().is_some() {
|
|
||||||
TTS::new(Backends::Tolk)
|
|
||||||
} else {
|
} else {
|
||||||
TTS::new(Backends::WinRT)
|
TTS::new(Backends::WinRT)
|
||||||
}
|
|
||||||
};
|
};
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
let tts = TTS::new(Backends::Web);
|
let tts = TTS::new(Backends::Web);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user