mirror of
https://github.com/lightsoutgames/godot-tts
synced 2024-11-22 19:15:56 +00:00
Merge branch 'missing_library_fix' into 'master'
Only initialize TTS outside the editor if system libraries are available Closes #3 See merge request lightsoutgames/godot-tts!1
This commit is contained in:
commit
8fc2321050
19
TTS.gd
19
TTS.gd
|
@ -3,24 +3,41 @@ extends Node
|
||||||
|
|
||||||
const TTS = preload("godot-tts.gdns")
|
const TTS = preload("godot-tts.gdns")
|
||||||
|
|
||||||
var tts = TTS.new()
|
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("Attempting to load TTS.")
|
||||||
|
tts = TTS.new()
|
||||||
|
else:
|
||||||
|
print("TTS not available!")
|
||||||
|
|
||||||
func set_rate(rate):
|
func set_rate(rate):
|
||||||
|
if tts != null:
|
||||||
tts.rate = rate
|
tts.rate = rate
|
||||||
|
|
||||||
func get_rate():
|
func get_rate():
|
||||||
|
if tts != null:
|
||||||
return tts.rate
|
return tts.rate
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
var rate setget set_rate, get_rate
|
var rate setget set_rate, get_rate
|
||||||
|
|
||||||
func speak(text, interrupt := true):
|
func speak(text, interrupt := true):
|
||||||
|
if tts != null:
|
||||||
tts.speak(text, interrupt)
|
tts.speak(text, interrupt)
|
||||||
|
|
||||||
func stop():
|
func stop():
|
||||||
|
if tts != null:
|
||||||
tts.stop()
|
tts.stop()
|
||||||
|
|
||||||
func get_is_rate_supported():
|
func get_is_rate_supported():
|
||||||
|
if tts != null:
|
||||||
return tts.is_rate_supported()
|
return tts.is_rate_supported()
|
||||||
|
else:
|
||||||
|
return false
|
||||||
|
|
||||||
var is_rate_supported setget , get_is_rate_supported
|
var is_rate_supported setget , get_is_rate_supported
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user