mirror of
https://github.com/lightsoutgames/godot-tts
synced 2024-11-22 14:25:56 +00:00
Reformat.
This commit is contained in:
parent
e88641f54d
commit
c7d827da93
32
TTS.gd
32
TTS.gd
|
@ -5,6 +5,7 @@ var TTS
|
||||||
|
|
||||||
var tts
|
var tts
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
if OS.get_name() == "Server" or OS.has_feature("JavaScript"):
|
if OS.get_name() == "Server" or OS.has_feature("JavaScript"):
|
||||||
return
|
return
|
||||||
|
@ -17,6 +18,7 @@ func _ready():
|
||||||
else:
|
else:
|
||||||
print_debug("TTS not available!")
|
print_debug("TTS not available!")
|
||||||
|
|
||||||
|
|
||||||
func _get_min_rate():
|
func _get_min_rate():
|
||||||
if OS.has_feature('JavaScript'):
|
if OS.has_feature('JavaScript'):
|
||||||
return 0.1
|
return 0.1
|
||||||
|
@ -27,8 +29,10 @@ func _get_min_rate():
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
var min_rate setget , _get_min_rate
|
var min_rate setget , _get_min_rate
|
||||||
|
|
||||||
|
|
||||||
func _get_max_rate():
|
func _get_max_rate():
|
||||||
if OS.has_feature('JavaScript'):
|
if OS.has_feature('JavaScript'):
|
||||||
return 10
|
return 10
|
||||||
|
@ -39,8 +43,10 @@ func _get_max_rate():
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
var max_rate setget , _get_max_rate
|
var max_rate setget , _get_max_rate
|
||||||
|
|
||||||
|
|
||||||
func _get_normal_rate():
|
func _get_normal_rate():
|
||||||
if OS.has_feature('JavaScript'):
|
if OS.has_feature('JavaScript'):
|
||||||
return 1
|
return 1
|
||||||
|
@ -51,10 +57,12 @@ func _get_normal_rate():
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
var normal_rate setget , _get_normal_rate
|
var normal_rate setget , _get_normal_rate
|
||||||
|
|
||||||
var javascript_rate = 50
|
var javascript_rate = 50
|
||||||
|
|
||||||
|
|
||||||
func _set_rate(rate):
|
func _set_rate(rate):
|
||||||
if rate < self.min_rate:
|
if rate < self.min_rate:
|
||||||
rate = self.min_rate
|
rate = self.min_rate
|
||||||
|
@ -67,6 +75,7 @@ func _set_rate(rate):
|
||||||
elif OS.has_feature('JavaScript'):
|
elif OS.has_feature('JavaScript'):
|
||||||
javascript_rate = rate
|
javascript_rate = rate
|
||||||
|
|
||||||
|
|
||||||
func _get_rate():
|
func _get_rate():
|
||||||
if Engine.has_singleton("AndroidTTS"):
|
if Engine.has_singleton("AndroidTTS"):
|
||||||
return tts.get_rate()
|
return tts.get_rate()
|
||||||
|
@ -77,29 +86,39 @@ func _get_rate():
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
var rate setget _set_rate, _get_rate
|
var rate setget _set_rate, _get_rate
|
||||||
|
|
||||||
|
|
||||||
func _get_rate_percentage():
|
func _get_rate_percentage():
|
||||||
return range_lerp(self.rate, self.min_rate, self.max_rate, 0, 100)
|
return range_lerp(self.rate, self.min_rate, self.max_rate, 0, 100)
|
||||||
|
|
||||||
|
|
||||||
func _set_rate_percentage(v):
|
func _set_rate_percentage(v):
|
||||||
self.rate = range_lerp(v, 0, 100, self.min_rate, self.max_rate)
|
self.rate = range_lerp(v, 0, 100, self.min_rate, self.max_rate)
|
||||||
|
|
||||||
|
|
||||||
var rate_percentage setget _set_rate_percentage, _get_rate_percentage
|
var rate_percentage setget _set_rate_percentage, _get_rate_percentage
|
||||||
|
|
||||||
|
|
||||||
func _get_normal_rate_percentage():
|
func _get_normal_rate_percentage():
|
||||||
return range_lerp(self.normal_rate, self.min_rate, self.max_rate, 0, 100)
|
return range_lerp(self.normal_rate, self.min_rate, self.max_rate, 0, 100)
|
||||||
|
|
||||||
|
|
||||||
var normal_rate_percentage setget , _get_rate_percentage
|
var normal_rate_percentage setget , _get_rate_percentage
|
||||||
|
|
||||||
|
|
||||||
func speak(text, interrupt := true):
|
func speak(text, interrupt := true):
|
||||||
if tts != null:
|
if tts != null:
|
||||||
tts.speak(text, interrupt)
|
tts.speak(text, interrupt)
|
||||||
elif OS.has_feature('JavaScript'):
|
elif OS.has_feature('JavaScript'):
|
||||||
var code = """
|
var code = (
|
||||||
|
"""
|
||||||
let utterance = new SpeechSynthesisUtterance("%s")
|
let utterance = new SpeechSynthesisUtterance("%s")
|
||||||
utterance.rate = %s
|
utterance.rate = %s
|
||||||
""" % [text.replace("\n", " "), javascript_rate]
|
"""
|
||||||
|
% [text.replace("\n", " "), javascript_rate]
|
||||||
|
)
|
||||||
if interrupt:
|
if interrupt:
|
||||||
code += """
|
code += """
|
||||||
window.speechSynthesis.cancel()
|
window.speechSynthesis.cancel()
|
||||||
|
@ -109,12 +128,14 @@ func speak(text, interrupt := true):
|
||||||
else:
|
else:
|
||||||
print_debug("%s: %s" % [text, interrupt])
|
print_debug("%s: %s" % [text, interrupt])
|
||||||
|
|
||||||
|
|
||||||
func stop():
|
func stop():
|
||||||
if tts != null:
|
if tts != null:
|
||||||
tts.stop()
|
tts.stop()
|
||||||
elif OS.has_feature('JavaScript'):
|
elif OS.has_feature('JavaScript'):
|
||||||
JavaScript.eval("window.speechSynthesis.cancel()")
|
JavaScript.eval("window.speechSynthesis.cancel()")
|
||||||
|
|
||||||
|
|
||||||
func get_is_rate_supported():
|
func get_is_rate_supported():
|
||||||
if Engine.has_singleton("AndroidTTS"):
|
if Engine.has_singleton("AndroidTTS"):
|
||||||
return true
|
return true
|
||||||
|
@ -125,8 +146,10 @@ func get_is_rate_supported():
|
||||||
else:
|
else:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
|
||||||
var is_rate_supported setget , get_is_rate_supported
|
var is_rate_supported setget , get_is_rate_supported
|
||||||
|
|
||||||
|
|
||||||
func _get_can_detect_screen_reader():
|
func _get_can_detect_screen_reader():
|
||||||
if Engine.has_singleton("AndroidTTS"):
|
if Engine.has_singleton("AndroidTTS"):
|
||||||
return true
|
return true
|
||||||
|
@ -136,8 +159,10 @@ func _get_can_detect_screen_reader():
|
||||||
return tts.can_detect_screen_reader
|
return tts.can_detect_screen_reader
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
|
||||||
var can_detect_screen_reader setget , _get_can_detect_screen_reader
|
var can_detect_screen_reader setget , _get_can_detect_screen_reader
|
||||||
|
|
||||||
|
|
||||||
func _get_has_screen_reader():
|
func _get_has_screen_reader():
|
||||||
if Engine.has_singleton("AndroidTTS"):
|
if Engine.has_singleton("AndroidTTS"):
|
||||||
return tts.has_screen_reader()
|
return tts.has_screen_reader()
|
||||||
|
@ -147,14 +172,17 @@ func _get_has_screen_reader():
|
||||||
return tts.has_screen_reader
|
return tts.has_screen_reader
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
|
||||||
var has_screen_reader setget , _get_has_screen_reader
|
var has_screen_reader setget , _get_has_screen_reader
|
||||||
|
|
||||||
|
|
||||||
func singular_or_plural(count, singular, plural):
|
func singular_or_plural(count, singular, plural):
|
||||||
if count == 1:
|
if count == 1:
|
||||||
return singular
|
return singular
|
||||||
else:
|
else:
|
||||||
return plural
|
return plural
|
||||||
|
|
||||||
|
|
||||||
func _exit_tree():
|
func _exit_tree():
|
||||||
if not tts or not TTS:
|
if not tts or not TTS:
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user