X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=ao-tools%2Faltosui%2FAltosVoice.java;h=ac13ee14e81176c69d46587392340c3a8018ba62;hb=a08b2a6363c194195db92029743f6612676373ce;hp=0c34795c55083981df54cf56f9ff6dcdf74e6c8a;hpb=005e2d6a7bb3b0546b0c1273296875621632ec6d;p=fw%2Faltos diff --git a/ao-tools/altosui/AltosVoice.java b/ao-tools/altosui/AltosVoice.java index 0c34795c..ac13ee14 100644 --- a/ao-tools/altosui/AltosVoice.java +++ b/ao-tools/altosui/AltosVoice.java @@ -17,18 +17,17 @@ package altosui; -/*import com.sun.speech.freetts.Voice; +import com.sun.speech.freetts.Voice; import com.sun.speech.freetts.VoiceManager; -import com.sun.speech.freetts.audio.JavaClipAudioPlayer; */ +import com.sun.speech.freetts.audio.JavaClipAudioPlayer; import java.util.concurrent.LinkedBlockingQueue; public class AltosVoice implements Runnable { -/* VoiceManager voice_manager; Voice voice; -*/ LinkedBlockingQueue phrases; Thread thread; + boolean busy; final static String voice_name = "kevin16"; @@ -36,29 +35,54 @@ public class AltosVoice implements Runnable { try { for (;;) { String s = phrases.take(); -/* voice.speak(s); */ + 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 () { -/* voice_manager = VoiceManager.getInstance(); + busy = false; + voice_manager = VoiceManager.getInstance(); voice = voice_manager.getVoice(voice_name); - if (voice != null) */ { -/* voice.allocate(); */ + if (voice != null) { + voice.allocate(); phrases = new LinkedBlockingQueue (); thread = new Thread(this); thread.start(); - speak("Rocket Flight Monitor Ready"); - } /* else { + } else { System.out.printf("Voice manager failed to open %s\n", voice_name); Voice[] voices = voice_manager.getVoices(); System.out.printf("Available voices:\n"); @@ -66,6 +90,6 @@ public class AltosVoice implements Runnable { System.out.println(" " + voices[i].getName() + " (" + voices[i].getDomain() + " domain)"); } - } */ + } } }