mirror of
https://github.com/lightsoutgames/godot-tts
synced 2024-11-24 14:35:56 +00:00
Implement stop signals.
This commit is contained in:
parent
2c73b45300
commit
1dabd5afd3
7
TTS.gd
7
TTS.gd
|
@ -5,6 +5,8 @@ signal utterance_begin(utterance)
|
||||||
|
|
||||||
signal utterance_end(utterance)
|
signal utterance_end(utterance)
|
||||||
|
|
||||||
|
signal utterance_stop(utterance)
|
||||||
|
|
||||||
var TTS
|
var TTS
|
||||||
|
|
||||||
var tts
|
var tts
|
||||||
|
@ -23,6 +25,7 @@ func _init():
|
||||||
if self.are_utterance_callbacks_supported:
|
if self.are_utterance_callbacks_supported:
|
||||||
tts.connect("utterance_begin", self, "_on_utterance_begin")
|
tts.connect("utterance_begin", self, "_on_utterance_begin")
|
||||||
tts.connect("utterance_end", self, "_on_utterance_end")
|
tts.connect("utterance_end", self, "_on_utterance_end")
|
||||||
|
tts.connect("utterance_stop", self, "_on_utterance_stop")
|
||||||
else:
|
else:
|
||||||
print_debug("TTS not available!")
|
print_debug("TTS not available!")
|
||||||
|
|
||||||
|
@ -245,6 +248,10 @@ func _on_utterance_end(utterance):
|
||||||
emit_signal("utterance_end", utterance)
|
emit_signal("utterance_end", utterance)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_utterance_stop(utterance):
|
||||||
|
emit_signal("utterance_stop", utterance)
|
||||||
|
|
||||||
|
|
||||||
func _exit_tree():
|
func _exit_tree():
|
||||||
if not tts or not TTS:
|
if not tts or not TTS:
|
||||||
return
|
return
|
||||||
|
|
22
src/lib.rs
22
src/lib.rs
|
@ -17,6 +17,7 @@ impl Utterance {
|
||||||
enum Msg {
|
enum Msg {
|
||||||
UtteranceBegin(UtteranceId),
|
UtteranceBegin(UtteranceId),
|
||||||
UtteranceEnd(UtteranceId),
|
UtteranceEnd(UtteranceId),
|
||||||
|
UtteranceStop(UtteranceId),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(NativeClass)]
|
#[derive(NativeClass)]
|
||||||
|
@ -36,6 +37,7 @@ impl TTS {
|
||||||
} = tts.supported_features();
|
} = tts.supported_features();
|
||||||
if utterance_callbacks {
|
if utterance_callbacks {
|
||||||
let tx_end = tx.clone();
|
let tx_end = tx.clone();
|
||||||
|
let tx_stop = tx.clone();
|
||||||
tts.on_utterance_begin(Some(Box::new(move |utterance| {
|
tts.on_utterance_begin(Some(Box::new(move |utterance| {
|
||||||
tx.send(Msg::UtteranceBegin(utterance)).unwrap();
|
tx.send(Msg::UtteranceBegin(utterance)).unwrap();
|
||||||
})))
|
})))
|
||||||
|
@ -44,6 +46,10 @@ impl TTS {
|
||||||
tx_end.send(Msg::UtteranceEnd(utterance)).unwrap();
|
tx_end.send(Msg::UtteranceEnd(utterance)).unwrap();
|
||||||
})))
|
})))
|
||||||
.expect("Failed to set utterance_end callback");
|
.expect("Failed to set utterance_end callback");
|
||||||
|
tts.on_utterance_stop(Some(Box::new(move |utterance| {
|
||||||
|
tx_stop.send(Msg::UtteranceStop(utterance)).unwrap();
|
||||||
|
})))
|
||||||
|
.expect("Failed to set utterance_stop callback");
|
||||||
}
|
}
|
||||||
Self(tts, rx)
|
Self(tts, rx)
|
||||||
}
|
}
|
||||||
|
@ -171,6 +177,15 @@ impl TTS {
|
||||||
usage: PropertyUsage::DEFAULT,
|
usage: PropertyUsage::DEFAULT,
|
||||||
}],
|
}],
|
||||||
});
|
});
|
||||||
|
builder.add_signal(Signal {
|
||||||
|
name: "utterance_stop",
|
||||||
|
args: &[SignalArgument {
|
||||||
|
name: "utterance",
|
||||||
|
default: Variant::default(),
|
||||||
|
export_info: ExportInfo::new(VariantType::Object),
|
||||||
|
usage: PropertyUsage::DEFAULT,
|
||||||
|
}],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export]
|
#[export]
|
||||||
|
@ -231,6 +246,13 @@ impl TTS {
|
||||||
.expect("Failed to set utterance ID");
|
.expect("Failed to set utterance ID");
|
||||||
owner.emit_signal("utterance_end", &[utterance.owned_to_variant()]);
|
owner.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()]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user