这是indexloc提供的服务,不要输入任何密码
Skip to content
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;
}
}