Skip to content

Support Android TTS#7497

Open
Shivansps wants to merge 8 commits into
scp-fs2open:masterfrom
Shivansps:tts-android
Open

Support Android TTS#7497
Shivansps wants to merge 8 commits into
scp-fs2open:masterfrom
Shivansps:tts-android

Conversation

@Shivansps

@Shivansps Shivansps commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

This is another part of the work split from the Android PR. Since this is non critical and does not depend on any changes to the build process or SDL version, it can be reviewed and merged at any time.
Testing was done on the android builds.

How this works:

To launch a SDL app in Android you need to make you own activity class that extend the SDL java class, were you set all the paramenters needed.
You can add anything more to this class to do whatever you want, and from the C++ side it is possible to use SDL + JNI (included in the NDK) to call static methods on the java side.

So for the TTS to work the java side handles all calls to the TTS service, then brings an "api" that can be used from C++. The java side looks something like this for the GameActivity that starts the game and the TTS itselft is handled on a separated class.

 // TTS wrappers ----------------------------------------------------------
public static boolean tts_speak(String text)     { return TTSManager.speak(text); }
public static boolean tts_stop()                 { return TTSManager.stop(); }
public static boolean tts_pause()                { return TTSManager.pause(); }
public static boolean tts_resume()               { return TTSManager.resume(); }
public static boolean tts_isSpeaking()           { return TTSManager.isSpeaking(); }
public static void    tts_shutdown()             { TTSManager.shutdown(); }
public static void    tts_setRate(float rate)    { TTSManager.setRate(rate); }
public static void    tts_setLanguageTag(String tag) { TTSManager.setLanguageTag(tag); }
public static String[] tts_getAvailableLanguageTags() { return TTSManager.getAvailableLanguageTags(); }
// ------------------------------------------------------------------------- 

More details on how that works on the java side can be look at here:
https://github.com/Shivansps/Fso_Android_Wrapper/tree/main/app/src/main/java/com/shivansps/fsowrapper
(GameActivity.java and /tts/TTSManager.java)

If the GameActivity class is somehow missing some or all methods, the init will fail and it will be printed in the log the expected method name and signature, so there is no need to look at external code to make your own version if desired.

Note: the pointer "JNIEnv*" is handled by SDL and must not be freed. Thats not a memory leak.

@BMagnu BMagnu added enhancement A new feature or upgrade of an existing feature to add additional functionality. Waiting for Stable Marks a pull request that is to be merged after the next stable release, due to a release cycle labels Jun 4, 2026
Comment thread code/sound/fsspeech.cpp Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement A new feature or upgrade of an existing feature to add additional functionality. Waiting for Stable Marks a pull request that is to be merged after the next stable release, due to a release cycle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants