2019-09-03 13:54:36 +00:00
|
|
|
use gdnative::*;
|
2018-06-13 12:14:03 +00:00
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
use speech_dispatcher::{Connection, Mode, Priority};
|
|
|
|
#[cfg(windows)]
|
|
|
|
use tolk::Tolk;
|
|
|
|
|
2019-09-03 13:54:36 +00:00
|
|
|
#[derive(gdnative::NativeClass)]
|
|
|
|
#[inherit(gdnative::Node)]
|
|
|
|
struct TTS(
|
|
|
|
#[cfg(unix)]
|
|
|
|
Connection,
|
|
|
|
#[cfg(windows)]
|
|
|
|
Tolk,
|
|
|
|
);
|
|
|
|
|
|
|
|
#[methods]
|
|
|
|
impl TTS {
|
|
|
|
fn _init(_owner: gdnative::Node) -> Self {
|
|
|
|
#[cfg(unix)]
|
|
|
|
{
|
|
|
|
let connection = Connection::open("godot", "godot", "godot", Mode::Single);
|
|
|
|
Self(connection)
|
2018-06-13 12:14:03 +00:00
|
|
|
}
|
2019-09-03 13:54:36 +00:00
|
|
|
#[cfg(windows)]
|
|
|
|
Self(Tolk::new())
|
|
|
|
}
|
2018-06-13 12:14:03 +00:00
|
|
|
|
2019-09-03 13:54:36 +00:00
|
|
|
#[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);
|
2018-06-13 12:14:03 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-03 13:54:36 +00:00
|
|
|
}
|
2018-06-13 12:14:03 +00:00
|
|
|
|
2019-09-03 13:54:36 +00:00
|
|
|
#[export]
|
|
|
|
fn stop(&mut self, _owner: Node) {
|
|
|
|
#[cfg(unix)]
|
|
|
|
{
|
|
|
|
self.0.cancel();
|
2018-06-13 12:14:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-03 13:54:36 +00:00
|
|
|
fn init(handle: gdnative::init::InitHandle) {
|
|
|
|
handle.add_class::<TTS>();
|
2018-06-13 12:14:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
godot_gdnative_init!();
|
|
|
|
godot_nativescript_init!(init);
|
|
|
|
godot_gdnative_terminate!();
|