upstream version 1.2.2
[debian/freetts] / de / dfki / lt / freetts / en / us / MbrolaVoiceValidator.java
1 /**
2  * Copyright 2002 DFKI GmbH.
3  * Portions Copyright 2002 Sun Microsystems, Inc.
4  * All Rights Reserved.  Use is subject to license terms.
5  *
6  * See the file "license.terms" for information on usage and
7  * redistribution of this file, and for a DISCLAIMER OF ALL
8  * WARRANTIES.
9  */
10
11 package de.dfki.lt.freetts.en.us;
12
13 import com.sun.speech.freetts.Validator;
14 import com.sun.speech.freetts.ValidationException;
15 import com.sun.speech.freetts.util.Utilities;
16
17 import java.io.File;
18
19 /**
20  * Shows this MbrolaVoice is valid (or usable). It tests for 
21  * the following:
22  * 
23  * <ol>
24  * <li> Check that the "mbrola.base" System property is defined,
25  *      and that directory exists.
26  * <li> Check that the $(mbrola.base)/mbrola binary exists.
27  * <li> Check that the transition table exists. It is assumed 
28  *      to be at $(mbrola.base)/us1/us1mrpa.
29  * <li> Check that its voice database exists.
30  * </ol>
31  */
32 public class MbrolaVoiceValidator implements Validator {
33
34     private MbrolaVoice mbrolaVoice;
35
36     public MbrolaVoiceValidator(MbrolaVoice mbrolaVoice) {
37         this.mbrolaVoice = mbrolaVoice;
38     }
39
40     /**
41      * Validates this MbrolaVoice.
42      *
43      * @throws ValidationException if this MbrolaVoice is invalid
44      */
45     public void validate() throws ValidationException {
46         String mbrolaBase = Utilities.getProperty("mbrola.base", null);
47         File mbrolaBinary = new File(mbrolaVoice.getMbrolaBinary());
48         File mbrolaVoiceDB = new File(mbrolaVoice.getDatabase());
49
50         if (mbrolaBase == null || mbrolaBase.length() == 0) {
51             throw new ValidationException
52                 ("System property \"mbrola.base\" is undefined. " +
53                  "You might need to set the MBROLA_DIR environment variable.");
54         }
55         if (!mbrolaBinary.exists()) {
56             throw new ValidationException
57                 ("No MBROLA binary at: " + mbrolaVoice.getMbrolaBinary());
58         }
59         if (!mbrolaVoiceDB.exists()) {
60             throw new ValidationException
61                 ("No voice database for " + mbrolaVoice.getName() + 
62                  " at: " + mbrolaVoice.getDatabase());
63         }
64     }
65
66     /**
67      * Returns the name of this validator.
68      *
69      * @return the name of this validator
70      */
71     public String toString() {
72         return (mbrolaVoice.toString() + "Validator");
73     }
74 }
75