public class TtsEngines extends Object
Constructor and Description |
---|
TtsEngines(Context ctx) |
Modifier and Type | Method and Description |
---|---|
String |
getDefaultEngine() |
TextToSpeech.EngineInfo |
getEngineInfo(String packageName)
Returns the engine info for a given engine name.
|
List<TextToSpeech.EngineInfo> |
getEngines()
Gets a list of all installed TTS engines.
|
String |
getHighestRankedEngineName() |
Locale |
getLocalePrefForEngine(String engineName)
Returns the default locale for a given TTS engine.
|
Locale |
getLocalePrefForEngine(String engineName,
String prefValue)
Returns the default locale for a given TTS engine from given settings string.
|
Intent |
getSettingsIntent(String engine) |
boolean |
isEngineInstalled(String engine) |
boolean |
isLocaleSetToDefaultForEngine(String engineName)
True if a given TTS engine uses the default phone locale as a default locale.
|
static Locale |
normalizeTTSLocale(Locale ttsLocale)
This method tries its best to return a valid
Locale object from the TTS-specific
Locale input (returned by TextToSpeech.getLanguage()
and TextToSpeech.getDefaultLanguage() ). |
Locale |
parseLocaleString(String localeString)
Parses a locale encoded as a string, and tries its best to return a valid
Locale
object, even if the input string is encoded using the old-style 3 character format e.g. |
static String[] |
toOldLocaleStringFormat(Locale locale)
Return the old-style string form of the locale.
|
void |
updateLocalePrefForEngine(String engineName,
Locale newLocale)
Serialize the locale to a string and store it as a default locale for the given engine.
|
public TtsEngines(Context ctx)
public String getDefaultEngine()
EngineInfoComparator
.public String getHighestRankedEngineName()
null
if no TTS engines were present in the system image.public TextToSpeech.EngineInfo getEngineInfo(String packageName)
public List<TextToSpeech.EngineInfo> getEngines()
null
.public boolean isEngineInstalled(String engine)
public Intent getSettingsIntent(String engine)
public Locale getLocalePrefForEngine(String engineName)
Settings.Secure#TTS_DEFAULT_LOCALE
, failing which the
default phone locale is returned.engineName
- the engine to return the locale for.public Locale getLocalePrefForEngine(String engineName, String prefValue)
public boolean isLocaleSetToDefaultForEngine(String engineName)
Settings.Secure#TTS_DEFAULT_LOCALE
. If
its value is empty, this methods returns true.engineName
- the engine to return the locale for.public Locale parseLocaleString(String localeString)
Locale
object, even if the input string is encoded using the old-style 3 character format e.g.
"deu-deu". At the end, we test if the resulting locale can return ISO3 language and
country codes (Locale.getISO3Language()
and Locale.getISO3Country()
),
if it fails to do so, we return null.public static Locale normalizeTTSLocale(Locale ttsLocale)
Locale
object from the TTS-specific
Locale input (returned by TextToSpeech.getLanguage()
and TextToSpeech.getDefaultLanguage()
). A TTS Locale language field contains
a three-letter ISO 639-2/T code (where a proper Locale would use a two-letter ISO 639-1
code), and the country field contains a three-letter ISO 3166 country code (where a proper
Locale would use a two-letter ISO 3166-1 code).
This method tries to convert three-letter language and country codes into their two-letter
equivalents. If it fails to do so, it keeps the value from the TTS locale.public static String[] toOldLocaleStringFormat(Locale locale)
#LOCALE_DELIMITER
ISO 3166 country code"
if the locale has no variant entry#LOCALE_DELIMITER
ISO 3166 country
code#LOCALE_DELIMITER
variant" if the locale has a variant entryLocale.getISO3Country()
and
Locale.getISO3Language()
, then we return new String[]{"eng","USA",""};public void updateLocalePrefForEngine(String engineName, Locale newLocale)
Locale.getDefault()
.