mirror of
https://github.com/lightsoutgames/godot-tts
synced 2024-11-22 10:15:56 +00:00
Pass utterance IDs into signals, and return an utterance ID when speaking.
This commit is contained in:
parent
68d1d9e011
commit
c7563fa997
6
TTS.gd
6
TTS.gd
|
@ -121,8 +121,9 @@ var normal_rate_percentage setget , _get_rate_percentage
|
|||
|
||||
|
||||
func speak(text, interrupt := true):
|
||||
var utterance
|
||||
if tts != null:
|
||||
tts.speak(text, interrupt)
|
||||
utterance = tts.speak(text, interrupt)
|
||||
elif OS.has_feature('JavaScript'):
|
||||
var code = (
|
||||
"""
|
||||
|
@ -139,6 +140,7 @@ func speak(text, interrupt := true):
|
|||
JavaScript.eval(code)
|
||||
else:
|
||||
print_debug("%s: %s" % [text, interrupt])
|
||||
return utterance
|
||||
|
||||
|
||||
func stop():
|
||||
|
@ -236,8 +238,6 @@ func singular_or_plural(count, singular, plural):
|
|||
|
||||
|
||||
func _on_utterance_begin(utterance):
|
||||
print("Here")
|
||||
print(utterance)
|
||||
emit_signal("utterance_begin", utterance)
|
||||
|
||||
|
||||
|
|
25
src/lib.rs
25
src/lib.rs
|
@ -174,9 +174,17 @@ impl TTS {
|
|||
}
|
||||
|
||||
#[export]
|
||||
fn speak(&mut self, _owner: &Node, message: GodotString, interrupt: bool) {
|
||||
fn speak(&mut self, _owner: &Node, message: GodotString, interrupt: bool) -> Option<Variant> {
|
||||
let message = message.to_string();
|
||||
self.0.speak(message, interrupt).unwrap();
|
||||
if let Ok(id) = self.0.speak(message, interrupt) {
|
||||
let utterance: Instance<Utterance, Unique> = Instance::new();
|
||||
utterance
|
||||
.map_mut(|u, _| u.0 = id)
|
||||
.expect("Failed to set utterance ID");
|
||||
Some(utterance.owned_to_variant())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[export]
|
||||
|
@ -208,16 +216,16 @@ impl TTS {
|
|||
match msg {
|
||||
Msg::UtteranceBegin(utterance_id) => {
|
||||
let utterance: Instance<Utterance, Unique> = Instance::new();
|
||||
/*utterance
|
||||
.map_mut(|u, _| u.0 = Some(utterance_id))
|
||||
.expect("Failed to set utterance ID");*/
|
||||
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_id) => {
|
||||
let utterance: Instance<Utterance, Unique> = Instance::new();
|
||||
/*utterance
|
||||
.map_mut(|u, _| u.0 = Some(utterance_id))
|
||||
.expect("Failed to set utterance ID");*/
|
||||
utterance
|
||||
.map_mut(|u, _| u.0 = Some(utterance_id))
|
||||
.expect("Failed to set utterance ID");
|
||||
owner.emit_signal("utterance_end", &[utterance.owned_to_variant()]);
|
||||
}
|
||||
}
|
||||
|
@ -227,6 +235,7 @@ impl TTS {
|
|||
|
||||
fn init(handle: InitHandle) {
|
||||
env_logger::init();
|
||||
handle.add_class::<Utterance>();
|
||||
handle.add_class::<TTS>();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user