001package de.dfki.lt.freetts.en.us; 002 003import java.util.List; 004import java.util.Locale; 005 006import com.sun.speech.freetts.Age; 007import com.sun.speech.freetts.Gender; 008import com.sun.speech.freetts.ValidationException; 009import com.sun.speech.freetts.Voice; 010import com.sun.speech.freetts.VoiceDirectory; 011import com.sun.speech.freetts.en.us.CMULexicon; 012import com.sun.speech.freetts.util.Utilities; 013 014/** 015 * Provides access to MBROLA voices. 016 */ 017public class MbrolaVoiceDirectory extends VoiceDirectory { 018 019 public Voice[] getVoices() { 020 021 String base = Utilities.getProperty("mbrola.base", null); 022 023 if (base == null || base.trim().length() == 0) { 024 System.out.println( 025 "System property \"mbrola.base\" is undefined. " 026 + "Will not use MBROLA voices."); 027 return new Voice[0]; 028 } else { 029 030 CMULexicon lexicon = new CMULexicon("cmulex"); 031 032 Voice mbrola1 = new MbrolaVoice 033 ("us1", "us1", 150f, 180F, 22F, 034 "mbrola_us1", Gender.FEMALE, Age.YOUNGER_ADULT, 035 "MBROLA Voice us1", 036 Locale.US, "general", "mbrola", lexicon); 037 038 Voice mbrola2 = new MbrolaVoice 039 ("us2", "us2", 150f, 115F, 12F, 040 "mbrola_us2", Gender.MALE, Age.YOUNGER_ADULT, 041 "MBROLA Voice us2", 042 Locale.US, "general", "mbrola", lexicon); 043 044 Voice mbrola3 = new MbrolaVoice 045 ("us3", "us3", 150f, 125F, 12F, 046 "mbrola_us3", Gender.MALE, Age.YOUNGER_ADULT, 047 "MBROLA Voice us3", 048 Locale.US, "general", "mbrola", lexicon); 049 050 Voice[] voices = {mbrola1, mbrola2, mbrola3}; 051 052 List validVoices = new java.util.ArrayList(); 053 int count = 0; 054 055 for (int i = 0; i < voices.length; i++) { 056 MbrolaVoiceValidator validator = 057 new MbrolaVoiceValidator((MbrolaVoice) voices[i]); 058 try { 059 validator.validate(); 060 validVoices.add(voices[i]); 061 count++; 062 } catch (ValidationException ve) { 063 // does nothing if the voice is not found 064 } 065 } 066 if (count == 0) { 067 System.err.println( 068 "\n" 069 + "Could not validate any MBROLA voices at\n\n" 070 + " " + base + "\n"); 071 if (base.indexOf('~') != -1) { 072 System.err.println( 073 "DO NOT USE ~ as part of the path name\n" 074 + "to specify the mbrola.base property."); 075 } 076 System.err.println( 077 "Make sure you FULLY specify the path to\n" 078 + "the MBROLA directory using the mbrola.base\n" 079 + "system property.\n"); 080 return new Voice[0]; 081 } else { 082 return ((Voice[])validVoices.toArray(new Voice[count])); 083 } 084 } 085 } 086 087 /** 088 * Prints out the MBROLA voices. 089 */ 090 public static void main(String[] args) { 091 System.out.println((new MbrolaVoiceDirectory()).toString()); 092 } 093} 094 095