Godot 4.3
Windows 11
On Android with TTS, everything works fine and there are no crashes.
On Android without TTS, calling DisplayServer.tts_get_voices() and DisplayServer.tts_get_voices_for_language("en") causes the application to crash.
I had to write an Android plugin in Android Studio to solve this problem and prevent the app from crashing.
package org.godotengine.plugin.android.checktts
import android.content.Intent
import android.speech.tts.TextToSpeech
import android.util.Log
import org.godotengine.godot.Godot
import org.godotengine.godot.plugin.GodotPlugin
import org.godotengine.godot.plugin.UsedByGodot
class GodotAndroidPlugin(godot: Godot): GodotPlugin(godot) {
override fun getPluginName() = BuildConfig.GODOT_PLUGIN_NAME
@UsedByGodot
fun canUseTTS(): Boolean {
return try {
val checkIntent = Intent(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA)
val resolveInfo = activity?.packageManager?.queryIntentActivities(checkIntent, 0)
val result = (resolveInfo?.size ?: 0) > 0
Log.v(pluginName, "TTS available: $result")
result
} catch (e: Exception) {
Log.e(pluginName, "TTS check error: ${e.message}")
false
}
}
}
I haven't found any other way to solve this problem. If there is a solution, please let me know.
Otherwise, this appears to be a bug in Godot.