Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added optional region and variant params to TTS intent #43

Merged
merged 1 commit into from
Sep 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}