niedev / RTranslator

Open source real-time translation app for Android that runs locally
Apache License 2.0
4.96k stars 367 forks source link

Added support for Samsung TTS Engine #24

Closed JingziC closed 5 days ago

JingziC commented 6 days ago

Hello,

Thank you so much for the awesome offline realtime translator app. It is very convenient and helpful even without text-to-speech services. I tried to modify the "app/src/main/java/nie/translator/rtranslator/tools/TTS.java" to support the Samsung TTS engine in this app and tested on the Samsung Galaxy S21 with Android 14. The built app could use text-to-speech engine from Samsung successfully.

As mentioned in Issue #8 and #15, it sometimes could not load Google TTS engine thus disable text-to-speech functionality. I also encountered this bug and noticed that only Samsung's TTS engine could be loaded when importing "android.speech.tts.TextToSpeech" and the Google TTS Engine was missed (although Google TTS engine was set as the default text-to-speech output). Thus the app could not find the correct text-to-speech engine.

In the modified TTS.java, some lines pairing the engine and corresponding available languages were added. It is expected to support at least samsung's engine while keeping compatible with the Google TTS engine in previous program.

However, it still requires validations on other devices. The program for validation has been built in an .apk file for a quick check and also can be built from this branch.

Available TTS Engine from "android.speech.tts.TextToSpeech" (https://github.com/JingziC/TTSLister was used to check the available tts engines on device directly):

Available_TTS_Engine
niedev commented 6 days ago

Thank you for the appreciation and for your contribution! Tomorrow I will check your changes 👍

niedev commented 5 days ago

Great work, thanks!

I made some changes to the format of the code and for some comments, and I restored the default low quality value to false.

The default behavior of the app is to not show languages ​​with low quality TTS, if Japanese does not have high quality it is not a problem, in that case the user can still use the language by changing the RTranslator settings, but knowing that the quality of the TTS is lower than normal.

I will do other tests and then merge the pull request.

niedev commented 5 days ago

Ok, with the quality threshold set to QUALITY_HIGH, the supported languages with Samsung TTS were only 3. So I lowered the default threshold to QUALITY_NORMAL.

Plus I discovered a bug where the low-quality TTS option in RTranslator wasn't working (in case you noticed something was wrong this was it), I will correct it right after the merge.

I tested everything else and it works, so I will merge the pull request.