Implement rate on Android in a way that is compatible with the new API.

This commit is contained in:
Nolan Darilek 2020-05-19 08:10:02 -05:00
parent 8b591704a3
commit 4495b89ff3
2 changed files with 15 additions and 14 deletions

14
TTS.gd
View File

@ -55,25 +55,29 @@ var normal_rate setget , _get_normal_rate
var javascript_rate = 50
func set_rate(rate):
func _set_rate(rate):
if rate < self.min_rate:
rate = self.min_rate
elif rate > self.max_rate:
rate = self.max_rate
if tts != null:
if Engine.has_singleton("AndroidTTS"):
return tts.set_rate(rate)
elif tts != null:
tts.rate = rate
elif OS.has_feature('JavaScript'):
javascript_rate = rate
func get_rate():
if tts != null:
func _get_rate():
if Engine.has_singleton("AndroidTTS"):
return tts.get_rate()
elif tts != null:
return tts.rate
elif OS.has_feature('JavaScript'):
return javascript_rate
else:
return 0
var rate setget set_rate, get_rate
var rate setget _set_rate, _get_rate
func _get_rate_percentage():
return range_lerp(self.rate, self.min_rate, self.max_rate, 0, 100)

View File

@ -32,15 +32,12 @@ public class TTS extends Godot.SingletonBase implements TextToSpeech.OnInitListe
tts.stop();
}
public void set_rate(Float rate) {
Float newRate;
if (rate <= 50)
newRate = rate / 50;
else {
newRate = rate - 50;
newRate = 1 + (newRate / 5);
public float get_rate() {
return tts.getSpeechRate();
}
tts.setSpeechRate(newRate);
public void set_rate(Float rate) {
tts.setSpeechRate(rate);
}
public void getInstanceId(int pInstanceId) {
@ -59,7 +56,7 @@ public class TTS extends Godot.SingletonBase implements TextToSpeech.OnInitListe
this.appContext = appActivity.getApplicationContext();
this.tts = new TextToSpeech(this.appContext, this);
// Register class name and functions to bind.
registerClass("AndroidTTS", new String[] { "speak", "stop", "set_rate", "getInstanceId" });
registerClass("AndroidTTS", new String[] { "speak", "stop", "get_rate", "set_rate", "getInstanceId" });
this.activity.runOnUiThread(new Runnable() {
public void run() {
}