Skip to content

Android TextToSpeech Support#29

Merged
m1maker merged 2 commits into
m1maker:mainfrom
JRJurman:android_tts_support
Apr 13, 2026
Merged

Android TextToSpeech Support#29
m1maker merged 2 commits into
m1maker:mainfrom
JRJurman:android_tts_support

Conversation

@JRJurman

@JRJurman JRJurman commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

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:

  • update CMakeLists.txt and SRC/SRAL.cpp to include Android Target, and support setting engine parameters before initialization
  • new Dep/AndroidTTSHelper.java which is used to give the C++ files access to Android's underlying TextToSpeech engine
  • update Include/SRAL.h to include new SRAL_ENGINE_ANDROID_TEXT_TO_SPEECH engine and support two new engine parameters: SRAL_PARAM_ANDROID_JNI_ENV and SRAL_PARAM_ANDROID_ACTIVITY
  • new SRC/AndroidTextToSpeech.cpp which implements the existing SRC/AndroidTextToSpeech.h
  • update SRC/AndroidTextToSpeech.h to include the proper return for SpeakToMemory
  • new Dep/AndroidContext.h and Dep/AndroidContext.cpp which stores the Android JNIEnv/Activity and provide thread-safe access for Android engines

Important

On Android, native code cannot obtain a JNIEnv* or Activity on its own. Before calling SRAL_Initialize, the host application calls SRAL_SetEngineParameter twice to provide these values:

SRAL_SetEngineParameter(SRAL_ENGINE_ANDROID_TEXT_TO_SPEECH, SRAL_PARAM_ANDROID_JNI_ENV, env);
SRAL_SetEngineParameter(SRAL_ENGINE_ANDROID_TEXT_TO_SPEECH, SRAL_PARAM_ANDROID_ACTIVITY, activity);

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 assembleEmbedNoRecordDebug and installed on a real android device with adb install -r <apk path>. I verified TTS output works by interacting with the app.

Note

The Dep/AndroidTTSHelper.java needs 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.

@m1maker m1maker requested review from m1maker and removed request for m1maker March 20, 2026 05:25

@m1maker m1maker left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contributions, but we can't take SDL3 into the project.

@JRJurman

Copy link
Copy Markdown
Contributor Author

Noted! I'll take a look at other options we might have here

@m1maker m1maker marked this pull request as draft March 29, 2026 16:01
@JRJurman

JRJurman commented Apr 13, 2026

Copy link
Copy Markdown
Contributor Author

@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 👍

@JRJurman JRJurman marked this pull request as ready for review April 13, 2026 06:42
@m1maker m1maker self-requested a review April 13, 2026 12:33
@m1maker m1maker merged commit 61abc4b into m1maker:main Apr 13, 2026
3 checks passed
@JRJurman JRJurman mentioned this pull request Apr 13, 2026
@enumag

enumag commented May 13, 2026

Copy link
Copy Markdown

Is it possible to build the android build using GitHub Actions?

@JRJurman

JRJurman commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

@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?

@enumag

enumag commented May 14, 2026

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants