From 05d8e3ac069131da0200d62e670d1208d1bce3d5 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 10 Sep 2019 10:09:04 -0500 Subject: [PATCH] Switch to tts crate. --- Cargo.toml | 7 +------ src/lib.rs | 36 ++++++------------------------------ 2 files changed, 7 insertions(+), 36 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 667fa23..a9e7a4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,4 @@ crate-type = ["cdylib"] [dependencies] gdnative = { git = "https://github.com/ndarilek/godot-rust/" } - -[target.'cfg(unix)'.dependencies] -speech-dispatcher = "0.3" - -[target.'cfg(windows)'.dependencies] -tolk = "0.1" +tts = { path = "../../TTS-RS" } diff --git a/src/lib.rs b/src/lib.rs index 2beaa8a..bea407f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,52 +1,28 @@ use gdnative::*; -#[cfg(unix)] -use speech_dispatcher::{Connection, Mode, Priority}; -#[cfg(windows)] -use tolk::Tolk; +use tts::{TTS as Tts}; #[derive(gdnative::NativeClass)] #[inherit(gdnative::Node)] -struct TTS( - #[cfg(unix)] - Connection, - #[cfg(windows)] - Tolk, -); +struct TTS(Tts); #[methods] impl TTS { fn _init(_owner: gdnative::Node) -> Self { - #[cfg(unix)] - { - let connection = Connection::open("godot", "godot", "godot", Mode::Single); - Self(connection) - } - #[cfg(windows)] - Self(Tolk::new()) + let tts = Tts::default().unwrap(); + Self(tts) } #[export] fn speak(&mut self, _owner: Node, message: GodotString, interrupt: bool) { let message = message.to_string(); println!("{}: {}", message, interrupt); - #[cfg(unix)] - { - if interrupt { - self.0.cancel(); - } - if message != "" { - self.0.say(Priority::Important, message); - } - } + self.0.speak(message, interrupt).unwrap(); } #[export] fn stop(&mut self, _owner: Node) { - #[cfg(unix)] - { - self.0.cancel(); - } + self.0.stop().unwrap(); } }