mirror of
https://github.com/lightsoutgames/godot-tts
synced 2024-11-22 15:05:56 +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
|
var javascript_rate = 50
|
||||||
|
|
||||||
func set_rate(rate):
|
func _set_rate(rate):
|
||||||
if rate < self.min_rate:
|
if rate < self.min_rate:
|
||||||
rate = self.min_rate
|
rate = self.min_rate
|
||||||
elif rate > self.max_rate:
|
elif rate > self.max_rate:
|
||||||
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
|
tts.rate = rate
|
||||||
elif OS.has_feature('JavaScript'):
|
elif OS.has_feature('JavaScript'):
|
||||||
javascript_rate = rate
|
javascript_rate = rate
|
||||||
|
|
||||||
func get_rate():
|
func _get_rate():
|
||||||
if tts != null:
|
if Engine.has_singleton("AndroidTTS"):
|
||||||
|
return tts.get_rate()
|
||||||
|
elif tts != null:
|
||||||
return tts.rate
|
return tts.rate
|
||||||
elif OS.has_feature('JavaScript'):
|
elif OS.has_feature('JavaScript'):
|
||||||
return javascript_rate
|
return javascript_rate
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
var rate setget set_rate, get_rate
|
var rate setget _set_rate, _get_rate
|
||||||
|
|
||||||
func _get_rate_percentage():
|
func _get_rate_percentage():
|
||||||
return range_lerp(self.rate, self.min_rate, self.max_rate, 0, 100)
|
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();
|
tts.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float get_rate() {
|
||||||
|
return tts.getSpeechRate();
|
||||||
|
}
|
||||||
|
|
||||||
public void set_rate(Float rate) {
|
public void set_rate(Float rate) {
|
||||||
Float newRate;
|
tts.setSpeechRate(rate);
|
||||||
if (rate <= 50)
|
|
||||||
newRate = rate / 50;
|
|
||||||
else {
|
|
||||||
newRate = rate - 50;
|
|
||||||
newRate = 1 + (newRate / 5);
|
|
||||||
}
|
|
||||||
tts.setSpeechRate(newRate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getInstanceId(int pInstanceId) {
|
public void getInstanceId(int pInstanceId) {
|
||||||
|
@ -59,7 +56,7 @@ public class TTS extends Godot.SingletonBase implements TextToSpeech.OnInitListe
|
||||||
this.appContext = appActivity.getApplicationContext();
|
this.appContext = appActivity.getApplicationContext();
|
||||||
this.tts = new TextToSpeech(this.appContext, this);
|
this.tts = new TextToSpeech(this.appContext, this);
|
||||||
// Register class name and functions to bind.
|
// 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() {
|
this.activity.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user