private void modifySpeechRate(NodeList nl,double percentage,boolean increaseSpeechRate){
  assert nl != null;
  for (int i=0; i < nl.getLength(); i++) {
    Element e=(Element)nl.item(i);
    assert "ph".equals(e.getNodeName()) : "NodeList should contain 'ph' elements only";
    if (!e.hasAttribute("d")) {
      continue;
    }
    double durAttribute=new Double(e.getAttribute("d")).doubleValue();
    double newDurAttribute;
    if (increaseSpeechRate) {
      newDurAttribute=durAttribute - (percentage * durAttribute / 100);
    }
 else {
      newDurAttribute=durAttribute + (percentage * durAttribute / 100);
    }
    e.setAttribute("d",newDurAttribute + "");
  }
  Element e=(Element)nl.item(0);
  Element rootElement=e.getOwnerDocument().getDocumentElement();
  NodeIterator nit=DomUtils.createNodeIterator(rootElement,MaryXML.PHONE,MaryXML.BOUNDARY);
  Element nd;
  double duration=0.0;
  for (int i=0; (nd=(Element)nit.nextNode()) != null; i++) {
    if ("boundary".equals(nd.getNodeName())) {
      if (nd.hasAttribute("duration")) {
        duration+=new Double(nd.getAttribute("duration")).doubleValue();
      }
    }
 else {
      if (nd.hasAttribute("d")) {
        duration+=new Double(nd.getAttribute("d")).doubleValue();
      }
    }
    double endTime=0.001 * duration;
    if (!nd.getNodeName().equals(MaryXML.BOUNDARY)) {
      nd.setAttribute("end",String.valueOf(endTime));
    }
  }
}

private void modifySpeechRate ( NodeList nl , double percentage , boolean increaseSpeechRate ) { assert nl != null ; for ( int i = 0 ; i < nl . getLength ( ) ; i ++ ) { Element e = ( Element ) nl . item ( i ) ; assert "ph" . equals ( e . getNodeName ( ) ) : "NodeList should contain 'ph' elements only" ; if ( ! e . hasAttribute ( "d" ) ) { continue ; } double durAttribute = new Double ( e . getAttribute ( "d" ) ) . doubleValue ( ) ; double newDurAttribute ; if ( increaseSpeechRate ) { newDurAttribute = durAttribute - ( percentage * durAttribute / 100 ) ; } else { newDurAttribute = durAttribute + ( percentage * durAttribute / 100 ) ; } e . setAttribute ( "d" , newDurAttribute + "" ) ; } Element e = ( Element ) nl . item ( 0 ) ; Element rootElement = e . getOwnerDocument ( ) . getDocumentElement ( ) ; NodeIterator nit = DomUtils . createNodeIterator ( rootElement , MaryXML . PHONE , MaryXML . BOUNDARY ) ; Element nd ; double duration = 0.0 ; for ( int i = 0 ; ( nd = ( Element ) nit . nextNode ( ) ) != null ; i ++ ) { if ( "boundary" . equals ( nd . getNodeName ( ) ) ) { if ( nd . hasAttribute ( "duration" ) ) { duration += new Double ( nd . getAttribute ( "duration" ) ) . doubleValue ( ) ; } } else { if ( nd . hasAttribute ( "d" ) ) { duration += new Double ( nd . getAttribute ( "d" ) ) . doubleValue ( ) ; } } double endTime = 0.001 * duration ; if ( ! nd . getNodeName ( ) . equals ( MaryXML . BOUNDARY ) ) { nd . setAttribute ( "end" , String . valueOf ( endTime ) ) ; } } }
to set duration specifications according to ' rate ' requirements
