!7 p { tts("Hello"); } // speech libraries! lib 1000722 lib 1000723 lib 1000724 lib 1000730 lib 1000731 lib 1000732 lib 1000726 lib 1000727 import javax.speech.*; import javax.speech.synthesis.*; static Lock tts_lock = fairLock(); sbool tts_debug, tts_disable, tts_verbose; static Synthesizer tts_synth; sS tts(String text) ctex { lock tts_lock; if (tts_verbose) print("Kevin: " + text); if (tts_disable || tts_synth != null && empty(trim(text))) return text; if (tts_synth == null) { System.setProperty("mbrola.base", f2s(userDir("dev/mbrola"))); String voiceName = "mbrola_us1"; System.setProperty("FreeTTSSynthEngineCentral", "com.sun.speech.freetts.jsapi.FreeTTSEngineCentral"); System.setProperty("freetts.voices", "de.dfki.lt.freetts.en.us.MbrolaVoiceDirectory"); Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral"); SynthesizerModeDesc desc = new SynthesizerModeDesc(null, "general", Locale.US, null, null); if (tts_debug) print("Creating synth"); Synthesizer synth = tts_synth = Central.createSynthesizer(desc); synth.allocate(); desc = (SynthesizerModeDesc) synth.getEngineModeDesc(); Voice[] voices = desc.getVoices(); Voice voice = null; for (Voice entry : voices) { if(entry.getName().equals(voiceName)) { voice = entry; break; } } if (tts_debug) print("Voice: " + voice); synth.getSynthesizerProperties().setVoice(voice); synth.resume(); } if (tts_debug) print("Speaking..."); tts_synth.speakPlainText(text, null); if (tts_debug) print("Waiting"); // TODO: We wait later anyway long state; int n = 0; while (((state = tts_synth.getEngineState()) & Synthesizer.QUEUE_EMPTY) != 0) { sleep(50); if (++n >= 10000/50) { print("Engine state: " + state + ", aborting"); break; } } //tts_synth.waitEngineState(Synthesizer.QUEUE_EMPTY); if (tts_debug) print("Done"); // keep synth for next time //tts_synth.deallocate(); ret text; }