summaryrefslogtreecommitdiffstats
path: root/platform/android/java/lib
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2023-05-16 14:18:12 +0300
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2023-05-18 20:16:03 +0300
commit5b9984b5a21f23c8e0b56c64304c34995c8bd5b3 (patch)
treef37e0c338a5c701c49a9440a2d5d9ab7a39f5506 /platform/android/java/lib
parent91f3cdfde0e8c5be58004228d62799912b8e4db7 (diff)
downloadredot-engine-5b9984b5a21f23c8e0b56c64304c34995c8bd5b3.tar.gz
Add `audio/general/text_to_speech` project setting to enable/disable TTS.
Diffstat (limited to 'platform/android/java/lib')
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/Godot.java8
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotLib.java5
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/tts/GodotTTS.java20
3 files changed, 20 insertions, 13 deletions
diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.java b/platform/android/java/lib/src/org/godotengine/godot/Godot.java
index 99527ccf3a..4c47ca9760 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/Godot.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.java
@@ -274,7 +274,9 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
// ...add to FrameLayout
containerLayout.addView(editText);
- if (!GodotLib.setup(command_line)) {
+ tts = new GodotTTS(activity);
+
+ if (!GodotLib.setup(command_line, tts)) {
Log.e(TAG, "Unable to setup the Godot engine! Aborting...");
alert(R.string.error_engine_setup_message, R.string.text_error_title, this::forceQuit);
return false;
@@ -574,7 +576,6 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
final Activity activity = getActivity();
io = new GodotIO(activity);
netUtils = new GodotNetUtils(activity);
- tts = new GodotTTS(activity);
Context context = getContext();
directoryAccessHandler = new DirectoryAccessHandler(context);
FileAccessHandler fileAccessHandler = new FileAccessHandler(context);
@@ -591,8 +592,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
netUtils,
directoryAccessHandler,
fileAccessHandler,
- use_apk_expansion,
- tts);
+ use_apk_expansion);
result_callback = null;
}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
index d9aab950df..c725b1a7c9 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
@@ -61,8 +61,7 @@ public class GodotLib {
GodotNetUtils netUtils,
DirectoryAccessHandler directoryAccessHandler,
FileAccessHandler fileAccessHandler,
- boolean use_apk_expansion,
- GodotTTS tts);
+ boolean use_apk_expansion);
/**
* Invoked on the main thread to clean up Godot native layer.
@@ -74,7 +73,7 @@ public class GodotLib {
* Invoked on the GL thread to complete setup for the Godot native layer logic.
* @param p_cmdline Command line arguments used to configure Godot native layer components.
*/
- public static native boolean setup(String[] p_cmdline);
+ public static native boolean setup(String[] p_cmdline, GodotTTS tts);
/**
* Invoked on the GL thread when the underlying Android surface has changed size.
diff --git a/platform/android/java/lib/src/org/godotengine/godot/tts/GodotTTS.java b/platform/android/java/lib/src/org/godotengine/godot/tts/GodotTTS.java
index ebab8398de..edace53e7f 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/tts/GodotTTS.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/tts/GodotTTS.java
@@ -62,8 +62,9 @@ public class GodotTTS extends UtteranceProgressListener {
final private static int EVENT_CANCEL = 2;
final private static int EVENT_BOUNDARY = 3;
- final private TextToSpeech synth;
- final private LinkedList<GodotUtterance> queue;
+ final private Activity activity;
+ private TextToSpeech synth;
+ private LinkedList<GodotUtterance> queue;
final private Object lock = new Object();
private GodotUtterance lastUtterance;
@@ -71,10 +72,7 @@ public class GodotTTS extends UtteranceProgressListener {
private boolean paused;
public GodotTTS(Activity p_activity) {
- synth = new TextToSpeech(p_activity, null);
- queue = new LinkedList<GodotUtterance>();
-
- synth.setOnUtteranceProgressListener(this);
+ activity = p_activity;
}
private void updateTTS() {
@@ -187,6 +185,16 @@ public class GodotTTS extends UtteranceProgressListener {
}
/**
+ * Initialize synth and query.
+ */
+ public void init() {
+ synth = new TextToSpeech(activity, null);
+ queue = new LinkedList<GodotUtterance>();
+
+ synth.setOnUtteranceProgressListener(this);
+ }
+
+ /**
* Adds an utterance to the queue.
*/
public void speak(String text, String voice, int volume, float pitch, float rate, int utterance_id, boolean interrupt) {