mirror of
https://github.com/lightsoutgames/godot-tts
synced 2024-11-22 19:35:56 +00:00
Initial Android support.
This commit is contained in:
parent
e02e1dd2b8
commit
ecfee60db5
6
TTS.gd
6
TTS.gd
|
@ -10,6 +10,8 @@ func _ready():
|
||||||
if TTS.can_instance() or Engine.editor_hint:
|
if TTS.can_instance() or Engine.editor_hint:
|
||||||
print_debug("Attempting to load TTS.")
|
print_debug("Attempting to load TTS.")
|
||||||
tts = TTS.new()
|
tts = TTS.new()
|
||||||
|
elif Engine.has_singleton("AndroidTTS"):
|
||||||
|
tts = Engine.get_singleton("AndroidTTS")
|
||||||
else:
|
else:
|
||||||
print_debug("TTS not available!")
|
print_debug("TTS not available!")
|
||||||
|
|
||||||
|
@ -35,7 +37,9 @@ func stop():
|
||||||
tts.stop()
|
tts.stop()
|
||||||
|
|
||||||
func get_is_rate_supported():
|
func get_is_rate_supported():
|
||||||
if tts != null:
|
if Engine.get_singleton("AndroidTTS"):
|
||||||
|
return false
|
||||||
|
elif tts != null:
|
||||||
return tts.is_rate_supported()
|
return tts.is_rate_supported()
|
||||||
else:
|
else:
|
||||||
return false
|
return false
|
||||||
|
|
66
android/src/games/lightsout/godot/tts/TTS.java
Normal file
66
android/src/games/lightsout/godot/tts/TTS.java
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
package games.lightsout.godot.tts;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.speech.tts.TextToSpeech;
|
||||||
|
import android.util.Log;
|
||||||
|
import com.godot.game.R;
|
||||||
|
import javax.microedition.khronos.opengles.GL10;
|
||||||
|
import org.godotengine.godot.Godot;
|
||||||
|
|
||||||
|
public class TTS extends Godot.SingletonBase implements TextToSpeech.OnInitListener {
|
||||||
|
|
||||||
|
protected Activity appActivity;
|
||||||
|
protected Context appContext;
|
||||||
|
private Godot activity = null;
|
||||||
|
private int instanceId = 0;
|
||||||
|
|
||||||
|
private TextToSpeech tts = null;
|
||||||
|
|
||||||
|
private Integer utteranceId = 0;
|
||||||
|
|
||||||
|
public void speak(String text, boolean interrupt) {
|
||||||
|
int mode = TextToSpeech.QUEUE_ADD;
|
||||||
|
if (interrupt)
|
||||||
|
mode = TextToSpeech.QUEUE_FLUSH;
|
||||||
|
tts.speak(text, mode, null, this.utteranceId.toString());
|
||||||
|
this.utteranceId++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
tts.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getInstanceId(int pInstanceId) {
|
||||||
|
// You will need to call this method from Godot and pass in the get_instance_id().
|
||||||
|
instanceId = pInstanceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public Godot.SingletonBase initialize(Activity p_activity) {
|
||||||
|
return new TTS(p_activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TTS(Activity 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"
|
||||||
|
});
|
||||||
|
this.activity.runOnUiThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onInit(int status) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user