mirror of
https://github.com/lightsoutgames/godot-tts
synced 2024-11-22 17:05:56 +00:00
Switch to tts crate.
This commit is contained in:
parent
a0dded472e
commit
05d8e3ac06
|
@ -9,9 +9,4 @@ crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
gdnative = { git = "https://github.com/ndarilek/godot-rust/" }
|
gdnative = { git = "https://github.com/ndarilek/godot-rust/" }
|
||||||
|
tts = { path = "../../TTS-RS" }
|
||||||
[target.'cfg(unix)'.dependencies]
|
|
||||||
speech-dispatcher = "0.3"
|
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
|
||||||
tolk = "0.1"
|
|
||||||
|
|
36
src/lib.rs
36
src/lib.rs
|
@ -1,52 +1,28 @@
|
||||||
use gdnative::*;
|
use gdnative::*;
|
||||||
|
|
||||||
#[cfg(unix)]
|
use tts::{TTS as Tts};
|
||||||
use speech_dispatcher::{Connection, Mode, Priority};
|
|
||||||
#[cfg(windows)]
|
|
||||||
use tolk::Tolk;
|
|
||||||
|
|
||||||
#[derive(gdnative::NativeClass)]
|
#[derive(gdnative::NativeClass)]
|
||||||
#[inherit(gdnative::Node)]
|
#[inherit(gdnative::Node)]
|
||||||
struct TTS(
|
struct TTS(Tts);
|
||||||
#[cfg(unix)]
|
|
||||||
Connection,
|
|
||||||
#[cfg(windows)]
|
|
||||||
Tolk,
|
|
||||||
);
|
|
||||||
|
|
||||||
#[methods]
|
#[methods]
|
||||||
impl TTS {
|
impl TTS {
|
||||||
fn _init(_owner: gdnative::Node) -> Self {
|
fn _init(_owner: gdnative::Node) -> Self {
|
||||||
#[cfg(unix)]
|
let tts = Tts::default().unwrap();
|
||||||
{
|
Self(tts)
|
||||||
let connection = Connection::open("godot", "godot", "godot", Mode::Single);
|
|
||||||
Self(connection)
|
|
||||||
}
|
|
||||||
#[cfg(windows)]
|
|
||||||
Self(Tolk::new())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export]
|
#[export]
|
||||||
fn speak(&mut self, _owner: Node, message: GodotString, interrupt: bool) {
|
fn speak(&mut self, _owner: Node, message: GodotString, interrupt: bool) {
|
||||||
let message = message.to_string();
|
let message = message.to_string();
|
||||||
println!("{}: {}", message, interrupt);
|
println!("{}: {}", message, interrupt);
|
||||||
#[cfg(unix)]
|
self.0.speak(message, interrupt).unwrap();
|
||||||
{
|
|
||||||
if interrupt {
|
|
||||||
self.0.cancel();
|
|
||||||
}
|
|
||||||
if message != "" {
|
|
||||||
self.0.say(Priority::Important, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export]
|
#[export]
|
||||||
fn stop(&mut self, _owner: Node) {
|
fn stop(&mut self, _owner: Node) {
|
||||||
#[cfg(unix)]
|
self.0.stop().unwrap();
|
||||||
{
|
|
||||||
self.0.cancel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user