1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

Add audio/general/text_to_speech project setting to enable/disable TTS.

This commit is contained in:
bruvzg
2023-05-22 16:41:09 +03:00
parent a810c8c5f6
commit 18ee8da7d6
16 changed files with 132 additions and 32 deletions

View File

@@ -440,7 +440,9 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
final String[] current_command_line = command_line;
mView.queueEvent(() -> {
if (!GodotLib.setup(current_command_line)) {
tts = new GodotTTS(activity);
if (!GodotLib.setup(current_command_line, tts)) {
godot_initialized = false;
Log.e(TAG, "Unable to setup the Godot engine! Aborting...");
alert(R.string.error_engine_setup_message, R.string.text_error_title, this::forceQuit);
@@ -663,7 +665,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 = new FileAccessHandler(context);
@@ -673,7 +674,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
GodotLib.initialize(activity, this, activity.getAssets(), io, netUtils, directoryAccessHandler, fileAccessHandler, use_apk_expansion, tts);
GodotLib.initialize(activity, this, activity.getAssets(), io, netUtils, directoryAccessHandler, fileAccessHandler, use_apk_expansion);
result_callback = null;

View File

@@ -53,7 +53,7 @@ public class GodotLib {
/**
* Invoked on the main thread to initialize Godot native layer.
*/
public static native void initialize(Activity activity, Godot p_instance, AssetManager p_asset_manager, GodotIO godotIO, GodotNetUtils netUtils, DirectoryAccessHandler directoryAccessHandler, FileAccessHandler fileAccessHandler, boolean use_apk_expansion, GodotTTS tts);
public static native void initialize(Activity activity, Godot p_instance, AssetManager p_asset_manager, GodotIO godotIO, GodotNetUtils netUtils, DirectoryAccessHandler directoryAccessHandler, FileAccessHandler fileAccessHandler, boolean use_apk_expansion);
/**
* Invoked on the main thread to clean up Godot native layer.
@@ -65,7 +65,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.

View File

@@ -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() {
@@ -186,6 +184,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.
*/