mirror of
https://github.com/lightsoutgames/godot-tts
synced 2024-11-21 15:55:56 +00:00
Merge branch 'master' into pr/dylanjaide/7
This commit is contained in:
commit
c92135d452
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
|
@ -32,7 +32,7 @@ jobs:
|
||||||
- uses: Swatinem/rust-cache@v1
|
- uses: Swatinem/rust-cache@v1
|
||||||
- run: |
|
- run: |
|
||||||
choco install -qy llvm
|
choco install -qy llvm
|
||||||
cargo build --features tolk --features tts/tolk --release
|
cargo build --release
|
||||||
move target windows
|
move target windows
|
||||||
- uses: actions/upload-artifact@v1
|
- uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
|
|
|
@ -8,9 +8,6 @@ edition = "2018"
|
||||||
crate-type = ["staticlib", "cdylib"]
|
crate-type = ["staticlib", "cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
env_logger = "0.8"
|
env_logger = "0.10"
|
||||||
gdnative = "0.9"
|
gdnative = "0.11"
|
||||||
tts = "0.15"
|
tts = { version = "0.25", features = ["tolk"] }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
|
||||||
tolk = { version = "0.3", optional = true }
|
|
111
src/lib.rs
111
src/lib.rs
|
@ -1,10 +1,9 @@
|
||||||
use std::sync::mpsc::{channel, Receiver};
|
use std::sync::mpsc::{channel, Receiver};
|
||||||
|
|
||||||
use gdnative::prelude::*;
|
use gdnative::prelude::*;
|
||||||
use tts::{Features, UtteranceId, TTS as Tts};
|
use tts::{Features, Tts, UtteranceId};
|
||||||
|
|
||||||
#[derive(NativeClass)]
|
#[derive(NativeClass)]
|
||||||
#[inherit(Reference)]
|
|
||||||
struct Utterance(pub(crate) Option<UtteranceId>);
|
struct Utterance(pub(crate) Option<UtteranceId>);
|
||||||
|
|
||||||
#[methods]
|
#[methods]
|
||||||
|
@ -21,6 +20,7 @@ enum Msg {
|
||||||
UtteranceStop(UtteranceId),
|
UtteranceStop(UtteranceId),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::upper_case_acronyms)]
|
||||||
#[derive(NativeClass)]
|
#[derive(NativeClass)]
|
||||||
#[inherit(Node)]
|
#[inherit(Node)]
|
||||||
#[register_with(Self::register)]
|
#[register_with(Self::register)]
|
||||||
|
@ -62,7 +62,7 @@ impl TTS {
|
||||||
|
|
||||||
fn register(builder: &ClassBuilder<Self>) {
|
fn register(builder: &ClassBuilder<Self>) {
|
||||||
builder
|
builder
|
||||||
.add_property("volume")
|
.property("volume")
|
||||||
.with_getter(|this: &TTS, _| match this.0.get_volume() {
|
.with_getter(|this: &TTS, _| match this.0.get_volume() {
|
||||||
Ok(volume) => volume,
|
Ok(volume) => volume,
|
||||||
_ => 0.,
|
_ => 0.,
|
||||||
|
@ -84,7 +84,7 @@ impl TTS {
|
||||||
})
|
})
|
||||||
.done();
|
.done();
|
||||||
builder
|
builder
|
||||||
.add_property("min_volume")
|
.property("min_volume")
|
||||||
.with_getter(|this: &TTS, _| {
|
.with_getter(|this: &TTS, _| {
|
||||||
let Features {
|
let Features {
|
||||||
volume: volume_supported,
|
volume: volume_supported,
|
||||||
|
@ -98,7 +98,7 @@ impl TTS {
|
||||||
})
|
})
|
||||||
.done();
|
.done();
|
||||||
builder
|
builder
|
||||||
.add_property("max_volume")
|
.property("max_volume")
|
||||||
.with_getter(|this: &TTS, _| {
|
.with_getter(|this: &TTS, _| {
|
||||||
let Features {
|
let Features {
|
||||||
volume: volume_supported,
|
volume: volume_supported,
|
||||||
|
@ -112,7 +112,7 @@ impl TTS {
|
||||||
})
|
})
|
||||||
.done();
|
.done();
|
||||||
builder
|
builder
|
||||||
.add_property("normal_volume")
|
.property("normal_volume")
|
||||||
.with_getter(|this: &TTS, _| {
|
.with_getter(|this: &TTS, _| {
|
||||||
let Features {
|
let Features {
|
||||||
volume: volume_supported,
|
volume: volume_supported,
|
||||||
|
@ -126,7 +126,7 @@ impl TTS {
|
||||||
})
|
})
|
||||||
.done();
|
.done();
|
||||||
builder
|
builder
|
||||||
.add_property("rate")
|
.property("rate")
|
||||||
.with_getter(|this: &TTS, _| match this.0.get_rate() {
|
.with_getter(|this: &TTS, _| match this.0.get_rate() {
|
||||||
Ok(rate) => rate,
|
Ok(rate) => rate,
|
||||||
_ => 0.,
|
_ => 0.,
|
||||||
|
@ -148,7 +148,7 @@ impl TTS {
|
||||||
})
|
})
|
||||||
.done();
|
.done();
|
||||||
builder
|
builder
|
||||||
.add_property("min_rate")
|
.property("min_rate")
|
||||||
.with_getter(|this: &TTS, _| {
|
.with_getter(|this: &TTS, _| {
|
||||||
let Features {
|
let Features {
|
||||||
rate: rate_supported,
|
rate: rate_supported,
|
||||||
|
@ -162,7 +162,7 @@ impl TTS {
|
||||||
})
|
})
|
||||||
.done();
|
.done();
|
||||||
builder
|
builder
|
||||||
.add_property("max_rate")
|
.property("max_rate")
|
||||||
.with_getter(|this: &TTS, _| {
|
.with_getter(|this: &TTS, _| {
|
||||||
let Features {
|
let Features {
|
||||||
rate: rate_supported,
|
rate: rate_supported,
|
||||||
|
@ -176,7 +176,7 @@ impl TTS {
|
||||||
})
|
})
|
||||||
.done();
|
.done();
|
||||||
builder
|
builder
|
||||||
.add_property("normal_rate")
|
.property("normal_rate")
|
||||||
.with_getter(|this: &TTS, _| {
|
.with_getter(|this: &TTS, _| {
|
||||||
let Features {
|
let Features {
|
||||||
rate: rate_supported,
|
rate: rate_supported,
|
||||||
|
@ -190,23 +190,15 @@ impl TTS {
|
||||||
})
|
})
|
||||||
.done();
|
.done();
|
||||||
builder
|
builder
|
||||||
.add_property("can_detect_screen_reader")
|
.property("can_detect_screen_reader")
|
||||||
.with_getter(|_: &TTS, _| cfg!(all(windows, features = "tolk")))
|
.with_getter(|_: &TTS, _| cfg!(windows))
|
||||||
.done();
|
|
||||||
#[allow(unreachable_code)]
|
|
||||||
builder
|
|
||||||
.add_property("has_screen_reader")
|
|
||||||
.with_getter(|_: &TTS, _| {
|
|
||||||
#[cfg(all(windows, features = "tolk"))]
|
|
||||||
{
|
|
||||||
let tolk = tolk::Tolk::new();
|
|
||||||
return tolk.detect_screen_reader().is_some();
|
|
||||||
}
|
|
||||||
false
|
|
||||||
})
|
|
||||||
.done();
|
.done();
|
||||||
builder
|
builder
|
||||||
.add_property("can_detect_is_speaking")
|
.property("has_screen_reader")
|
||||||
|
.with_getter(|_, _| Tts::screen_reader_available())
|
||||||
|
.done();
|
||||||
|
builder
|
||||||
|
.property("can_detect_is_speaking")
|
||||||
.with_getter(|this: &TTS, _| {
|
.with_getter(|this: &TTS, _| {
|
||||||
let Features {
|
let Features {
|
||||||
is_speaking: is_speaking_supported,
|
is_speaking: is_speaking_supported,
|
||||||
|
@ -216,7 +208,7 @@ impl TTS {
|
||||||
})
|
})
|
||||||
.done();
|
.done();
|
||||||
builder
|
builder
|
||||||
.add_property("is_speaking")
|
.property("is_speaking")
|
||||||
.with_getter(|this: &TTS, _| {
|
.with_getter(|this: &TTS, _| {
|
||||||
let Features {
|
let Features {
|
||||||
is_speaking: is_speaking_supported,
|
is_speaking: is_speaking_supported,
|
||||||
|
@ -231,38 +223,37 @@ impl TTS {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.done();
|
.done();
|
||||||
builder.add_signal(Signal {
|
builder
|
||||||
name: "utterance_begin",
|
.signal("utterance_begin")
|
||||||
args: &[SignalArgument {
|
.with_param_custom(SignalParam {
|
||||||
name: "utterance",
|
name: "utterance".into(),
|
||||||
default: Variant::default(),
|
default: Variant::default(),
|
||||||
export_info: ExportInfo::new(VariantType::Object),
|
export_info: ExportInfo::new(VariantType::Object),
|
||||||
usage: PropertyUsage::DEFAULT,
|
usage: PropertyUsage::DEFAULT,
|
||||||
}],
|
})
|
||||||
});
|
.done();
|
||||||
builder.add_signal(Signal {
|
builder
|
||||||
name: "utterance_end",
|
.signal("utterance_end")
|
||||||
args: &[SignalArgument {
|
.with_param_custom(SignalParam {
|
||||||
name: "utterance",
|
name: "utterance".into(),
|
||||||
default: Variant::default(),
|
default: Variant::default(),
|
||||||
export_info: ExportInfo::new(VariantType::Object),
|
export_info: ExportInfo::new(VariantType::Object),
|
||||||
usage: PropertyUsage::DEFAULT,
|
usage: PropertyUsage::DEFAULT,
|
||||||
}],
|
})
|
||||||
});
|
.done();
|
||||||
builder.add_signal(Signal {
|
builder
|
||||||
name: "utterance_stop",
|
.signal("utterance_stop")
|
||||||
args: &[SignalArgument {
|
.with_param_custom(SignalParam {
|
||||||
name: "utterance",
|
name: "utterance".into(),
|
||||||
default: Variant::default(),
|
default: Variant::default(),
|
||||||
export_info: ExportInfo::new(VariantType::Object),
|
export_info: ExportInfo::new(VariantType::Object),
|
||||||
usage: PropertyUsage::DEFAULT,
|
usage: PropertyUsage::DEFAULT,
|
||||||
}],
|
})
|
||||||
});
|
.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export]
|
#[method]
|
||||||
fn speak(&mut self, _owner: &Node, message: GodotString, interrupt: bool) -> Variant {
|
fn speak(&mut self, message: String, interrupt: bool) -> Variant {
|
||||||
let message = message.to_string();
|
|
||||||
if let Ok(id) = self.0.speak(message, interrupt) {
|
if let Ok(id) = self.0.speak(message, interrupt) {
|
||||||
let utterance: Instance<Utterance, Unique> = Instance::new();
|
let utterance: Instance<Utterance, Unique> = Instance::new();
|
||||||
if id.is_some() {
|
if id.is_some() {
|
||||||
|
@ -276,13 +267,13 @@ impl TTS {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export]
|
#[method]
|
||||||
fn stop(&mut self, _owner: &Node) {
|
fn stop(&mut self) {
|
||||||
self.0.stop().expect("Failed to stop");
|
self.0.stop().expect("Failed to stop");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export]
|
#[method]
|
||||||
fn is_rate_supported(&mut self, _owner: &Node) -> bool {
|
fn is_rate_supported(&mut self) -> bool {
|
||||||
let Features {
|
let Features {
|
||||||
rate: rate_supported,
|
rate: rate_supported,
|
||||||
..
|
..
|
||||||
|
@ -290,8 +281,8 @@ impl TTS {
|
||||||
rate_supported
|
rate_supported
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export]
|
#[method]
|
||||||
fn are_utterance_callbacks_supported(&mut self, _owner: &Node) -> bool {
|
fn are_utterance_callbacks_supported(&mut self) -> bool {
|
||||||
let Features {
|
let Features {
|
||||||
utterance_callbacks: supported,
|
utterance_callbacks: supported,
|
||||||
..
|
..
|
||||||
|
@ -299,8 +290,8 @@ impl TTS {
|
||||||
supported
|
supported
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export]
|
#[method]
|
||||||
fn _process(&mut self, owner: &Node, _delta: f32) {
|
fn _process(&mut self, #[base] base: &Node, _delta: f32) {
|
||||||
if let Ok(msg) = self.1.try_recv() {
|
if let Ok(msg) = self.1.try_recv() {
|
||||||
match msg {
|
match msg {
|
||||||
Msg::UtteranceBegin(utterance_id) => {
|
Msg::UtteranceBegin(utterance_id) => {
|
||||||
|
@ -308,21 +299,21 @@ impl TTS {
|
||||||
utterance
|
utterance
|
||||||
.map_mut(|u, _| u.0 = Some(utterance_id))
|
.map_mut(|u, _| u.0 = Some(utterance_id))
|
||||||
.expect("Failed to set utterance ID");
|
.expect("Failed to set utterance ID");
|
||||||
owner.emit_signal("utterance_begin", &[utterance.owned_to_variant()]);
|
base.emit_signal("utterance_begin", &[utterance.owned_to_variant()]);
|
||||||
}
|
}
|
||||||
Msg::UtteranceEnd(utterance_id) => {
|
Msg::UtteranceEnd(utterance_id) => {
|
||||||
let utterance: Instance<Utterance, Unique> = Instance::new();
|
let utterance: Instance<Utterance, Unique> = Instance::new();
|
||||||
utterance
|
utterance
|
||||||
.map_mut(|u, _| u.0 = Some(utterance_id))
|
.map_mut(|u, _| u.0 = Some(utterance_id))
|
||||||
.expect("Failed to set utterance ID");
|
.expect("Failed to set utterance ID");
|
||||||
owner.emit_signal("utterance_end", &[utterance.owned_to_variant()]);
|
base.emit_signal("utterance_end", &[utterance.owned_to_variant()]);
|
||||||
}
|
}
|
||||||
Msg::UtteranceStop(utterance_id) => {
|
Msg::UtteranceStop(utterance_id) => {
|
||||||
let utterance: Instance<Utterance, Unique> = Instance::new();
|
let utterance: Instance<Utterance, Unique> = Instance::new();
|
||||||
utterance
|
utterance
|
||||||
.map_mut(|u, _| u.0 = Some(utterance_id))
|
.map_mut(|u, _| u.0 = Some(utterance_id))
|
||||||
.expect("Failed to set utterance ID");
|
.expect("Failed to set utterance ID");
|
||||||
owner.emit_signal("utterance_stop", &[utterance.owned_to_variant()]);
|
base.emit_signal("utterance_stop", &[utterance.owned_to_variant()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,6 +326,4 @@ fn init(handle: InitHandle) {
|
||||||
handle.add_class::<TTS>();
|
handle.add_class::<TTS>();
|
||||||
}
|
}
|
||||||
|
|
||||||
godot_gdnative_init!();
|
godot_init!(init);
|
||||||
godot_nativescript_init!(init);
|
|
||||||
godot_gdnative_terminate!();
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user