예제 #1
0
  /**
   * Constructor providing the individual filenames of files that are required.
   *
   * @param allophonesFilename
   * @param userdictFilename
   * @param lexiconFilename
   * @param ltsFilename
   * @param removetrailingonefromphonesBoolean
   * @throws Exception
   */
  public JPhonemiser(
      String componentName,
      MaryDataType inputType,
      MaryDataType outputType,
      String allophonesProperty,
      String userdictProperty,
      String lexiconProperty,
      String ltsProperty,
      String removetrailingonefromphonesProperty)
      throws IOException, MaryConfigurationException {
    super(
        componentName,
        inputType,
        outputType,
        MaryRuntimeUtils.needAllophoneSet(allophonesProperty).getLocale());
    allophoneSet = MaryRuntimeUtils.needAllophoneSet(allophonesProperty);
    // userdict is optional
    String userdictFilename = MaryProperties.getFilename(userdictProperty); // may be null
    if (userdictFilename != null) {
      if (new File(userdictFilename).exists()) {
        userdict = readLexicon(userdictFilename);
      } else {
        logger.info(
            "User dictionary '"
                + userdictFilename
                + "' for locale '"
                + getLocale()
                + "' does not exist. Ignoring.");
      }
    }

    // HB 150915 Need to allow lexiconProperty to be a list. If lexicon is *fst, load as before, if
    // *dict, load like userlex
    // Lookup in the order of the lexiconProperty
    // First: keep lexicon the way it is, and add no.secondary_lexicon to no.config
    System.err.println("lexiconProperty: " + MaryProperties.getProperty(lexiconProperty));

    String secondary_lexiconFilename = MaryProperties.getProperty("da.secondary_lexicon");
    if (secondary_lexiconFilename != null) {
      System.err.println("Loading da.secondary_lexicon: " + secondary_lexiconFilename);
      secondary_lexicon =
          readLexiconStream(
              secondary_lexiconFilename, MaryProperties.needStream("da.secondary_lexicon"));
    }

    InputStream lexiconStream = MaryProperties.needStream(lexiconProperty);
    lexicon = new FSTLookup(lexiconStream, lexiconProperty);
    InputStream ltsStream = MaryProperties.needStream(ltsProperty);
    if (removetrailingonefromphonesProperty != null) {
      this.removeTrailingOneFromPhones =
          MaryProperties.getBoolean(removetrailingonefromphonesProperty, true);
    }
    lts = new TrainedLTS(allophoneSet, ltsStream, this.removeTrailingOneFromPhones);
  }
예제 #2
0
 /**
  * Initialise this join cost function by reading the appropriate settings from the MaryProperties
  * using the given configPrefix.
  *
  * @param configPrefix the prefix for the (voice-specific) config entries to use when looking up
  *     files to load.
  */
 public void init(String configPrefix) throws MaryConfigurationException {
   try {
     String joinFileName = MaryProperties.needFilename(configPrefix + ".joinCostFile");
     InputStream joinPdfStream = MaryProperties.needStream(configPrefix + ".joinPdfFile");
     InputStream joinTreeStream = MaryProperties.needStream(configPrefix + ".joinTreeFile");
     // CHECK not tested the trickyPhonesFile needs to be added into the configuration file
     String trickyPhonesFileName = MaryProperties.needFilename(configPrefix + ".trickyPhonesFile");
     load(joinFileName, joinPdfStream, joinTreeStream, trickyPhonesFileName);
   } catch (IOException ioe) {
     throw new MaryConfigurationException("Problem loading join file", ioe);
   }
 }
예제 #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);
 }