Switch to tts crate.

This commit is contained in:
Nolan Darilek 2019-09-10 10:09:04 -05:00
parent a0dded472e
commit 05d8e3ac06
2 changed files with 7 additions and 36 deletions

View File

@ -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" }

View File

@ -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();
}
}