예제 #1
0
  private void loadFile(String basename) {
    try {
      File wavFile = new File(wavDir, basename + db.getProp(db.WAVEXT));
      if (!wavFile.exists())
        throw new IllegalArgumentException("File " + wavFile.getAbsolutePath() + " does not exist");
      File labFile = new File(phoneLabDir, basename + db.getProp(db.LABEXT));
      if (!labFile.exists())
        throw new IllegalArgumentException("File " + labFile.getAbsolutePath() + " does not exist");
      // pm file is optional
      File pmFile = new File(pmDir, basename + db.getProp(PMEXT));
      if (pmFile.exists()) {
        System.out.println("Loading pitchmarks file " + pmFile.getAbsolutePath());
        pitchmarks = new ESTTextfileDoubleDataSource(pmFile).getAllData();
      } else {
        System.out.println("Pitchmarks file " + pmFile.getAbsolutePath() + " does not exist");
        pitchmarks = null;
      }

      AudioInputStream ais = AudioSystem.getAudioInputStream(wavFile);
      audioFormat = ais.getFormat();
      samplingRate = (int) audioFormat.getSampleRate();
      audioSignal = new AudioDoubleDataSource(ais).getAllData();

      String file = FileUtils.getFileAsString(labFile, "ASCII");
      String[] lines = file.split("\n");
      labels.setListData(lines);

      saveFilename.setText(basename);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 /**
  * Files have to be text files with a *.txt extension.
  *
  * <p>TODO: BUG: FileUtils gets all .txt files from main and sub directories as well.
  *
  * @param directory
  * @return A set of file names.
  */
 private Set<String> getFiles(String directoryPath) {
   try {
     return Sets.newHashSet(marytts.util.io.FileUtils.getFileList(directoryPath, "txt"));
   } catch (NullPointerException e) {
     throw new IllegalArgumentException("Invalid directory path : " + directoryPath);
   }
 }
예제 #3
0
  /**
   * Converts file format from gv Mary format 4 to Mary 5, the converted file will have the same
   * input name
   *
   * @param gvInFile gvInFile
   * @throws IOException IOException
   */
  public void convertGvBinaryFile(File gvInFile) throws IOException {
    int i;
    String gvInFileString = gvInFile.getName();
    // the destination file name will be the same as the input file so
    String gvOutFile = gvInFile.getAbsolutePath();
    String path = gvInFile.getParent();
    // I make a copy or the original file
    FileUtils.copy(gvInFile.getAbsolutePath(), path + "/tmp");
    gvInFile = new File(path + "/tmp");

    DataInputStream dataIn;
    DataOutputStream dataOut;
    dataIn = new DataInputStream(new BufferedInputStream(new FileInputStream(gvInFile)));

    // int numMix = data_in.readShort(); /* --NOT USED -- first short is the number of mixtures in
    // Gaussian model */
    int order = dataIn.readShort(); /* second short is the order of static vector */
    float gvmean[] = new float[order]; /* allocate memory of this size */
    float gvcov[] = new float[order];
    logger.debug("Reading from file " + gvInFileString + " order=" + order);

    for (i = 0; i < order; i++) {
      gvmean[i] = dataIn.readFloat();
      // System.out.format("gvmean[%d]=%f\n",i,gvmean[i]);
    }
    for (i = 0; i < order; i++) {
      gvcov[i] = dataIn.readFloat();
      // System.out.format("gvcov[%d]=%f\n",i,gvcov[i]);
    }
    dataIn.close();

    dataOut = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(gvOutFile)));
    /* This is the format in version 2.0 */
    // numMSDFlag
    dataOut.writeInt(0);
    // numStream
    dataOut.writeInt(1);
    // vectorSize
    dataOut.writeInt(order);
    // numDurPdf
    dataOut.writeInt(1);

    for (i = 0; i < order; i++) {
      dataOut.writeFloat(gvmean[i]);
      dataOut.writeFloat(gvcov[i]);
    }

    dataOut.close();
    gvInFile.delete();
    logger.debug("Updated format in file " + gvOutFile);
  }
