-
Notifications
You must be signed in to change notification settings - Fork 107
feat(tts): expose Android TextToSpeech bridge to Lua #578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
CI note: this PR is from a fork, so the GitHub Actions
Could a maintainer please click “Approve and run” for the workflow run so the build checks can execute? Thanks! |
|
Are all of these methods API level 4? |
|
Could you move the kotlin implementation from MainActivity to its own class?. |
|
Yes, I've verified the API compatibility:
|
|
Done! I've refactored the TTS logic into a dedicated |
|
Pushed another follow-up in 92150ff to reduce Codacy complexity by simplifying TTSEngine control flow while keeping behavior the same. Waiting for Codacy result on latest commit. |
|
All requested follow-ups are now addressed:
Latest commit is a95a2fa and Codacy is now green. Ready for re-review. |
I note it got rid of the lock. Is that all okay and thread-safe? On average I wouldn't pay too much attention to automated "complexity" checks btw; it's often significantly more complex when refactored into dozens of tiny functions you have to chase down (but in this case it looks much clearer :-). |
Summary
This PR adds an Android TextToSpeech (TTS) bridge to the launcher, exposing the system TTS framework to Lua via a new
android.ttsnamespace. This enables KOReader-side plugins to implement “Read Aloud” using the user’s configured system TTS engine (Google/Samsung/…).API exposed to Lua
assets/android.luanow provides:android.tts.init()->boolean(requests initialization; initialization completes asynchronously)android.tts.speak(text, queueMode)->boolean(returnsfalseif the engine is not ready yet)android.tts.stop()->booleanandroid.tts.isSpeaking()->booleanandroid.tts.setSpeechRate(ratePercent)->boolean(e.g. 50..200)android.tts.setPitch(pitchPercent)->boolean(e.g. 50..200)android.tts.openSettings()->voidandroid.tts.installData()->voidandroid.tts.say(text, queueMode)convenience wrapperConstants:
android.tts.QUEUE_FLUSH = 0android.tts.QUEUE_ADD = 1Implementation Details
app/src/main/java/org/koreader/launcher/LuaInterface.kttts*methods to the Lua/JNI interface.app/src/main/java/org/koreader/launcher/MainActivity.kttts*methods.TextToSpeechinstance and a readiness flag (ttsInitialized).runOnUiThread(except forisSpeaking, which is best-effort).onDestroy()viattsShutdownInternal().assets/android.luaandroid.ttsnamespace and ensures JNI varargs type-safety by casting ints withffi.new("int32_t", ...).Testing
android.tts.init()and retryandroid.tts.say("hello")until it returnstrue.android.tts.stop()andandroid.tts.isSpeaking().android.tts.openSettings()andandroid.tts.installData().Limitations
This change is