예제 #1
0
 public Mary4To5VoiceConverter(List<VoiceComponentDescription> voiceDescriptions, File voiceZip) {
   voiceDescription = null;
   mary4Zip = voiceZip;
   for (VoiceComponentDescription d : voiceDescriptions) {
     if (d.getPackageFilename().equals(mary4Zip.getName())) {
       voiceDescription = d;
       break;
     }
   }
   if (voiceDescription == null) {
     throw new IllegalArgumentException(
         "No matching voice description for file " + mary4Zip.getName());
   }
   if (!MaryUtils.isLog4jConfigured()) {
     BasicConfigurator.configure();
   }
   logger = Logger.getLogger(this.getClass());
   logger.info(
       voiceDescription.getName()
           + " "
           + voiceDescription.getVersion()
           + " ("
           + voiceDescription.getLocale()
           + " "
           + voiceDescription.getGender()
           + ")");
 }
예제 #2
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());
    }
  }