Voice voice;
LinkedBlockingQueue<String> phrases;
Thread thread;
+ boolean busy;
final static String voice_name = "kevin16";
for (;;) {
String s = phrases.take();
voice.speak(s);
+ synchronized(this) {
+ if (phrases.isEmpty()) {
+ busy = false;
+ notifyAll();
+ }
+ }
}
} catch (InterruptedException e) {
}
}
- public void speak(String s) {
+
+ 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) {
}
}
+ public void speak(String s) {
+ if (AltosPreferences.voice())
+ speak_always(s);
+ }
+
+ public void speak(String format, Object... parameters) {
+ speak(String.format(format, parameters));
+ }
+
public AltosVoice () {
+ busy = false;
voice_manager = VoiceManager.getInstance();
voice = voice_manager.getVoice(voice_name);
if (voice != null) {
phrases = new LinkedBlockingQueue<String> ();
thread = new Thread(this);
thread.start();
- speak("Rocket Flight Monitor Ready");
} else {
System.out.printf("Voice manager failed to open %s\n", voice_name);
Voice[] voices = voice_manager.getVoices();