2 * Copyright © 2010 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.altosuilib_9;
20 import com.sun.speech.freetts.Voice;
21 import com.sun.speech.freetts.VoiceManager;
22 import java.util.concurrent.LinkedBlockingQueue;
24 public class AltosVoice implements Runnable {
25 VoiceManager voice_manager;
27 LinkedBlockingQueue<String> phrases;
31 final static String voice_name = "kevin16";
36 String s = phrases.take();
39 if (phrases.isEmpty()) {
45 } catch (InterruptedException e) {
49 public synchronized void drain() throws InterruptedException {
54 public void speak_always(String s) {
62 } catch (InterruptedException e) {
66 public void speak(String s) {
67 if (AltosUIPreferences.voice())
71 public void speak(String format, Object... parameters) {
72 speak(String.format(format, parameters));
75 public AltosVoice () {
77 voice_manager = VoiceManager.getInstance();
78 voice = voice_manager.getVoice(voice_name);
81 phrases = new LinkedBlockingQueue<String> ();
82 thread = new Thread(this);
85 System.out.printf("Voice manager failed to open %s\n", voice_name);
86 Voice[] voices = voice_manager.getVoices();
87 System.out.printf("Available voices:\n");
88 for (int i = 0; i < voices.length; i++) {
89 System.out.println(" " + voices[i].getName()
90 + " (" + voices[i].getDomain() + " domain)");