mirror of
https://github.com/lightsoutgames/godot-tts
synced 2024-11-22 09:55:56 +00:00
Add signal support to Android.
This commit is contained in:
parent
41c4204224
commit
ed7f3920f6
2
TTS.gd
2
TTS.gd
|
@ -166,7 +166,7 @@ var is_rate_supported setget , _get_is_rate_supported
|
||||||
|
|
||||||
func _get_are_utterance_callbacks_supported():
|
func _get_are_utterance_callbacks_supported():
|
||||||
if Engine.has_singleton("GodotTTS"):
|
if Engine.has_singleton("GodotTTS"):
|
||||||
return false
|
return true
|
||||||
elif OS.has_feature('JavaScript'):
|
elif OS.has_feature('JavaScript'):
|
||||||
return false
|
return false
|
||||||
elif tts != null:
|
elif tts != null:
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
package games.lightsout.godot.tts;
|
package games.lightsout.godot.tts;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.godotengine.godot.Godot;
|
import org.godotengine.godot.Godot;
|
||||||
import org.godotengine.godot.plugin.GodotPlugin;
|
import org.godotengine.godot.plugin.GodotPlugin;
|
||||||
|
import org.godotengine.godot.plugin.SignalInfo;
|
||||||
|
|
||||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.speech.tts.TextToSpeech;
|
import android.speech.tts.TextToSpeech;
|
||||||
|
import android.speech.tts.UtteranceProgressListener;
|
||||||
import android.view.accessibility.AccessibilityManager;
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
|
||||||
public class TTS extends GodotPlugin implements TextToSpeech.OnInitListener {
|
public class TTS extends GodotPlugin implements TextToSpeech.OnInitListener {
|
||||||
|
@ -18,12 +22,14 @@ public class TTS extends GodotPlugin implements TextToSpeech.OnInitListener {
|
||||||
|
|
||||||
private Integer utteranceId = 0;
|
private Integer utteranceId = 0;
|
||||||
|
|
||||||
public void speak(String text, boolean interrupt) {
|
public int speak(String text, boolean interrupt) {
|
||||||
int mode = TextToSpeech.QUEUE_ADD;
|
int mode = TextToSpeech.QUEUE_ADD;
|
||||||
if (interrupt)
|
if (interrupt)
|
||||||
mode = TextToSpeech.QUEUE_FLUSH;
|
mode = TextToSpeech.QUEUE_FLUSH;
|
||||||
tts.speak(text, mode, null, this.utteranceId.toString());
|
tts.speak(text, mode, null, this.utteranceId.toString());
|
||||||
|
int rv = this.utteranceId.intValue();
|
||||||
this.utteranceId++;
|
this.utteranceId++;
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
@ -55,9 +61,27 @@ public class TTS extends GodotPlugin implements TextToSpeech.OnInitListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Listener extends UtteranceProgressListener {
|
||||||
|
public void onStart(String utteranceId) {
|
||||||
|
Integer id = Integer.parseInt(utteranceId);
|
||||||
|
TTS.this.emitSignal("utterance_begin", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDone(String utteranceId) {
|
||||||
|
Integer id = Integer.parseInt(utteranceId);
|
||||||
|
TTS.this.emitSignal("utterance_end", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onError(String utteranceId) {
|
||||||
|
Integer id = Integer.parseInt(utteranceId);
|
||||||
|
TTS.this.emitSignal("utterance_end", id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public TTS(Godot godot) {
|
public TTS(Godot godot) {
|
||||||
super(godot);
|
super(godot);
|
||||||
this.tts = new TextToSpeech(this.getActivity(), this);
|
this.tts = new TextToSpeech(this.getActivity(), this);
|
||||||
|
tts.setOnUtteranceProgressListener(new Listener());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -70,6 +94,13 @@ public class TTS extends GodotPlugin implements TextToSpeech.OnInitListener {
|
||||||
return Arrays.asList("speak", "stop", "get_rate", "set_rate", "has_screen_reader", "is_speaking");
|
return Arrays.asList("speak", "stop", "get_rate", "set_rate", "has_screen_reader", "is_speaking");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<SignalInfo> getPluginSignals() {
|
||||||
|
SignalInfo begin = new SignalInfo("utterance_begin", Integer.class);
|
||||||
|
SignalInfo end = new SignalInfo("utterance_end", Integer.class);
|
||||||
|
return new HashSet(Arrays.asList(begin, end));
|
||||||
|
}
|
||||||
|
|
||||||
public void onInit(int status) {
|
public void onInit(int status) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user