예제 #4
0
  /**
   * Converts format from pdf Mary format 4 to Mary 5, the converted file will have the same input
   * name
   *
   * @param pdfInFile pdfInFile
   * @throws Exception Exception
   */
  public void convertPdfBinaryFile(File pdfInFile) throws Exception {
    int i, j, k, l;
    boolean lf0 = false;

    String pdfInFileString = pdfInFile.getName();
    // the destination file name will be the same as the input file so
    String pdfOutFile = pdfInFile.getAbsolutePath();
    String path = pdfInFile.getParent();
    // I make a copy or the original file
    FileUtils.copy(pdfInFile.getAbsolutePath(), path + "/tmp");
    pdfInFile = new File(path + "/tmp");

    DataInputStream dataIn;
    DataOutputStream dataOut;

    dataIn = new DataInputStream(new BufferedInputStream(new FileInputStream(pdfInFile)));
    // numMSDFlag
    int numMSDFlag = 0;
    // numStream
    int numStream = 1; // 1 for mgc, str, mag or dur
    // vectorSize
    int vectorSize;
    // numDurPdf
    int numPdf[];

    logger.debug("Reading: from file " + pdfInFileString);
    float pdf[]; // pdf[vectorSize];
    float fval;
    int numState = 5;

    // ---------------------------------------------------------------------------------
    // ------------ Read header --------------------------------------------------------
    // ---------------------------------------------------------------------------------
    vectorSize = dataIn.readInt();
    if (pdfInFileString.contains("lf0.pdf")) {
      numStream = vectorSize;
      vectorSize =
          4; // vectorSize = 4 --> [1]:mean f0, [2]:var f0, [3]:voiced weight, [4]:unvoiced weight
      lf0 = true;
      numMSDFlag = 1;
    } else if (pdfInFileString.contains("dur.pdf")) {
      /* 2*nstate because the vector size for duration is the number of states */
      // pdf = new double[1][numDurPdf][1][2*numState]; // just one state and one stream
      numState = 1;
      numStream = 5;
    }
    logger.debug(
        "vectorSize(r) = "
            + vectorSize
            + " numMSDFlag="
            + numMSDFlag
            + " numStream="
            + numStream
            + " numState="
            + numState);

    /* Now we need the number of pdf's for each state */
    numPdf = new int[numState];
    for (i = 0; i < numState; i++) {
      numPdf[i] = dataIn.readInt();
      logger.debug("loadPdfs(r): numPdf[state:" + i + "]=" + numPdf[i]);
      if (numPdf[i] < 0)
        throw new Exception("loadPdfs: #pdf at state " + i + " must be positive value.");
    }
    pdf = new float[2 * vectorSize];

    dataOut = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(pdfOutFile)));
    // This is the format in version 2.0
    // numMSDFlag
    dataOut.writeInt(numMSDFlag);
    // numStream
    dataOut.writeInt(numStream);
    // vectorSize (for lf0 vectorsize is the same numStream)
    if (lf0) dataOut.writeInt(numStream);
    else dataOut.writeInt(vectorSize);
    // numPdf per state
    for (i = 0; i < numState; i++) {
      dataOut.writeInt(numPdf[i]);
    }

    // ---------------------------------------------------------------------------------
    // -------------- Now read the data ------------------------------------------------
    // in the old version the mean vector goes first and then the cov
    // in the new version the mean and cov elements of the vector are one after another
    // ---------------------------------------------------------------------------------
    if (lf0) {
      /* read pdfs (mean, variance). (2*vectorSize because mean and diag variance */
      /* are allocated in only one vector. */
      for (i = 0; i < numState; i++) {
        for (j = 0; j < numPdf[i]; j++) {
          for (k = 0; k < numStream; k++) {
            for (l = 0; l < vectorSize; l++) {
              fval = dataIn.readFloat();
              // NOTE: Here (hts_engine v1.04) the order seem to be the same as before
              dataOut.writeFloat(fval);
            }
          }
        }
        // System.out.println("New pdf  j=" + j);
      }
    } else {
      /* read pdfs (mean, variance). (2*vectorSize because mean and diag variance */
      /* are allocated in only one vector. */
      for (i = 0; i < numState; i++) {
        for (j = 0; j < numPdf[i]; j++) {
          for (k = 0; k < (2 * vectorSize); k++) {
            pdf[k] = dataIn.readFloat();
          }
          for (k = 0; k < vectorSize; k++) {
            dataOut.writeFloat(pdf[k]);
            dataOut.writeFloat(pdf[k + vectorSize]);
          }
        }
        // System.out.println("New pdf  j=" + j);
      }
    }
    dataIn.close();
    dataOut.close();
    pdfInFile.delete();
    logger.debug("Updated format in file " + pdfOutFile);
  }
