/**
   * Converts a given text file into a audio file of WAVE format.
   *
   * @param inputFile The input file path. Cannot be null or empty.
   * @throws Exception
   */
  public void convertText2Audio(String inputFile) throws Exception {
    // Verify the file name
    if (StringUtils.isEmpty(inputFile)) {
      throw new IllegalArgumentException("Invalid file path");
    }

    LOGGER.debug("Starting conversion of file : " + inputFile);

    // Timing the conversion process
    long startTime = System.nanoTime();

    // TODO: This is very memory inefficient.
    String inputText = FileUtils.readFileToString(new File(inputFile));

    // Text to Audio format conversion
    ByteArrayOutputStream audioOutputStream = new ByteArrayOutputStream();
    MaryClient mary = MaryClient.getMaryClient(new Address(maryHostname, maryPort));
    mary.process(inputText, inputType, outputType, locale, audioType, voiceName, audioOutputStream);

    // The byte array constitutes a full wave file, including the header. Write the byte array to
    // file.
    FileOutputStream fileOut = new FileOutputStream(getOutputFile(inputFile));
    audioOutputStream.writeTo(fileOut);
    audioOutputStream.flush();
    fileOut.close();

    // Timing purpose
    long endTime = System.nanoTime();
    long duration = (endTime - startTime);
    LOGGER.info(
        "Conversion time for file : " + inputFile + " took " + duration / 1000000000.0 + " secs");
  }
 /** {@inheritDoc} It creates the MaryClient and starts the synthesisQueue thread. */
 @Override
 public void connect(final ConnectionInformation info) throws IOException {
   processor = MaryClient.getMaryClient();
   synthesisQueue = new SynthesisQueue(this);
   synthesisQueue.addListener(this);
   synthesisQueue.setProcessor(processor);
   synthesisQueue.setRequestParameters(maryRequestParameters);
   synthesisQueue.start();
 }
 public MaryClient getMaryClient() throws IOException {
   if (mary == null) {
     try {
       mary =
           MaryClient.getMaryClient(
               new Address(getProp(MARYSERVERHOST), Integer.parseInt(getProp(MARYSERVERPORT))));
     } catch (IOException e) {
       throw new IOException(
           "Could not connect to Maryserver at "
               + getProp(MARYSERVERHOST)
               + " "
               + getProp(MARYSERVERPORT));
     }
   }
   return mary;
 }