mirror of
https://github.com/lightsoutgames/godot-tts
synced 2024-11-08 18:35:57 +00:00
Nolan Darilek
e233b97fff
And yet it still prints in exported builds not using the debug templates. *sigh*
50 lines
1016 B
GDScript
50 lines
1016 B
GDScript
tool
|
|
extends Node
|
|
|
|
const TTS = preload("godot-tts.gdns")
|
|
|
|
var tts = null
|
|
|
|
func _ready():
|
|
# Only initialize TTS if it's available or if we're in the editor.
|
|
if TTS.can_instance() or Engine.editor_hint:
|
|
print_debug("Attempting to load TTS.")
|
|
tts = TTS.new()
|
|
else:
|
|
print_debug("TTS not available!")
|
|
|
|
func set_rate(rate):
|
|
if tts != null:
|
|
tts.rate = rate
|
|
|
|
func get_rate():
|
|
if tts != null:
|
|
return tts.rate
|
|
else:
|
|
return 0
|
|
|
|
var rate setget set_rate, get_rate
|
|
|
|
func speak(text, interrupt := true):
|
|
print_debug("%s: %s" % [text, interrupt])
|
|
if tts != null:
|
|
tts.speak(text, interrupt)
|
|
|
|
func stop():
|
|
if tts != null:
|
|
tts.stop()
|
|
|
|
func get_is_rate_supported():
|
|
if tts != null:
|
|
return tts.is_rate_supported()
|
|
else:
|
|
return false
|
|
|
|
var is_rate_supported setget , get_is_rate_supported
|
|
|
|
func singular_or_plural(count, singular, plural):
|
|
if count == 1:
|
|
return singular
|
|
else:
|
|
return plural
|