diff --git a/Cargo.toml b/Cargo.toml index fcbc8dc..9cd9313 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,9 @@ log = "0.4" [dev-dependencies] env_logger = "0.6" +[target.'cfg(windows)'.dependencies] +tolk = { git = "https://github.com/ndarilek/tolk-rs" } + [target.'cfg(target_os = "linux")'.dependencies] speech-dispatcher = "0.2" diff --git a/src/backends/mod.rs b/src/backends/mod.rs index 9fd026a..ae26aec 100644 --- a/src/backends/mod.rs +++ b/src/backends/mod.rs @@ -1,11 +1,17 @@ #[cfg(target_os = "linux")] mod speech_dispatcher; +#[cfg(windows)] +mod tolk; + #[cfg(target_arch = "wasm32")] mod web; #[cfg(target_os = "linux")] pub use self::speech_dispatcher::*; +#[cfg(windows)] +pub use self::tolk::*; + #[cfg(target_arch = "wasm32")] pub use self::web::*; diff --git a/src/backends/tolk.rs b/src/backends/tolk.rs new file mode 100644 index 0000000..5e93850 --- /dev/null +++ b/src/backends/tolk.rs @@ -0,0 +1,61 @@ +#[cfg(windows)] +use log::{info, trace}; +use tolk::Tolk as TolkPtr; + +use crate::{Backend, Error, Features}; + +pub struct Tolk(TolkPtr); + +impl Tolk { + pub fn new() -> impl Backend { + info!("Initializing Tolk backend"); + let tolk = TolkPtr::new(); + Tolk(tolk) + } +} + +impl Backend for Tolk { + fn supported_features(&self) -> Features { + Features { + stop: false, + rate: false, + pitch: false, + volume: false, + } + } + + fn speak(&self, text: &str, interrupt: bool) -> Result<(), Error> { + trace!("speak({}, {})", text, interrupt); + self.0.speak(text, interrupt); + Ok(()) + } + + fn stop(&self) -> Result<(), Error> { + trace!("stop()"); + unimplemented!(); + } + + fn get_rate(&self) -> Result { + unimplemented!(); + } + + fn set_rate(&mut self, _rate: u8) -> Result<(), Error> { + unimplemented!(); + } + + fn get_pitch(&self) -> Result { + unimplemented!(); + } + + fn set_pitch(&mut self, _pitch: u8) -> Result<(), Error> { + unimplemented!(); + } + + fn get_volume(&self) -> Result { + unimplemented!(); + } + + fn set_volume(&mut self, _volume: u8) -> Result<(), Error> { + unimplemented!(); + } +} diff --git a/src/lib.rs b/src/lib.rs index 1594f18..d2d4b6a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,8 @@ pub enum Backends { SpeechDispatcher, #[cfg(target_arch = "wasm32")] Web, + #[cfg(windows)] + Tolk, } #[derive(Debug, Fail)] @@ -75,12 +77,19 @@ impl TTS { let tts = backends::Web::new()?; Ok(TTS(Box::new(tts))) } + #[cfg(windows)] + Backends::Tolk => { + let tts = backends::Tolk::new(); + Ok(TTS(Box::new(tts))) + } } } pub fn default() -> Result { #[cfg(target_os = "linux")] let tts = TTS::new(Backends::SpeechDispatcher); + #[cfg(windows)] + let tts = TTS::new(Backends::Tolk); #[cfg(target_arch = "wasm32")] let tts = TTS::new(Backends::Web); tts