mirror of
https://github.com/lightsoutgames/godot-tts
synced 2024-11-22 15:25:56 +00:00
Bridge TTS callbacks to signals.
This commit is contained in:
parent
0c9efa5c7b
commit
a71bf417b6
21
TTS.gd
21
TTS.gd
|
@ -1,12 +1,14 @@
|
||||||
tool
|
tool
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
signal utterance_begin
|
||||||
|
|
||||||
|
signal utterance_end
|
||||||
|
|
||||||
var TTS
|
var TTS
|
||||||
|
|
||||||
var tts
|
var tts
|
||||||
|
|
||||||
signal done
|
|
||||||
|
|
||||||
|
|
||||||
func _init():
|
func _init():
|
||||||
if OS.get_name() == "Server" or OS.has_feature("JavaScript"):
|
if OS.get_name() == "Server" or OS.has_feature("JavaScript"):
|
||||||
|
@ -17,6 +19,10 @@ func _init():
|
||||||
TTS = preload("godot-tts.gdns")
|
TTS = preload("godot-tts.gdns")
|
||||||
if TTS and (TTS.can_instance() or Engine.editor_hint):
|
if TTS and (TTS.can_instance() or Engine.editor_hint):
|
||||||
tts = TTS.new()
|
tts = TTS.new()
|
||||||
|
self.add_child(tts)
|
||||||
|
if self.are_utterance_callbacks_supported:
|
||||||
|
tts.connect("utterance_begin", self, "_on_utterance_begin")
|
||||||
|
tts.connect("utterance_end", self, "_on_utterance_end")
|
||||||
else:
|
else:
|
||||||
print_debug("TTS not available!")
|
print_debug("TTS not available!")
|
||||||
|
|
||||||
|
@ -229,15 +235,12 @@ func singular_or_plural(count, singular, plural):
|
||||||
return plural
|
return plural
|
||||||
|
|
||||||
|
|
||||||
var _was_speaking = false
|
func _on_utterance_begin():
|
||||||
|
emit_signal("utterance_begin")
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
func _on_utterance_end():
|
||||||
if self.is_speaking:
|
emit_signal("utterance_end")
|
||||||
_was_speaking = true
|
|
||||||
elif _was_speaking:
|
|
||||||
emit_signal("done")
|
|
||||||
_was_speaking = false
|
|
||||||
|
|
||||||
|
|
||||||
func _exit_tree():
|
func _exit_tree():
|
||||||
|
|
|
@ -15,9 +15,15 @@ struct TTS(Tts, Receiver<Msg>);
|
||||||
|
|
||||||
#[methods]
|
#[methods]
|
||||||
impl TTS {
|
impl TTS {
|
||||||
fn new(_owner: &Node) -> Self {
|
fn new(owner: &Node) -> Self {
|
||||||
|
owner.set_pause_mode(2);
|
||||||
let tts = Tts::default().unwrap();
|
let tts = Tts::default().unwrap();
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
|
let Features {
|
||||||
|
utterance_callbacks,
|
||||||
|
..
|
||||||
|
} = tts.supported_features();
|
||||||
|
if utterance_callbacks {
|
||||||
let tx_end = tx.clone();
|
let tx_end = 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();
|
||||||
|
@ -27,6 +33,7 @@ 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");
|
||||||
|
}
|
||||||
Self(tts, rx)
|
Self(tts, rx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user