예제 #5
0
  private void convert() throws Exception {
    logger.info("converting...");
    File rootDir = mary4Zip.getParentFile();
    extractedDir =
        new File(rootDir, voiceDescription.getName() + "-" + voiceDescription.getVersion());
    logger.debug("... extracting archive to " + extractedDir.getPath());
    if (extractedDir.exists()) {
      logger.debug("Folder " + extractedDir.getPath() + " exists, trying to delete...");
      extractedDir.delete();
    }
    FileUtils.unzipArchive(mary4Zip, extractedDir);

    loadConfig(findConfigFile());

    compileDir =
        new File(
            rootDir, voiceDescription.getName() + "-" + Version.specificationVersion() + "-maven");

    domain = config.getProperty(getPropertyPrefix() + "domain");
    samplingRate = Integer.parseInt(config.getProperty(getPropertyPrefix() + "samplingRate"));

    filesForResources = getFilesForResources();
    filesForFilesystem = getFilesForFilesystem();
    Map<String, String> extraVariablesToSubstitute = null;

    compiler =
        new VoiceCompiler.MavenVoiceCompiler(
            compileDir,
            getVoiceName(),
            Version.specificationVersion(),
            voiceDescription.getLocale(),
            voiceDescription.getGender(),
            domain,
            samplingRate,
            isUnitSelectionVoice(),
            filesForResources,
            filesForFilesystem,
            extraVariablesToSubstitute);

    logger.debug("Creating directories");
    compiler.createDirectories();

    logger.debug("Copying template files");
    compiler.copyTemplateFiles();

    updateConfig(compiler.getPackageName());
    saveConfig(compiler.getConfigFile());

    logger.debug("Copying voice files");
    compiler.copyVoiceFiles();

    if (!isUnitSelectionVoice()) {
      logger.debug("Converting HMM PDF files from Mary 4.0 to Mary 5.0 format");
      convertMary4ToMary5HmmPdfFiles(compiler.getMainResourcesDir());
    }

    logger.debug("Compiling with Maven");
    compiler.compileWithMaven();

    String convertedZipFilename = getFilenamePrefix() + ".zip";
    File convertedZipFile = new File(compileDir + "/target/" + convertedZipFilename);
    if (!convertedZipFile.exists()) {
      throw new IOException(
          "Maven should have created file "
              + convertedZipFile.getAbsolutePath()
              + " but file does not exist.");
    }

    updateVoiceDescription(rootDir, convertedZipFile);

    File finalZipFile = new File(rootDir, convertedZipFilename);
    if (finalZipFile.exists()) {
      finalZipFile.delete();
    }
    boolean success = convertedZipFile.renameTo(finalZipFile);
    if (!success) {
      throw new IOException(
          "Failure trying to move "
              + convertedZipFile.getAbsolutePath()
              + " to "
              + finalZipFile.getAbsolutePath());
    }
  }
