mirror of
https://github.com/lightsoutgames/godot-tts
synced 2024-11-25 13:45:57 +00:00
Implement rate on Android in a way that is compatible with the new API.
This commit is contained in:
parent
8b591704a3
commit
4495b89ff3
14
TTS.gd
14
TTS.gd
|
@ -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)
|
||||
|
|
|
@ -32,15 +32,12 @@ public class TTS extends Godot.SingletonBase implements TextToSpeech.OnInitListe
|
|||
tts.stop();
|
||||
}
|
||||
|
||||
public float get_rate() {
|
||||
return tts.getSpeechRate();
|
||||
}
|
||||
|
||||
public void set_rate(Float rate) {
|
||||
Float newRate;
|
||||
if (rate <= 50)
|
||||
newRate = rate / 50;
|
||||
else {
|
||||
newRate = rate - 50;
|
||||
newRate = 1 + (newRate / 5);
|
||||
}
|
||||
tts.setSpeechRate(newRate);
|
||||
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() {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user