001/** 002 * Copyright 2002 DFKI GmbH. 003 * Portions Copyright 2002 Sun Microsystems, Inc. 004 * All Rights Reserved. Use is subject to license terms. 005 * 006 * See the file "license.terms" for information on usage and 007 * redistribution of this file, and for a DISCLAIMER OF ALL 008 * WARRANTIES. 009 */ 010 011package de.dfki.lt.freetts.en.us; 012 013import com.sun.speech.freetts.Validator; 014import com.sun.speech.freetts.ValidationException; 015import com.sun.speech.freetts.util.Utilities; 016 017import java.io.File; 018 019/** 020 * Shows this MbrolaVoice is valid (or usable). It tests for 021 * the following: 022 * 023 * <ol> 024 * <li> Check that the "mbrola.base" System property is defined, 025 * and that directory exists. 026 * <li> Check that the $(mbrola.base)/mbrola binary exists. 027 * <li> Check that the transition table exists. It is assumed 028 * to be at $(mbrola.base)/us1/us1mrpa. 029 * <li> Check that its voice database exists. 030 * </ol> 031 */ 032public class MbrolaVoiceValidator implements Validator { 033 034 private MbrolaVoice mbrolaVoice; 035 036 public MbrolaVoiceValidator(MbrolaVoice mbrolaVoice) { 037 this.mbrolaVoice = mbrolaVoice; 038 } 039 040 /** 041 * Validates this MbrolaVoice. 042 * 043 * @throws ValidationException if this MbrolaVoice is invalid 044 */ 045 public void validate() throws ValidationException { 046 String mbrolaBase = Utilities.getProperty("mbrola.base", null); 047 File mbrolaBinary = new File(mbrolaVoice.getMbrolaBinary()); 048 File mbrolaVoiceDB = new File(mbrolaVoice.getDatabase()); 049 050 if (mbrolaBase == null || mbrolaBase.length() == 0) { 051 throw new ValidationException 052 ("System property \"mbrola.base\" is undefined. " + 053 "You might need to set the MBROLA_DIR environment variable."); 054 } 055 if (!mbrolaBinary.exists()) { 056 throw new ValidationException 057 ("No MBROLA binary at: " + mbrolaVoice.getMbrolaBinary()); 058 } 059 if (!mbrolaVoiceDB.exists()) { 060 throw new ValidationException 061 ("No voice database for " + mbrolaVoice.getName() + 062 " at: " + mbrolaVoice.getDatabase()); 063 } 064 } 065 066 /** 067 * Returns the name of this validator. 068 * 069 * @return the name of this validator 070 */ 071 public String toString() { 072 return (mbrolaVoice.toString() + "Validator"); 073 } 074} 075