コード例 #1
0
  @Override
  protected void loadFromByteBuffer(String fileName)
      throws IOException, MaryConfigurationException {
    /* Open the file */
    FileInputStream fis = new FileInputStream(fileName);
    FileChannel fc = fis.getChannel();
    ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
    fis.close();

    /* Load the Mary header */
    hdr = new MaryHeader(bb);
    if (hdr.getType() != MaryHeader.HALFPHONE_UNITFEATS) {
      throw new MaryConfigurationException(
          "File [" + fileName + "] is not a valid Mary Halfphone Features file.");
    }
    leftWeights = new FeatureDefinition(bb);
    rightWeights = new FeatureDefinition(bb);
    assert leftWeights.featureEquals(rightWeights)
        : "Halfphone unit feature file contains incompatible feature definitions for left and right units -- this should not happen!";
    featureDefinition = leftWeights; // one of them, for super class
    int numberOfUnits = bb.getInt();
    featureVectors = new FeatureVector[numberOfUnits];
    for (int i = 0; i < numberOfUnits; i++) {
      featureVectors[i] = featureDefinition.readFeatureVector(i, bb);
    }
  }
コード例 #2
0
 @Override
 protected void loadFromStream(String fileName) throws IOException, MaryConfigurationException {
   /* Open the file */
   DataInputStream dis = null;
   dis = new DataInputStream(new BufferedInputStream(new FileInputStream(fileName)));
   /* Load the Mary header */
   hdr = new MaryHeader(dis);
   if (hdr.getType() != MaryHeader.HALFPHONE_UNITFEATS) {
     throw new IOException("File [" + fileName + "] is not a valid Mary Halfphone Features file.");
   }
   leftWeights = new FeatureDefinition(dis);
   rightWeights = new FeatureDefinition(dis);
   assert leftWeights.featureEquals(rightWeights)
       : "Halfphone unit feature file contains incompatible feature definitions for left and right units -- this should not happen!";
   featureDefinition = leftWeights; // one of them, for super class
   int numberOfUnits = dis.readInt();
   featureVectors = new FeatureVector[numberOfUnits];
   for (int i = 0; i < numberOfUnits; i++) {
     featureVectors[i] = featureDefinition.readFeatureVector(i, dis);
   }
 }