Пример #1
0
 /**
  * Read data from input stream <code>is</code>, in the appropriate way as determined by our <code>
  * type</code>.
  *
  * @param is the InputStream from which to read.
  * @param endMarker a string marking end of file. If this is null, read until end-of-file; if it
  *     is non-null, read up to (and including) the first line containing the end marker string.
  *     This will be ignored for audio data.
  * @throws ParserConfigurationException ParserConfigurationException
  * @throws SAXException SAXException
  * @throws IOException IOException
  * @throws TransformerConfigurationException TransformerConfigurationException
  * @throws TransformerException TransformerException
  */
 public void readFrom(InputStream is, String endMarker)
     throws ParserConfigurationException, SAXException, IOException,
         TransformerConfigurationException, TransformerException {
   if (type.isXMLType() || type.isTextType())
     readFrom(new InputStreamReader(is, "UTF-8"), endMarker);
   else { // audio
     // ignore endMarker
     setAudio((AudioInputStream) is);
   }
 }
Пример #2
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. "Helpers" needed
  * to read the data, such as XML parser objects, are created when they are needed. If doWarnClient
  * is set to true, warning and error messages related to XML parsing are logged to the log
  * category connected to the client from which this request originated.
  *
  * @param from the Reader from which to read.
  * @param endMarker a string marking end of file. If this is null, read until end-of-file; if it
  *     is non-null, read up to (and including) the first line containing the end marker string.
  * @throws ParserConfigurationException ParserConfigurationException
  * @throws SAXException SAXException
  * @throws IOException IOException
  */
 public void readFrom(Reader from, String endMarker)
     throws ParserConfigurationException, SAXException, IOException {
   // For the case that the data to be read it is not
   // followed by end-of-file, we use a ReaderSplitter which
   // provides a reader artificially "inserting" an end-of-file
   // after a line containing the pattern given in endMarker.
   Reader r = from;
   if (endMarker != null) {
     ReaderSplitter fromSplitter = new ReaderSplitter(from, endMarker);
     r = fromSplitter.nextReader();
   }
   readFrom(r);
 }
Пример #3
0
 /**
  * Read data from input stream <code>is</code>, in the appropriate way as determined by our <code>
  * type</code>.
  *
  * @param is is
  * @throws ParserConfigurationException ParserConfigurationException
  * @throws SAXException SAXException
  * @throws IOException IOException
  * @throws TransformerConfigurationException TransformerConfigurationException
  * @throws TransformerException TransformerException
  */
 public void readFrom(InputStream is)
     throws ParserConfigurationException, SAXException, IOException,
         TransformerConfigurationException, TransformerException {
   readFrom(is, null);
 }
  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);

  }