WIP: Try passing in utterance to signals.

This commit is contained in:
Nolan Darilek 2020-09-30 11:57:50 -05:00
parent a71bf417b6
commit 68d1d9e011
2 changed files with 43 additions and 12 deletions

14
TTS.gd
View File

@ -1,9 +1,9 @@
tool tool
extends Node extends Node
signal utterance_begin signal utterance_begin(utterance)
signal utterance_end signal utterance_end(utterance)
var TTS var TTS
@ -235,12 +235,14 @@ func singular_or_plural(count, singular, plural):
return plural return plural
func _on_utterance_begin(): func _on_utterance_begin(utterance):
emit_signal("utterance_begin") print("Here")
print(utterance)
emit_signal("utterance_begin", utterance)
func _on_utterance_end(): func _on_utterance_end(utterance):
emit_signal("utterance_end") emit_signal("utterance_end", utterance)
func _exit_tree(): func _exit_tree():

View File

@ -3,6 +3,17 @@ use std::sync::mpsc::{channel, Receiver};
use gdnative::prelude::*; use gdnative::prelude::*;
use tts::{Features, UtteranceId, TTS as Tts}; use tts::{Features, UtteranceId, TTS as Tts};
#[derive(NativeClass)]
#[inherit(Reference)]
struct Utterance(pub(crate) Option<UtteranceId>);
#[methods]
impl Utterance {
fn new(_owner: &Reference) -> Self {
Self(None)
}
}
enum Msg { enum Msg {
UtteranceBegin(UtteranceId), UtteranceBegin(UtteranceId),
UtteranceEnd(UtteranceId), UtteranceEnd(UtteranceId),
@ -144,11 +155,21 @@ impl TTS {
.done(); .done();
builder.add_signal(Signal { builder.add_signal(Signal {
name: "utterance_begin", name: "utterance_begin",
args: &[], args: &[SignalArgument {
name: "utterance",
default: Variant::default(),
export_info: ExportInfo::new(VariantType::Object),
usage: PropertyUsage::DEFAULT,
}],
}); });
builder.add_signal(Signal { builder.add_signal(Signal {
name: "utterance_end", name: "utterance_end",
args: &[], args: &[SignalArgument {
name: "utterance",
default: Variant::default(),
export_info: ExportInfo::new(VariantType::Object),
usage: PropertyUsage::DEFAULT,
}],
}); });
} }
@ -185,11 +206,19 @@ impl TTS {
fn _process(&mut self, owner: &Node, _delta: f32) { fn _process(&mut self, owner: &Node, _delta: f32) {
if let Some(msg) = self.1.try_recv().ok() { if let Some(msg) = self.1.try_recv().ok() {
match msg { match msg {
Msg::UtteranceBegin(_utterance) => { Msg::UtteranceBegin(utterance_id) => {
owner.emit_signal("utterance_begin", &[]); 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_begin", &[utterance.owned_to_variant()]);
} }
Msg::UtteranceEnd(_utterance) => { Msg::UtteranceEnd(utterance_id) => {
owner.emit_signal("utterance_end", &[]); 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()]);
} }
} }
} }