Merge branch 'master' into pr/dylanjaide/7

This commit is contained in:
Nolan Darilek 2023-04-26 09:48:23 -05:00
commit c92135d452
3 changed files with 54 additions and 68 deletions

View File

@ -32,7 +32,7 @@ jobs:
- uses: Swatinem/rust-cache@v1
- run: |
choco install -qy llvm
cargo build --features tolk --features tts/tolk --release
cargo build --release
move target windows
- uses: actions/upload-artifact@v1
with:

View File

@ -8,9 +8,6 @@ edition = "2018"
crate-type = ["staticlib", "cdylib"]
[dependencies]
env_logger = "0.8"
gdnative = "0.9"
tts = "0.15"
[target.'cfg(windows)'.dependencies]
tolk = { version = "0.3", optional = true }
env_logger = "0.10"
gdnative = "0.11"
tts = { version = "0.25", features = ["tolk"] }

View File

@ -1,10 +1,9 @@
use std::sync::mpsc::{channel, Receiver};
use gdnative::prelude::*;
use tts::{Features, UtteranceId, TTS as Tts};
use tts::{Features, Tts, UtteranceId};
#[derive(NativeClass)]
#[inherit(Reference)]
struct Utterance(pub(crate) Option<UtteranceId>);
#[methods]
@ -21,6 +20,7 @@ enum Msg {
UtteranceStop(UtteranceId),
}
#[allow(clippy::upper_case_acronyms)]
#[derive(NativeClass)]
#[inherit(Node)]
#[register_with(Self::register)]
@ -62,7 +62,7 @@ impl TTS {
fn register(builder: &ClassBuilder<Self>) {
builder
.add_property("volume")
.property("volume")
.with_getter(|this: &TTS, _| match this.0.get_volume() {
Ok(volume) => volume,
_ => 0.,
@ -84,7 +84,7 @@ impl TTS {
})
.done();
builder
.add_property("min_volume")
.property("min_volume")
.with_getter(|this: &TTS, _| {
let Features {
volume: volume_supported,
@ -98,7 +98,7 @@ impl TTS {
})
.done();
builder
.add_property("max_volume")
.property("max_volume")
.with_getter(|this: &TTS, _| {
let Features {
volume: volume_supported,
@ -112,7 +112,7 @@ impl TTS {
})
.done();
builder
.add_property("normal_volume")
.property("normal_volume")
.with_getter(|this: &TTS, _| {
let Features {
volume: volume_supported,
@ -126,7 +126,7 @@ impl TTS {
})
.done();
builder
.add_property("rate")
.property("rate")
.with_getter(|this: &TTS, _| match this.0.get_rate() {
Ok(rate) => rate,
_ => 0.,
@ -148,7 +148,7 @@ impl TTS {
})
.done();
builder
.add_property("min_rate")
.property("min_rate")
.with_getter(|this: &TTS, _| {
let Features {
rate: rate_supported,
@ -162,7 +162,7 @@ impl TTS {
})
.done();
builder
.add_property("max_rate")
.property("max_rate")
.with_getter(|this: &TTS, _| {
let Features {
rate: rate_supported,
@ -176,7 +176,7 @@ impl TTS {
})
.done();
builder
.add_property("normal_rate")
.property("normal_rate")
.with_getter(|this: &TTS, _| {
let Features {
rate: rate_supported,
@ -190,23 +190,15 @@ impl TTS {
})
.done();
builder
.add_property("can_detect_screen_reader")
.with_getter(|_: &TTS, _| cfg!(all(windows, features = "tolk")))
.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
})
.property("can_detect_screen_reader")
.with_getter(|_: &TTS, _| cfg!(windows))
.done();
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, _| {
let Features {
is_speaking: is_speaking_supported,
@ -216,7 +208,7 @@ impl TTS {
})
.done();
builder
.add_property("is_speaking")
.property("is_speaking")
.with_getter(|this: &TTS, _| {
let Features {
is_speaking: is_speaking_supported,
@ -231,38 +223,37 @@ impl TTS {
}
})
.done();
builder.add_signal(Signal {
name: "utterance_begin",
args: &[SignalArgument {
name: "utterance",
builder
.signal("utterance_begin")
.with_param_custom(SignalParam {
name: "utterance".into(),
default: Variant::default(),
export_info: ExportInfo::new(VariantType::Object),
usage: PropertyUsage::DEFAULT,
}],
});
builder.add_signal(Signal {
name: "utterance_end",
args: &[SignalArgument {
name: "utterance",
})
.done();
builder
.signal("utterance_end")
.with_param_custom(SignalParam {
name: "utterance".into(),
default: Variant::default(),
export_info: ExportInfo::new(VariantType::Object),
usage: PropertyUsage::DEFAULT,
}],
});
builder.add_signal(Signal {
name: "utterance_stop",
args: &[SignalArgument {
name: "utterance",
})
.done();
builder
.signal("utterance_stop")
.with_param_custom(SignalParam {
name: "utterance".into(),
default: Variant::default(),
export_info: ExportInfo::new(VariantType::Object),
usage: PropertyUsage::DEFAULT,
}],
});
})
.done();
}
#[export]
fn speak(&mut self, _owner: &Node, message: GodotString, interrupt: bool) -> Variant {
let message = message.to_string();
#[method]
fn speak(&mut self, message: String, interrupt: bool) -> Variant {
if let Ok(id) = self.0.speak(message, interrupt) {
let utterance: Instance<Utterance, Unique> = Instance::new();
if id.is_some() {
@ -276,13 +267,13 @@ impl TTS {
}
}
#[export]
fn stop(&mut self, _owner: &Node) {
#[method]
fn stop(&mut self) {
self.0.stop().expect("Failed to stop");
}
#[export]
fn is_rate_supported(&mut self, _owner: &Node) -> bool {
#[method]
fn is_rate_supported(&mut self) -> bool {
let Features {
rate: rate_supported,
..
@ -290,8 +281,8 @@ impl TTS {
rate_supported
}
#[export]
fn are_utterance_callbacks_supported(&mut self, _owner: &Node) -> bool {
#[method]
fn are_utterance_callbacks_supported(&mut self) -> bool {
let Features {
utterance_callbacks: supported,
..
@ -299,8 +290,8 @@ impl TTS {
supported
}
#[export]
fn _process(&mut self, owner: &Node, _delta: f32) {
#[method]
fn _process(&mut self, #[base] base: &Node, _delta: f32) {
if let Ok(msg) = self.1.try_recv() {
match msg {
Msg::UtteranceBegin(utterance_id) => {
@ -308,21 +299,21 @@ impl TTS {
utterance
.map_mut(|u, _| u.0 = Some(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) => {
let utterance: Instance<Utterance, Unique> = Instance::new();
utterance
.map_mut(|u, _| u.0 = Some(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) => {
let utterance: Instance<Utterance, Unique> = Instance::new();
utterance
.map_mut(|u, _| u.0 = Some(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>();
}
godot_gdnative_init!();
godot_nativescript_init!(init);
godot_gdnative_terminate!();
godot_init!(init);