kiwix / kiwix-android

Kiwix for Android
https://android.kiwix.org
GNU General Public License v3.0
906 stars 450 forks source link

"Read aloud" is not always (with a new language) available immediatly #1510

Closed kelson42 closed 4 years ago

kelson42 commented 5 years ago

If I start to read an article in a language in which I never have use read aloud before, it won't work immediatly. First the feature won't generate any sounds for many minutes.... But after trying maybe 10 minutes, then it looks like that it will start to work.

I strongly suspect that in the background Android has to download the voice and that explains why it does not work immediatly. But that should be clearly communicated to the user.

Would be great if my theory could be confirmed.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be now be reviewed manually. Thank you for your contributions.

mohamed-sameh-khalil commented 4 years ago

Is this issue still open ? if so, I would like to work on it

kelson42 commented 4 years ago

@mohamedsamehkhalil Can you reproduce the problem?

mohamed-sameh-khalil commented 4 years ago

@kelson42 No, I tried 3 different foreign languages (Arabic, Abkhazian, chinese) and each time I would get a toast telling me the following :

The language of this page is not supported, or appropriate data was not installed. The article may not be properly read

kelson42 commented 4 years ago

@mohamedsamehkhalil Will be hard for you to fix the pb if you can not reproduce it

macgills commented 4 years ago

Well it sounds like it could be fixed? @mohamedsamehkhalil after trying multiple times did it eventually start reading aloud? If the original hypothesis about the voice needing to be downloaded is correct then after a while it may start working. Your scenario with an error message seems a lot better than the initial behaviour described in the ticket

mohamed-sameh-khalil commented 4 years ago

@macgills, No it did not, I keep trying and I still get the same toast. And so far there is no indication that anything is being downloaded in the background. It could also be that the languages I chose all did not have tts support. @kelson42 could you tell me what languages resulted in the behaviour described by the ticket

mohamed-sameh-khalil commented 4 years ago

I was able to reproduce the problem exactly as described. I have a galaxy phone so it used the Samsung TTS engine by default but when I switched to the Google TTS engine the described behaviour occurs. The problem seems to exist only when using Google TTS engine because instead of reporting a missing language it jumps to downloading the data. I would like to continue working on this issue if it's okay.

macgills commented 4 years ago

@mohamedsamehkhalil please do, you have been assigned

mohamed-sameh-khalil commented 4 years ago

So I think I found the problem and have a solution for it, however I am new here and don't know if I am putting too much details or not enough details in this comment. if I am doing either, please excuse me tell me how I should clarify and I will be glad to hear your improvements to my solution. @kelson42 @macgills

The Problem

the problem occurs at line 134 in KiwixTextToSpeech.java

tts.setLanguage(locale);
if (requestAudioFocus()) {
         loadURL(webView);
}

it happens because the google TTS engine (possibly other engines too) does not return LANG_MISSING_DATA when the voice data is not available, instead it schedules it for download when internet is available which can cause the application to request audio focus without any voice being produced. I have tried it with the Samsung TTS engine but it returns LANG_MISSING_DATA as expected. I did not try any other engines.

My Proposed Solution

after assigning The locale we can get The used voice and check if one of it's features is KEY_FEATURE_NOT_INSTALLED which is returned only if the voice data is not installed and requires installation. more details can be found here and [here](https://developer.android.com/reference/android/speech/tts/Voice.html#getFeatures()). I suggest that whenever the voice data is not available the app will show a toast to inform the user that the download will start when internet is available and skip requesting Audio Focus

macgills commented 4 years ago

Sounds great @mohamedsamehkhalil , I look forward to the pull request