mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-03 11:23:48 +00:00
[android] Load TTS languages from core
Signed-off-by: Andrei Shkrob <github@shkrob.dev>
This commit is contained in:
committed by
Konstantin Pastbin
parent
0a96a23ca0
commit
ebc5370052
@@ -1,7 +1,6 @@
|
||||
package app.organicmaps.sdk.sound;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@@ -10,9 +9,9 @@ import android.provider.Settings;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
import android.speech.tts.UtteranceProgressListener;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Pair;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.sdk.util.Config;
|
||||
import app.organicmaps.sdk.util.concurrency.UiThread;
|
||||
import app.organicmaps.sdk.util.log.Logger;
|
||||
@@ -43,6 +42,9 @@ public enum TtsPlayer
|
||||
private static final float SPEECH_RATE = 1.0f;
|
||||
private static final int TTS_SPEAK_DELAY_MILLIS = 50;
|
||||
|
||||
@Nullable
|
||||
private static List<Pair<String, String>> sSupportedLanguages = null;
|
||||
|
||||
public static Runnable sOnReloadCallback = null;
|
||||
|
||||
private ContentObserver mTtsEngineObserver;
|
||||
@@ -286,19 +288,15 @@ public enum TtsPlayer
|
||||
|
||||
private boolean getUsableLanguages(List<LanguageData> outList)
|
||||
{
|
||||
Resources resources = mContext.getResources();
|
||||
String[] codes = resources.getStringArray(R.array.tts_languages_supported);
|
||||
String[] names = resources.getStringArray(R.array.tts_language_names);
|
||||
|
||||
for (int i = 0; i < codes.length; i++)
|
||||
for (final Pair<String, String> langNamePair : getSupportedLanguages())
|
||||
{
|
||||
try
|
||||
{
|
||||
outList.add(new LanguageData(codes[i], names[i], mTts));
|
||||
outList.add(new LanguageData(langNamePair.first, langNamePair.second, mTts));
|
||||
}
|
||||
catch (LanguageData.NotAvailableException ignored)
|
||||
catch (LanguageData.NotAvailableException ex)
|
||||
{
|
||||
Logger.w(TAG, "Failed to get usable languages " + ignored.getMessage());
|
||||
Logger.w(TAG, "Failed to get usable languages " + ex.getMessage());
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
@@ -351,8 +349,20 @@ public enum TtsPlayer
|
||||
return res;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private List<Pair<String, String>> getSupportedLanguages()
|
||||
{
|
||||
if (sSupportedLanguages == null)
|
||||
{
|
||||
sSupportedLanguages = nativeGetSupportedLanguages();
|
||||
}
|
||||
return sSupportedLanguages;
|
||||
}
|
||||
|
||||
private native static void nativeEnableTurnNotifications(boolean enable);
|
||||
private native static boolean nativeAreTurnNotificationsEnabled();
|
||||
private native static void nativeSetTurnNotificationsLocale(String code);
|
||||
private native static String nativeGetTurnNotificationsLocale();
|
||||
@NonNull
|
||||
private native static List<Pair<String, String>> nativeGetSupportedLanguages();
|
||||
}
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!--
|
||||
Supported voice languages. Should have language[-country][:code] format.
|
||||
Where:
|
||||
language - two-letter ISO 639-1 language code.
|
||||
country - two-letter ISO 3166-1 (alpha-2) country code.
|
||||
code - internal language code to be set in the core.
|
||||
If not specified, language is used.
|
||||
|
||||
Chinese is an exception. Matching is based on country code:
|
||||
zh_TW, zh_MO and zh_HK correspond to zh-Hant.
|
||||
Otherwise we consider that this is zh-Hans.
|
||||
|
||||
TODO: Move language list to core, now sync manually with platform/languages.hpp
|
||||
|
||||
languages should be added alphabetically in tts_language_names
|
||||
-->
|
||||
<string-array name="tts_languages_supported"
|
||||
translatable="false">
|
||||
<item>en</item>
|
||||
<item>id</item>
|
||||
<item>ca</item>
|
||||
<item>da</item>
|
||||
<item>de</item>
|
||||
<item>es-ES:es</item>
|
||||
<item>es-MX:es-MX</item>
|
||||
<item>eu</item>
|
||||
<item>fr</item>
|
||||
<item>hr</item>
|
||||
<item>it</item>
|
||||
<item>sw</item>
|
||||
<item>hu</item>
|
||||
<item>nl</item>
|
||||
<item>nb</item>
|
||||
<item>pl</item>
|
||||
<item>pt-PT:pt</item>
|
||||
<item>pt-BR:pt-BR</item>
|
||||
<item>ro</item>
|
||||
<item>sk</item>
|
||||
<item>fi</item>
|
||||
<item>sv</item>
|
||||
<item>vi</item>
|
||||
<item>tr</item>
|
||||
<item>cs</item>
|
||||
<item>el</item>
|
||||
<item>be</item>
|
||||
<item>bg</item>
|
||||
<item>ru</item>
|
||||
<item>sr</item>
|
||||
<item>uk</item>
|
||||
<item>ar</item>
|
||||
<item>fa</item>
|
||||
<item>mr</item>
|
||||
<item>hi</item>
|
||||
<item>th</item>
|
||||
<item>zh-CN:zh-Hans</item>
|
||||
<item>zh-TW:zh-Hant</item>
|
||||
<item>ja</item>
|
||||
<item>ko</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="tts_language_names"
|
||||
translatable="false">
|
||||
<item>English</item>
|
||||
<item>Bahasa Indonesia</item>
|
||||
<item>Català</item>
|
||||
<item>Dansk</item>
|
||||
<item>Deutsch</item>
|
||||
<item>Español</item>
|
||||
<item>Español (México)</item>
|
||||
<item>Euskara</item>
|
||||
<item>Français</item>
|
||||
<item>Hrvatski</item>
|
||||
<item>Italiano</item>
|
||||
<item>Kiswahili</item>
|
||||
<item>Magyar</item>
|
||||
<item>Nederlands</item>
|
||||
<item>Norsk Bokmål</item>
|
||||
<item>Polski</item>
|
||||
<item>Português</item>
|
||||
<item>Português (Brasil)</item>
|
||||
<item>Română</item>
|
||||
<item>Slovenčina</item>
|
||||
<item>Suomi</item>
|
||||
<item>Svenska</item>
|
||||
<item>Tiếng Việt</item>
|
||||
<item>Türkçe</item>
|
||||
<item>Čeština</item>
|
||||
<item>Ελληνικά</item>
|
||||
<item>Беларуская</item>
|
||||
<item>Български</item>
|
||||
<item>Русский</item>
|
||||
<item>Српски</item>
|
||||
<item>Українська</item>
|
||||
<item>العربية</item>
|
||||
<item>فارسی</item>
|
||||
<item>मराठी</item>
|
||||
<item>हिन्दी</item>
|
||||
<item>ไทย</item>
|
||||
<item>中文简体</item>
|
||||
<item>中文繁體</item>
|
||||
<item>日本語</item>
|
||||
<item>한국어</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user