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):
|
func speak(text, interrupt := true):
|
||||||
|
var utterance
|
||||||
if tts != null:
|
if tts != null:
|
||||||
tts.speak(text, interrupt)
|
utterance = tts.speak(text, interrupt)
|
||||||
elif OS.has_feature('JavaScript'):
|
elif OS.has_feature('JavaScript'):
|
||||||
var code = (
|
var code = (
|
||||||
"""
|
"""
|
||||||
|
@ -139,6 +140,7 @@ func speak(text, interrupt := true):
|
||||||
JavaScript.eval(code)
|
JavaScript.eval(code)
|
||||||
else:
|
else:
|
||||||
print_debug("%s: %s" % [text, interrupt])
|
print_debug("%s: %s" % [text, interrupt])
|
||||||
|
return utterance
|
||||||
|
|
||||||
|
|
||||||
func stop():
|
func stop():
|
||||||
|
@ -236,8 +238,6 @@ func singular_or_plural(count, singular, plural):
|
||||||
|
|
||||||
|
|
||||||
func _on_utterance_begin(utterance):
|
func _on_utterance_begin(utterance):
|
||||||
print("Here")
|
|
||||||
print(utterance)
|
|
||||||
emit_signal("utterance_begin", utterance)
|
emit_signal("utterance_begin", utterance)
|
||||||
|
|
||||||
|
|
||||||
|
|
25
src/lib.rs
25
src/lib.rs
|
@ -174,9 +174,17 @@ impl TTS {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export]
|
#[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();
|
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]
|
#[export]
|
||||||
|
@ -208,16 +216,16 @@ impl TTS {
|
||||||
match msg {
|
match msg {
|
||||||
Msg::UtteranceBegin(utterance_id) => {
|
Msg::UtteranceBegin(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_begin", &[utterance.owned_to_variant()]);
|
owner.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()]);
|
owner.emit_signal("utterance_end", &[utterance.owned_to_variant()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,6 +235,7 @@ impl TTS {
|
||||||
|
|
||||||
fn init(handle: InitHandle) {
|
fn init(handle: InitHandle) {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
handle.add_class::<Utterance>();
|
||||||
handle.add_class::<TTS>();
|
handle.add_class::<TTS>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user