translation improvements
This commit is contained in:
@@ -1,28 +1,48 @@
|
||||
extends Node
|
||||
|
||||
var voice_id
|
||||
var _tts_locale := ""
|
||||
|
||||
|
||||
func _ready():
|
||||
var voices = DisplayServer.tts_get_voices_for_language("de")
|
||||
if voices.size() > 0:
|
||||
voice_id = "German+Robosoft6"
|
||||
else:
|
||||
voices = DisplayServer.tts_get_voices_for_language("en")
|
||||
voice_id = voices[0]
|
||||
|
||||
# Connect with DialogueManager
|
||||
_update_voice_for_locale()
|
||||
DialogueManager.got_dialogue.connect(_on_dialogue)
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_TRANSLATION_CHANGED:
|
||||
_update_voice_for_locale()
|
||||
|
||||
|
||||
func _update_voice_for_locale() -> void:
|
||||
var locale := TranslationServer.get_locale()
|
||||
var lang := locale.substr(0, 2)
|
||||
if lang == _tts_locale and voice_id != null:
|
||||
return
|
||||
_tts_locale = lang
|
||||
|
||||
var voices = DisplayServer.tts_get_voices_for_language(lang)
|
||||
if voices.size() > 0:
|
||||
# Prefer a known German robotic voice when available; otherwise first matching voice
|
||||
if lang == "de" and "German+Robosoft6" in voices:
|
||||
voice_id = "German+Robosoft6"
|
||||
else:
|
||||
voice_id = voices[0]
|
||||
else:
|
||||
# Fallback to English if current language has no TTS voices
|
||||
voices = DisplayServer.tts_get_voices_for_language("en")
|
||||
if voices.size() > 0:
|
||||
voice_id = voices[0]
|
||||
else:
|
||||
voice_id = null
|
||||
|
||||
|
||||
func _on_dialogue(line):
|
||||
if voice_id == null:
|
||||
return
|
||||
|
||||
# Stop earlier text (important!)
|
||||
DisplayServer.tts_stop()
|
||||
|
||||
# Speak
|
||||
DisplayServer.tts_speak(line.text, voice_id, 100)
|
||||
|
||||
|
||||
|
||||
func _stop_dialogue():
|
||||
DisplayServer.tts_stop()
|
||||
|
||||
Reference in New Issue
Block a user