mirror of
https://github.com/lightsoutgames/godot-tts
synced 2024-11-22 05:15:57 +00:00
Switch to tts crate.
This commit is contained in:
parent
a0dded472e
commit
05d8e3ac06
|
@ -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" }
|
||||
|
|
36
src/lib.rs
36
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user