001/**
002 * Copyright 2001 Sun Microsystems, Inc.
003 * 
004 * See the file "license.terms" for information on usage and
005 * redistribution of this file, and for a DISCLAIMER OF ALL 
006 * WARRANTIES.
007 */
008package com.sun.speech.freetts;
009
010/**
011 * Provides a means to access the voices that are stored in a jar
012 * file.  Every jar file that provides a voice must contain a subclass
013 * of VoiceDirectory.  The class must provide a main() function that
014 * calls dumpVoices() or performs an equivalent operation.  All
015 * subclasses of VoiceDirectory can be assumed to always be created by
016 * the default constructor (no arguments).
017 *
018 * Any jar file that has a subclass of VoiceDirectory must define
019 * certain attributes in its Manifest.  "Main-class:" must refer to
020 * the subclass of VoiceDirectory. "Class-Path:" lists the other jar
021 * files upon which this is dependent.  For example,
022 * "cmu_us_kal.jar" may be dependent on "en_us.jar" for its lexicon.
023 * The Manifest must also have a "FreeTTSVoiceDefinition: true" entry.
024 *
025 * @see Voice
026 * @see VoiceManager
027 */
028public abstract class VoiceDirectory {
029    /**
030     * Default constructor does nothing.  This may be overridden by
031     * subclasses, but it is not recommended.  This is the only
032     * constructor that will be called.
033     */
034    public VoiceDirectory() {
035    }
036
037    /**
038     * Provide a means to access the voices in a voice jar file.  The
039     * implementation of this function is up to the subclasses.
040     *
041     * @return an array of Voice instances provided in the jar file
042     */
043    public abstract Voice[] getVoices();
044
045    /**
046     * Print the information about voices contained in this voice
047     * directory to a String.
048     *
049     * @return a String containing the information
050     *
051     * @see #main(String[] args)
052     */
053    public String toString() {
054        String newline = System.getProperty("line.separator");
055        Voice[] voices = getVoices();
056        StringBuilder s = new StringBuilder();
057        s.append("VoiceDirectory '");
058        s.append(this.getClass().getName());
059        s.append("'");
060        s.append(newline);
061
062        for (int i = 0; i < voices.length; i++) {
063            s.append(newline);
064            s.append("Name: ");
065            s.append(voices[i].getName());
066            s.append(newline);
067            s.append("\tDescription: ");
068            s.append(voices[i].getDescription());
069            s.append(newline);
070            s.append("\tOrganization: ");
071            s.append(voices[i].getOrganization());
072            s.append(newline);
073            s.append("\tDomain: ");
074            s.append(voices[i].getDomain());
075            s.append(newline);
076            s.append("\tLocale: ");
077            s.append(voices[i].getLocale().toString());
078            s.append(newline);
079            s.append("\tStyle: ");
080            s.append(voices[i].getStyle());
081            s.append(newline);
082            s.append("\tGender: ");
083            s.append(voices[i].getGender().toString());
084            s.append(newline);
085            s.append("\tAge: ");
086            s.append(voices[i].getAge().toString());
087            s.append(newline);
088            s.append("\tPitch: ");
089            s.append(voices[i].getPitch());
090            s.append(newline);
091            s.append("\tPitch Range: ");
092            s.append(voices[i].getPitchRange());
093            s.append(newline);
094            s.append("\tPitch Shift: ");
095            s.append(voices[i].getPitchShift());
096            s.append(newline);
097            s.append("\tRate: ");
098            s.append(voices[i].getRate());
099            s.append(newline);
100            s.append("\tVolume: ");
101            s.append(voices[i].getVolume());
102            s.append(newline);
103            s.append(newline);
104        }
105        return s.toString();
106    }
107
108    /**
109     * The main function must be implemented by subclasses to print
110     * out information about provided voices.  For example, they may
111     * just call dumpVoices()
112     *
113     * @see #toString()
114     */
115    public static void main(String[] args) {
116        // subclasses must call dumpVoices()
117    }
118}