Skip to content

Commit

Permalink
Merge pull request #43 from garwiz/master
Browse files Browse the repository at this point in the history
Added optional region and variant params to TTS intent
  • Loading branch information
fornwall authored Sep 4, 2016
2 parents 1f57769 + 50672b0 commit 0026f1a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion app/src/main/java/com/termux/api/TextToSpeechAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public void onDestroy() {
@Override
protected void onHandleIntent(final Intent intent) {
final String speechLanguage = intent.getStringExtra("language");
final String speechRegion = intent.getStringExtra("region");
final String speechVariant = intent.getStringExtra("variant");
final String speechEngine = intent.getStringExtra("engine");
final float speechPitch = intent.getFloatExtra("pitch", 1.0f);

Expand Down Expand Up @@ -148,7 +150,7 @@ public void onDone(String utteranceId) {
});

if (speechLanguage != null) {
int setLanguageResult = mTts.setLanguage(new Locale(speechLanguage));
int setLanguageResult = mTts.setLanguage(getLocale(speechLanguage, speechRegion, speechVariant));
if (setLanguageResult != TextToSpeech.LANG_AVAILABLE) {
TermuxApiLogger.error("tts.setLanguage('" + speechLanguage + "') returned " + setLanguageResult);
}
Expand Down Expand Up @@ -187,4 +189,17 @@ public void onDone(String utteranceId) {
}
}

private static Locale getLocale(String language, String region, String variant) {
Locale result = null;
if (region != null) {
if (variant != null) {
result = new Locale(language, region, variant);
} else {
result = new Locale(language, region);
}
} else {
result = new Locale(language);
}
return result;
}
}

0 comments on commit 0026f1a

Please sign in to comment.