예제 #6
0
 /**
  * Read data from reader <code>r</code> in the appropriate way as determined by our <code>type
  * </code>. Only XML and Text data can be read from a reader, audio data cannot.
  *
  * @param from from
  * @throws ParserConfigurationException ParserConfigurationException
  * @throws SAXException SAXException
  * @throws IOException IOException
  */
 public void readFrom(Reader from) throws ParserConfigurationException, SAXException, IOException {
   String inputData = FileUtils.getReaderAsString(from);
   setData(inputData);
 }
  // Pseudo harmonics based noise generation for pseudo periods
  public static double[] synthesize(
      HntmSpeechSignal hnmSignal,
      HntmAnalyzerParams analysisParams,
      HntmSynthesizerParams synthesisParams,
      String referenceFile) {
    double[] noisePart = null;
    int trackNoToExamine = 1;

    int i, k, n;
    double t; // Time in seconds

    double tsik = 0.0; // Synthesis time in seconds
    double tsikPlusOne = 0.0; // Synthesis time in seconds

    double trackStartInSeconds, trackEndInSeconds;
    // double lastPeriodInSeconds = 0.0;
    int trackStartIndex, trackEndIndex;
    double akt;
    int numHarmonicsCurrentFrame, numHarmonicsPrevFrame, numHarmonicsNextFrame;
    int harmonicIndexShiftPrev, harmonicIndexShiftCurrent, harmonicIndexShiftNext;
    int maxNumHarmonics = 0;
    for (i = 0; i < hnmSignal.frames.length; i++) {
      if (hnmSignal.frames[i].maximumFrequencyOfVoicingInHz > 0.0f
          && hnmSignal.frames[i].n != null) {
        numHarmonicsCurrentFrame =
            (int) Math.floor(hnmSignal.samplingRateInHz / analysisParams.noiseF0InHz + 0.5);
        numHarmonicsCurrentFrame = Math.max(0, numHarmonicsCurrentFrame);
        if (numHarmonicsCurrentFrame > maxNumHarmonics) maxNumHarmonics = numHarmonicsCurrentFrame;
      }
    }

    double aksi;
    double aksiPlusOne;

    float[] phasekis = null;
    float phasekiPlusOne;

    double ht;
    float phasekt = 0.0f;

    float phasekiEstimate = 0.0f;
    float phasekiPlusOneEstimate = 0.0f;
    int Mk;
    boolean isPrevNoised, isNoised, isNextNoised;
    boolean isTrackNoised, isNextTrackNoised, isPrevTrackNoised;
    int outputLen =
        SignalProcUtils.time2sample(
            hnmSignal.originalDurationInSeconds, hnmSignal.samplingRateInHz);

    noisePart =
        new double
            [outputLen]; // In fact, this should be prosody scaled length when you implement prosody
                         // modifications
    Arrays.fill(noisePart, 0.0);

    // Write separate tracks to output
    double[][] noiseTracks = null;

    if (maxNumHarmonics > 0) {
      noiseTracks = new double[maxNumHarmonics][];
      for (k = 0; k < maxNumHarmonics; k++) {
        noiseTracks[k] = new double[outputLen];
        Arrays.fill(noiseTracks[k], 0.0);
      }

      phasekis = new float[maxNumHarmonics];
      for (k = 0; k < maxNumHarmonics; k++)
        phasekis[k] = (float) (MathUtils.TWOPI * (Math.random() - 0.5));
    }
    //

    int transitionLen =
        SignalProcUtils.time2sample(
            synthesisParams.unvoicedVoicedTrackTransitionInSeconds, hnmSignal.samplingRateInHz);
    Window transitionWin = Window.get(Window.HAMMING, transitionLen * 2);
    transitionWin.normalizePeakValue(1.0f);
    double[] halfTransitionWinLeft = transitionWin.getCoeffsLeftHalf();
    float halfFs = hnmSignal.samplingRateInHz;

    for (i = 0; i < hnmSignal.frames.length; i++) {
      isPrevNoised = false;
      isNoised = false;
      isNextNoised = false;

      if (i > 0
          && hnmSignal.frames[i - 1].n != null
          && hnmSignal.frames[i - 1].maximumFrequencyOfVoicingInHz < halfFs
          && ((FrameNoisePartPseudoHarmonic) hnmSignal.frames[i - 1].n).ceps != null)
        isPrevNoised = true;

      if (i > 0
          && hnmSignal.frames[i].n != null
          && hnmSignal.frames[i].maximumFrequencyOfVoicingInHz < halfFs
          && ((FrameNoisePartPseudoHarmonic) hnmSignal.frames[i].n).ceps != null) isNoised = true;

      if (i < hnmSignal.frames.length - 1
          && hnmSignal.frames[i + 1].maximumFrequencyOfVoicingInHz < halfFs
          && hnmSignal.frames[i + 1].n != null
          && ((FrameNoisePartPseudoHarmonic) hnmSignal.frames[i + 1].n).ceps != null)
        isNextNoised = true;

      numHarmonicsPrevFrame = 0;
      numHarmonicsCurrentFrame = 0;
      numHarmonicsNextFrame = 0;
      harmonicIndexShiftPrev = 0;
      harmonicIndexShiftCurrent = 0;
      harmonicIndexShiftNext = 0;

      if (isPrevNoised) {
        numHarmonicsPrevFrame =
            (int)
                Math.floor(
                    (hnmSignal.samplingRateInHz
                                - hnmSignal.frames[i - 1].maximumFrequencyOfVoicingInHz)
                            / analysisParams.noiseF0InHz
                        + 0.5);
        numHarmonicsPrevFrame = Math.max(0, numHarmonicsPrevFrame);
        harmonicIndexShiftPrev =
            (int)
                Math.floor(
                    hnmSignal.frames[i - 1].maximumFrequencyOfVoicingInHz
                            / analysisParams.noiseF0InHz
                        + 0.5);
        harmonicIndexShiftPrev = Math.max(1, harmonicIndexShiftPrev);
      }

      if (isNoised) {
        numHarmonicsCurrentFrame =
            (int)
                Math.floor(
                    (hnmSignal.samplingRateInHz - hnmSignal.frames[i].maximumFrequencyOfVoicingInHz)
                            / analysisParams.noiseF0InHz
                        + 0.5);
        numHarmonicsCurrentFrame = Math.max(0, numHarmonicsCurrentFrame);
        harmonicIndexShiftCurrent =
            (int)
                Math.floor(
                    hnmSignal.frames[i].maximumFrequencyOfVoicingInHz / analysisParams.noiseF0InHz
                        + 0.5);
        harmonicIndexShiftCurrent = Math.max(1, harmonicIndexShiftCurrent);
      } else if (!isNoised && isNextNoised) {
        numHarmonicsCurrentFrame =
            (int)
                Math.floor(
                    (hnmSignal.samplingRateInHz
                                - hnmSignal.frames[i + 1].maximumFrequencyOfVoicingInHz)
                            / analysisParams.noiseF0InHz
                        + 0.5);
        numHarmonicsCurrentFrame = Math.max(0, numHarmonicsCurrentFrame);
        harmonicIndexShiftCurrent =
            (int)
                Math.floor(
                    hnmSignal.frames[i + 1].maximumFrequencyOfVoicingInHz
                            / analysisParams.noiseF0InHz
                        + 0.5);
        harmonicIndexShiftCurrent = Math.max(1, harmonicIndexShiftCurrent);
      }

      if (isNextNoised) {
        numHarmonicsNextFrame =
            (int)
                Math.floor(
                    (hnmSignal.samplingRateInHz
                                - hnmSignal.frames[i + 1].maximumFrequencyOfVoicingInHz)
                            / analysisParams.noiseF0InHz
                        + 0.5);
        numHarmonicsNextFrame = Math.max(0, numHarmonicsNextFrame);
        harmonicIndexShiftNext =
            (int)
                Math.floor(
                    hnmSignal.frames[i + 1].maximumFrequencyOfVoicingInHz
                            / analysisParams.noiseF0InHz
                        + 0.5);
        harmonicIndexShiftNext = Math.max(1, harmonicIndexShiftNext);
      }

      for (k = 0; k < numHarmonicsCurrentFrame; k++) {
        aksi = 0.0;
        aksiPlusOne = 0.0;

        phasekiPlusOne = 0.0f;

        isPrevTrackNoised = false;
        isTrackNoised = false;
        isNextTrackNoised = false;

        if (i > 0 && hnmSignal.frames[i - 1].n != null && numHarmonicsPrevFrame > k)
          isPrevTrackNoised = true;

        if (hnmSignal.frames[i].n != null && numHarmonicsCurrentFrame > k) isTrackNoised = true;

        if (i < hnmSignal.frames.length - 1
            && hnmSignal.frames[i + 1].n != null
            && numHarmonicsNextFrame > k) isNextTrackNoised = true;

        tsik = hnmSignal.frames[i].tAnalysisInSeconds;

        if (i == 0) trackStartInSeconds = 0.0;
        else trackStartInSeconds = tsik;

        if (i == hnmSignal.frames.length - 1) tsikPlusOne = hnmSignal.originalDurationInSeconds;
        else tsikPlusOne = hnmSignal.frames[i + 1].tAnalysisInSeconds;

        trackEndInSeconds = tsikPlusOne;

        trackStartIndex =
            SignalProcUtils.time2sample(trackStartInSeconds, hnmSignal.samplingRateInHz);
        trackEndIndex = SignalProcUtils.time2sample(trackEndInSeconds, hnmSignal.samplingRateInHz);

        if (isTrackNoised && trackEndIndex - trackStartIndex + 1 > 0) {
          // Amplitudes
          if (isTrackNoised) {
            if (!analysisParams.useNoiseAmplitudesDirectly) {
              if (analysisParams.regularizedCepstrumWarpingMethod
                  == RegularizedCepstrumEstimator.REGULARIZED_CEPSTRUM_WITH_PRE_BARK_WARPING)
                aksi =
                    RegularizedPreWarpedCepstrumEstimator.cepstrum2linearSpectrumValue(
                        ((FrameNoisePartPseudoHarmonic) hnmSignal.frames[i].n).ceps,
                        (k + harmonicIndexShiftCurrent) * analysisParams.noiseF0InHz,
                        hnmSignal.samplingRateInHz);
              else if (analysisParams.regularizedCepstrumWarpingMethod
                  == RegularizedCepstrumEstimator.REGULARIZED_CEPSTRUM_WITH_POST_MEL_WARPING)
                aksi =
                    RegularizedPostWarpedCepstrumEstimator.cepstrum2linearSpectrumValue(
                        ((FrameNoisePartPseudoHarmonic) hnmSignal.frames[i].n).ceps,
                        (k + harmonicIndexShiftCurrent) * analysisParams.noiseF0InHz,
                        hnmSignal.samplingRateInHz);
            } else {
              if (k < ((FrameNoisePartPseudoHarmonic) hnmSignal.frames[i].n).ceps.length)
                aksi =
                    ((FrameNoisePartPseudoHarmonic) hnmSignal.frames[i].n)
                        .ceps[k]; // Use amplitudes directly without cepstrum method
              else aksi = 0.0;
            }
          } else aksi = 0.0;

          if (isNextTrackNoised) {
            if (!analysisParams.useNoiseAmplitudesDirectly) {
              if (analysisParams.regularizedCepstrumWarpingMethod
                  == RegularizedCepstrumEstimator.REGULARIZED_CEPSTRUM_WITH_PRE_BARK_WARPING)
                aksiPlusOne =
                    RegularizedPreWarpedCepstrumEstimator.cepstrum2linearSpectrumValue(
                        ((FrameNoisePartPseudoHarmonic) hnmSignal.frames[i + 1].n).ceps,
                        (k + harmonicIndexShiftNext) * analysisParams.noiseF0InHz,
                        hnmSignal.samplingRateInHz);
              else if (analysisParams.regularizedCepstrumWarpingMethod
                  == RegularizedCepstrumEstimator.REGULARIZED_CEPSTRUM_WITH_POST_MEL_WARPING)
                aksiPlusOne =
                    RegularizedPostWarpedCepstrumEstimator.cepstrum2linearSpectrumValue(
                        ((FrameNoisePartPseudoHarmonic) hnmSignal.frames[i + 1].n).ceps,
                        (k + harmonicIndexShiftNext) * analysisParams.noiseF0InHz,
                        hnmSignal.samplingRateInHz);
            } else {
              if (k < ((FrameNoisePartPseudoHarmonic) hnmSignal.frames[i + 1].n).ceps.length)
                aksiPlusOne =
                    ((FrameNoisePartPseudoHarmonic) hnmSignal.frames[i + 1].n)
                        .ceps[k]; // Use amplitudes directly without cepstrum method
              else aksiPlusOne = 0.0;
            }
          } else aksiPlusOne = 0.0;
          //

          // Phases
          phasekis[k] = (float) (MathUtils.TWOPI * (Math.random() - 0.5));
          phasekiPlusOne =
              (float)
                  (phasekis[k]
                      + (k + harmonicIndexShiftCurrent)
                          * MathUtils.TWOPI
                          * analysisParams.noiseF0InHz
                          * (tsikPlusOne - tsik)); // Equation (3.55)
          //

          if (!isPrevTrackNoised) trackStartIndex = Math.max(0, trackStartIndex - transitionLen);

          for (n = trackStartIndex; n <= Math.min(trackEndIndex, outputLen - 1); n++) {
            t = SignalProcUtils.sample2time(n, hnmSignal.samplingRateInHz);

            // if (t>=tsik && t<tsikPlusOne)
            {
              // Amplitude estimate
              akt = MathUtils.interpolatedSample(tsik, t, tsikPlusOne, aksi, aksiPlusOne);
              //

              // Phase estimate
              phasekt = (float) (phasekiPlusOne * (t - tsik) / (tsikPlusOne - tsik));
              //

              if (!isPrevTrackNoised && n - trackStartIndex < transitionLen)
                noiseTracks[k][n] =
                    halfTransitionWinLeft[n - trackStartIndex] * akt * Math.cos(phasekt);
              else noiseTracks[k][n] = akt * Math.cos(phasekt);
            }
          }

          phasekis[k] = phasekiPlusOne;
        }
      }
    }

    for (k = 0; k < noiseTracks.length; k++) {
      for (n = 0; n < noisePart.length; n++) noisePart[n] += noiseTracks[k][n];
    }

    // Write separate tracks to output
    if (noiseTracks != null) {
      for (k = 0; k < noiseTracks.length; k++) {
        for (n = 0; n < noisePart.length; n++) noisePart[n] += noiseTracks[k][n];
      }

      if (referenceFile != null
          && FileUtils.exists(referenceFile)
          && synthesisParams.writeSeparateHarmonicTracksToOutputs) {
        // Write separate tracks to output
        AudioInputStream inputAudio = null;
        try {
          inputAudio = AudioSystem.getAudioInputStream(new File(referenceFile));
        } catch (UnsupportedAudioFileException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        if (inputAudio != null) {
          // k=1;
          for (k = 0; k < noiseTracks.length; k++) {
            noiseTracks[k] = MathUtils.divide(noiseTracks[k], 32767.0);

            DDSAudioInputStream outputAudio =
                new DDSAudioInputStream(
                    new BufferedDoubleDataSource(noiseTracks[k]), inputAudio.getFormat());
            String outFileName =
                StringUtils.getFolderName(referenceFile)
                    + "noiseTrack"
                    + String.valueOf(k + 1)
                    + ".wav";
            try {
              AudioSystem.write(outputAudio, AudioFileFormat.Type.WAVE, new File(outFileName));
            } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
        }
      }
      //
    }

    return noisePart;
  }
  public void computeFeaturesFor(String basename) throws IOException, Exception {
    String text;
    Locale localVoice;
    localVoice = MaryUtils.string2locale(locale);

    // First, test if there is a corresponding .rawmaryxml file in textdir:
    File rawmaryxmlFile =
        new File(db.getProp(db.MARYXMLDIR) + basename + db.getProp(db.MARYXMLEXT));
    if (rawmaryxmlFile.exists()) {
      text = FileUtils.getFileAsString(rawmaryxmlFile, "UTF-8");
    } else {
      text =
          getMaryXMLHeaderWithInitialBoundary(locale)
              + FileUtils.getFileAsString(
                  new File(db.getProp(db.TEXTDIR) + basename + db.getProp(db.TEXTEXT)), "UTF-8")
              + "</maryxml>";
    }
    File pfeatFile = new File(unitfeatureDir, basename + featsExt);
    OutputStream os = new BufferedOutputStream(new FileOutputStream(pfeatFile));
    MaryClient maryClient = getMaryClient();
    /*Vector voices = maryClient.getVoices(localVoice);
    MaryClient.Voice defaultVoice = (MaryClient.Voice) voices.firstElement();
    String voiceName = defaultVoice.name();*/
    // maryClient.process(text, maryInputType, maryOutputType, null, null, os);

    maryClient.process(text, maryInputType, maryOutputType, locale, null, "slt-arctic", os);
    // maryClient.process(text, maryInputType, maryOutputType, null, "slt-arctic", os, timeout);
    // maryClient.getOutputDataTypes().size()
    // MaryData result = new MaryData(os);

    os.flush();
    os.close();

    // System.out.println(" TO STRING: "+new FileReader(pfeatFile).toString());
    // BufferedReader bfr = new BufferedReader(new FileReader(pfeatFile));
    String line;
    MaryData d = new MaryData(MaryDataType.get("PHONEMISED_EN"), Locale.US);
    // d.readFrom(new ByteArrayInputStream(os.toByteArray()));
    d.readFrom(new FileReader(pfeatFile));

    // MaryData d = new MaryData(pfeatFile);
    Document doc = d.getDocument();
    // Document acoustparams = d.getDocument();

    // NodeIterator it = ((DocumentTraversal)acoustparams).createNodeIterator(acoustparams,
    // NodeFilter.SHOW_ELEMENT,new NameNodeFilter(new String[]{MaryXML.TOKEN,
    // MaryXML.BOUNDARY}),false);
    NodeIterator it =
        ((DocumentTraversal) doc)
            .createNodeIterator(
                doc, NodeFilter.SHOW_ELEMENT, new NameNodeFilter(MaryXML.TOKEN), false);

    Element t = null;
    while ((t = (Element) it.nextNode()) != null) {
      if (t.hasAttribute("g2p_method")) {
        String g2p = t.getAttribute("g2p_method");
        String nodeText = t.getTextContent().trim();
        if (g2p.equals("rules")) { // && nodeText.equals("!")){
          System.out.print(basename + " ----> " + nodeText);
          if (bnl.contains(basename)) bnl.remove(basename);
          System.out.println(" SO removing basename: " + basename);
        }

        // System.out.println("G2P:"+t.getAttribute("g2p_method"));
        // System.out.println("Text:"+t.getTextContent());
      }
    }

    /*while((line =bfr.readLine()) != null){
        //boolean b = m.matches();
        if(Pattern.matches("rules", line))
                System.out.println(basename + " LINE ---> " + line);

    }*/
    // System.out.println(" TO STRING: "+line);

  }