2 * Copyright 2003 Sun Microsystems, Inc.
4 * See the file "license.terms" for information on usage and
5 * redistribution of this file, and for a DISCLAIMER OF ALL
9 package com.sun.speech.freetts.jsapi;
10 import java.util.LinkedList;
11 import java.util.List;
12 import java.util.Locale;
14 import javax.speech.Engine;
15 import javax.speech.EngineCreate;
16 import javax.speech.EngineException;
17 import javax.speech.synthesis.SynthesizerModeDesc;
19 import com.sun.speech.engine.synthesis.BaseVoice;
20 import com.sun.speech.freetts.ValidationException;
23 * Represents a SynthesizerModeDesc for the
24 * FreeTTSSynthesizer. A FreeTTSSynthesizerModeDesc adds
25 * an audio player to the standard mode items.
27 public class FreeTTSSynthesizerModeDesc extends SynthesizerModeDesc
28 implements EngineCreate {
31 * Creates a fully-specified descriptor.
32 * Any of the features may be <code>null</code>.
34 * @param engineName the name of the engine
35 * @param modeName the name of the mode
36 * @param locale the locale associated with this mode
38 public FreeTTSSynthesizerModeDesc( String engineName, String modeName,
40 super(engineName, modeName, locale, Boolean.FALSE, null);
44 * Returns the valid voices in this synthesizer mode.
46 * @return an array of valid voices, if no valid voices, it will
47 * return an array of size 0
49 public javax.speech.synthesis.Voice[] getVoices() {
50 List voiceList = new LinkedList();
51 javax.speech.synthesis.Voice[] voices = super.getVoices();
53 for (int i = 0; i < voices.length; i++) {
54 FreeTTSVoice freettsVoice = (FreeTTSVoice) voices[i];
56 freettsVoice.validate();
57 voiceList.add(freettsVoice);
59 } catch (ValidationException ve) {
60 // don't do anything here if a FreeTTSVoice is invalid
63 javax.speech.synthesis.Voice[] validVoices =
64 new javax.speech.synthesis.Voice[count];
65 voiceList.toArray(validVoices);
71 * Returns true if this is a valid FreeTTSSynthesizerModeDesc.
72 * It is valid if it contains at least one valid Voice.
73 * Returns false otherwise.
75 * @throws ValidationException if this FreeTTSSynthesizerModeDesc
78 public void validate() throws ValidationException {
79 javax.speech.synthesis.Voice[] voices = super.getVoices();
81 String validationMessage = "";
83 for (int i = 0; i < voices.length; i++) {
85 ((FreeTTSVoice) voices[i]).validate();
86 } catch (ValidationException ve) {
88 validationMessage += (ve.getMessage() + "\n");
91 if (invalidCount == voices.length) {
92 throw new ValidationException
93 (validationMessage + getModeName() + " has no valid voices.");
98 * Constructs a FreeTTSSynthesizer with the properties of this mode
101 * @return a synthesizer that mathes the mode
103 * @throws IllegalArgumentException if the properties of this
104 * descriptor do not match any known engine or mode
105 * @throws EngineException if the engine could not be created
106 * @throws SecurityException if the caller does not have
107 * permission to use the speech engine
109 public Engine createEngine()
110 throws IllegalArgumentException, EngineException, SecurityException {
111 FreeTTSSynthesizer s = new FreeTTSSynthesizer(this);