godot-tts/src/lib.rs
2019-09-27 13:03:19 -05:00

68 lines
1.5 KiB
Rust

use gdnative::*;
use gdnative::init::*;
use tts::{TTS as Tts};
struct TTS(Tts);
impl NativeClass for TTS {
type Base = Node;
type UserData = user_data::MutexData<TTS>;
fn class_name() -> &'static str {
"TTS"
}
fn init(owner: Self::Base) -> Self {
Self::_init(owner)
}
fn register_properties(builder: &ClassBuilder<Self>) {
builder.add_property(Property {
name: "rate",
default: 128,
hint: PropertyHint::Range {
range: 0.0..255.0,
step: 1.,
slider: true,
},
getter: |this: &TTS| {
let rate = this.0.get_rate().unwrap();
rate
},
setter: |this: &mut TTS, v: u8| {
this.0.set_rate(v).unwrap();
},
usage: PropertyUsage::DEFAULT,
});
}
}
#[methods]
impl TTS {
fn _init(_owner: gdnative::Node) -> Self {
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);
self.0.speak(message, interrupt).unwrap();
}
#[export]
fn stop(&mut self, _owner: Node) {
self.0.stop().unwrap();
}
}
fn init(handle: gdnative::init::InitHandle) {
handle.add_class::<TTS>();
}
godot_gdnative_init!();
godot_nativescript_init!(init);
godot_gdnative_terminate!();