summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2010-09-05 01:19:11 -0700
committerKeith Packard <keithp@keithp.com>2010-09-05 01:19:11 -0700
commit4dec5c36702d76dc95beada7c1d3222a638a2cbb (patch)
tree7727ca0f6f02e38854d408a120bd6c68603e7ea7
parent410ba89eef9c9817eef81b702966cb88820ff7c4 (diff)
altosui: Add AltosVoice.drain() to wait for queued speech to finish
drain() blocks until all pending phrases have been processed, allowing the UI code to avoid pending data that will end up stale by the time it is emitted. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--ao-tools/altosui/AltosVoice.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/ao-tools/altosui/AltosVoice.java b/ao-tools/altosui/AltosVoice.java
index ebe9d5a8..ac13ee14 100644
--- a/ao-tools/altosui/AltosVoice.java
+++ b/ao-tools/altosui/AltosVoice.java
@@ -27,6 +27,7 @@ public class AltosVoice implements Runnable {
Voice voice;
LinkedBlockingQueue<String> phrases;
Thread thread;
+ boolean busy;
final static String voice_name = "kevin16";
@@ -35,15 +36,30 @@ public class AltosVoice implements Runnable {
for (;;) {
String s = phrases.take();
voice.speak(s);
+ synchronized(this) {
+ if (phrases.isEmpty()) {
+ busy = false;
+ notifyAll();
+ }
+ }
}
} catch (InterruptedException e) {
}
}
+ public synchronized void drain() throws InterruptedException {
+ while (busy)
+ wait();
+ }
+
public void speak_always(String s) {
try {
- if (voice != null)
- phrases.put(s);
+ if (voice != null) {
+ synchronized(this) {
+ busy = true;
+ phrases.put(s);
+ }
+ }
} catch (InterruptedException e) {
}
}
@@ -58,6 +74,7 @@ public class AltosVoice implements Runnable {
}
public AltosVoice () {
+ busy = false;
voice_manager = VoiceManager.getInstance();
voice = voice_manager.getVoice(voice_name);
if (voice != null) {