From a5b6c201252e044929e62e76920a936ca4a1b70f Mon Sep 17 00:00:00 2001 From: Ellen Poe Date: Sat, 12 Oct 2019 15:03:26 -0700 Subject: [PATCH] Only initialize TTS outside the editor if system libraries are available --- TTS.gd | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/TTS.gd b/TTS.gd index abcaeb1..177c583 100644 --- a/TTS.gd +++ b/TTS.gd @@ -3,24 +3,41 @@ extends Node 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): - tts.rate = rate + if tts != null: + tts.rate = rate func get_rate(): - return tts.rate + if tts != null: + return tts.rate + else: + return 0 var rate setget set_rate, get_rate func speak(text, interrupt := true): - tts.speak(text, interrupt) + if tts != null: + tts.speak(text, interrupt) func stop(): - tts.stop() + if tts != null: + tts.stop() func get_is_rate_supported(): - return tts.is_rate_supported() + if tts != null: + return tts.is_rate_supported() + else: + return false var is_rate_supported setget , get_is_rate_supported