From 691dd66054b873a9b2bfaee3973e973578cc8574 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Sun, 17 May 2020 12:46:57 -0500 Subject: [PATCH] Experimental untested support for setting speech rate on Android. --- TTS.gd | 2 +- .../src/games/lightsout/godot/tts/TTS.java | 23 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/TTS.gd b/TTS.gd index 14f704c..8368132 100644 --- a/TTS.gd +++ b/TTS.gd @@ -70,7 +70,7 @@ func stop(): func get_is_rate_supported(): if Engine.get_singleton("AndroidTTS"): - return false + return true elif OS.has_feature('JavaScript'): return true elif tts != null: diff --git a/android/src/games/lightsout/godot/tts/TTS.java b/android/src/games/lightsout/godot/tts/TTS.java index e784d97..b391915 100644 --- a/android/src/games/lightsout/godot/tts/TTS.java +++ b/android/src/games/lightsout/godot/tts/TTS.java @@ -32,8 +32,20 @@ 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); + } + tts.setSpeechRate(newRate); + } + public void getInstanceId(int pInstanceId) { - // You will need to call this method from Godot and pass in the get_instance_id(). + // You will need to call this method from Godot and pass in the + // get_instance_id(). instanceId = pInstanceId; } @@ -42,17 +54,12 @@ public class TTS extends Godot.SingletonBase implements TextToSpeech.OnInitListe } public TTS(Activity p_activity) { - this.activity = (Godot)p_activity; + this.activity = (Godot) p_activity; this.appActivity = p_activity; this.appContext = appActivity.getApplicationContext(); this.tts = new TextToSpeech(this.appContext, this); // Register class name and functions to bind. - registerClass("AndroidTTS", new String[] - { - "speak", - "stop", - "getInstanceId" - }); + registerClass("AndroidTTS", new String[] { "speak", "stop", "set_rate", "getInstanceId" }); this.activity.runOnUiThread(new Runnable() { public void run() { }