Skip to content

Commit 09f6291

Browse files
authored
refactor: remove unnecessary compatibility code (#145)
Capacitor 7 requires Android SDK level 23+, so an SDK level below 21 is not possible.
1 parent de65580 commit 09f6291

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

android/src/main/java/com/getcapacitor/community/tts/TextToSpeech.java

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,33 +105,22 @@ public void speak(
105105

106106
Locale locale = Locale.forLanguageTag(lang);
107107

108-
if (Build.VERSION.SDK_INT >= 21) {
109-
Bundle ttsParams = new Bundle();
110-
ttsParams.putSerializable(android.speech.tts.TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackId);
111-
ttsParams.putSerializable(android.speech.tts.TextToSpeech.Engine.KEY_PARAM_VOLUME, volume);
112-
113-
tts.setLanguage(locale);
114-
tts.setSpeechRate(rate);
115-
tts.setPitch(pitch);
116-
117-
if (voice >= 0) {
118-
ArrayList<Voice> supportedVoices = getSupportedVoicesOrdered();
119-
if (voice < supportedVoices.size()) {
120-
Voice newVoice = supportedVoices.get(voice);
121-
int resultCode = tts.setVoice(newVoice);
122-
}
108+
Bundle ttsParams = new Bundle();
109+
ttsParams.putSerializable(android.speech.tts.TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackId);
110+
ttsParams.putSerializable(android.speech.tts.TextToSpeech.Engine.KEY_PARAM_VOLUME, volume);
111+
112+
tts.setLanguage(locale);
113+
tts.setSpeechRate(rate);
114+
tts.setPitch(pitch);
115+
116+
if (voice >= 0) {
117+
ArrayList<Voice> supportedVoices = getSupportedVoicesOrdered();
118+
if (voice < supportedVoices.size()) {
119+
Voice newVoice = supportedVoices.get(voice);
120+
int resultCode = tts.setVoice(newVoice);
123121
}
124-
tts.speak(text, queueStrategy, ttsParams, callbackId);
125-
} else {
126-
HashMap<String, String> ttsParams = new HashMap<>();
127-
ttsParams.put(android.speech.tts.TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackId);
128-
ttsParams.put(android.speech.tts.TextToSpeech.Engine.KEY_PARAM_VOLUME, Float.toString(volume));
129-
130-
tts.setLanguage(locale);
131-
tts.setSpeechRate(rate);
132-
tts.setPitch(pitch);
133-
tts.speak(text, queueStrategy, ttsParams);
134122
}
123+
tts.speak(text, queueStrategy, ttsParams, callbackId);
135124
}
136125

137126
public void stop() {

0 commit comments

Comments
 (0)