/**
  * If the given string ends with a consonant, insert a syllable boundary before that consonant.
  * Otherwise, append a syllable boundary.
  *
  * @param s input syllable
  * @return syllable with boundaries reset
  */
 private String rebuildTrans(String s) {
   AllophoneSet set = jphon.getAllophoneSet();
   if (set != null) {
     Allophone[] allophones = set.splitIntoAllophones(s);
     if (allophones != null && allophones.length > 0) {
       Allophone last = allophones[allophones.length - 1];
       if (last.isConsonant()) { // insert a syllable boundary before final consonant
         String lastPh = last.name();
         return s.substring(0, s.length() - lastPh.length()) + "-" + lastPh;
       }
     }
   }
   return s + "-";
 }
Beispiel #2
0
 /**
  * Converts an array of phone symbol strings into a single phone string. If stress is marked on
  * input phone symbols ("1" appended), a crude syllabification is done on the phone string.
  */
 public String phoneArray2phoneString(AllophoneSet allophoneSet, String[] voicePhones) {
   StringBuilder phoneBuf = new StringBuilder();
   for (int i = 0; i < voicePhones.length; i++) {
     phoneBuf.append(voicePhones[i]);
   }
   Syllabifier syllabifier = allophoneSet.getSyllabifier();
   return syllabifier.syllabify(phoneBuf.toString());
 }
Beispiel #3
0
 /**
  * Convenience method to access the allophone set referenced in the MARY property with the given
  * name.
  *
  * @param propertyName name of the property referring to the allophone set
  * @throws MaryConfigurationException if the allophone set cannot be obtained
  * @return the requested allophone set. This method will never return null; if it cannot get the
  *     allophone set, it throws an exception.
  */
 public static AllophoneSet needAllophoneSet(String propertyName)
     throws MaryConfigurationException {
   String propertyValue = MaryProperties.getProperty(propertyName);
   if (propertyValue == null) {
     throw new MaryConfigurationException("No such property: " + propertyName);
   }
   if (AllophoneSet.hasAllophoneSet(propertyValue)) {
     return AllophoneSet.getAllophoneSetById(propertyValue);
   }
   InputStream alloStream;
   try {
     alloStream = MaryProperties.needStream(propertyName);
   } catch (FileNotFoundException e) {
     throw new MaryConfigurationException(
         "Cannot open allophone stream for property " + propertyName, e);
   }
   assert alloStream != null;
   return AllophoneSet.getAllophoneSet(alloStream, propertyValue);
 }
  protected Map<String, List<String>> readLexiconStream(
      String lexiconFilename, InputStream lexiconStream) throws IOException {
    logger.debug(String.format("Reading lexicon from '%s'", lexiconFilename));
    String line;
    Map<String, List<String>> fLexicon = new HashMap<String, List<String>>();

    BufferedReader lexiconFile = new BufferedReader(new InputStreamReader(lexiconStream, "UTF-8"));
    while ((line = lexiconFile.readLine()) != null) {
      // Ignore empty lines and comments:
      if (line.trim().equals("") || line.startsWith("#")) continue;

      String[] lineParts = line.split("\\s*\\|\\s*");
      String graphStr = lineParts[0];
      String phonStr = null;
      try {
        phonStr = lineParts[1];
      } catch (ArrayIndexOutOfBoundsException e) {
        logger.warn(
            String.format(
                "Lexicon '%s': missing transcription for '%s'", lexiconFilename, graphStr));
        continue;
      }
      try {
        allophoneSet.splitIntoAllophones(phonStr);
      } catch (IllegalArgumentException e) {
        logger.warn(
            String.format(
                "Lexicon '%s': invalid entry for '%s': %s",
                lexiconFilename, graphStr, e.getMessage()));
        continue;
      }
      String phonPosStr = phonStr;
      if (lineParts.length > 2) {
        String pos = lineParts[2];
        if (!pos.trim().equals("")) phonPosStr += "|" + pos;
      }

      List<String> transcriptions = fLexicon.get(graphStr);
      if (null == transcriptions) {
        transcriptions = new ArrayList<String>();
        fLexicon.put(graphStr, transcriptions);
      }
      transcriptions.add(phonPosStr);
    }
    lexiconFile.close();
    return fLexicon;
  }