summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
410ba89)
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>
Voice voice;
LinkedBlockingQueue<String> phrases;
Thread thread;
Voice voice;
LinkedBlockingQueue<String> phrases;
Thread thread;
final static String voice_name = "kevin16";
final static String voice_name = "kevin16";
for (;;) {
String s = phrases.take();
voice.speak(s);
for (;;) {
String s = phrases.take();
voice.speak(s);
+ synchronized(this) {
+ if (phrases.isEmpty()) {
+ busy = false;
+ notifyAll();
+ }
+ }
}
} catch (InterruptedException e) {
}
}
}
} catch (InterruptedException e) {
}
}
+ public synchronized void drain() throws InterruptedException {
+ while (busy)
+ wait();
+ }
+
public void speak_always(String s) {
try {
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) {
}
}
} catch (InterruptedException e) {
}
}
voice_manager = VoiceManager.getInstance();
voice = voice_manager.getVoice(voice_name);
if (voice != null) {
voice_manager = VoiceManager.getInstance();
voice = voice_manager.getVoice(voice_name);
if (voice != null) {