Android TextToSpeech Support#29
Conversation
|
Noted! I'll take a look at other options we might have here |
…etEngineParameter
|
@m1maker - sorry for the delay here, but I finally got around to updating this with a solution that I feel pretty happy about! I've updated the PR Summary, but the TLDR is I've removed the SDL3 dependency, and we follow a pattern more similar to other libraries (like Firebase) which take in a JNI Env and Activity before initialization. There's a requirement to set these before we initialize in the host application, but if that feels off let me know and I can look for potential alternatives. I've retested this on my android device, and everything works as expected 👍 |
|
Is it possible to build the android build using GitHub Actions? |
|
@enumag - for my own project, I ended up including a large set of the sral files in the android project, and then had the android build system compile them. I think this is almost certainly the way other projects would need to take advantage of this library, but is there a specific file / output you were expecting from the GitHub Actions to include? |
|
I dont know how exactly this works for android. I assumed there would be some equivalent file to .dll for windows, .dylib for macos or .so for Linux which I could then use using FFI. If that's now how it works on Android then it's irrelevant. |
Previously, we had a header for AndroidTextToSpeech support, but no corresponding .cpp implementation file. This prevented Android from being a valid working target for SRAL.
This PR builds out several pieces to support Android TextToSpeech.
Namely:
CMakeLists.txtandSRC/SRAL.cppto include Android Target, and support setting engine parameters before initializationDep/AndroidTTSHelper.javawhich is used to give the C++ files access to Android's underlying TextToSpeech engineInclude/SRAL.hto include newSRAL_ENGINE_ANDROID_TEXT_TO_SPEECHengine and support two new engine parameters:SRAL_PARAM_ANDROID_JNI_ENVandSRAL_PARAM_ANDROID_ACTIVITYSRC/AndroidTextToSpeech.cppwhich implements the existingSRC/AndroidTextToSpeech.hSRC/AndroidTextToSpeech.hto include the proper return forSpeakToMemoryDep/AndroidContext.handDep/AndroidContext.cppwhich stores the Android JNIEnv/Activity and provide thread-safe access for Android enginesImportant
On Android, native code cannot obtain a
JNIEnv*orActivityon its own. Before callingSRAL_Initialize, the host application callsSRAL_SetEngineParametertwice to provide these values:This pattern is similar to other native Android libraries (e.g. Firebase C++ SDK's
App::Create(options, env, activity))Additionally, I updated the README to include details about the Android TextToSpeech support and the recently added VoiceOver and AVFoundation support on iOS.
Testing: Built the love-android project with
./gradlew assembleEmbedNoRecordDebugand installed on a real android device withadb install -r <apk path>. I verified TTS output works by interacting with the app.Note
The
Dep/AndroidTTSHelper.javaneeds to be compiled into the app's Java sources for Android projects to be able to compile and use SRAL.Like the previous iOS PR, I didn't include example source code here, since there are a lot of complexities with setting up even a simple Android project. If that would be appreciated, I'm happy to work on building something like that.
This does not include support for Android TalkBack. I'm planning to investigate that in a follow up PR.