Element segment = (Element) segments.item(i); int factor = 100; int klatt0 = klattRule0(segment); int klatt2 = klattRule2(segment); int klatt2a = klattRule2a(segment); int klatt3 = klattRule3(segment); int klatt4 = klattRule4(segment); int klatt5 = klattRule5(segment); int klatt6 = klattRule6(segment); int klatt7 = klattRule7(segment); int klatt8 = klattRule8(segment); int klatt10 = klattRule10(segment); int accentProminence = accentProminenceRule(segment); factor = (factor * klatt0) / 100; factor = (factor * klatt2) / 100; int inhDuration = getInhDuration(segment); int minDuration = getMinDuration(segment); int normalDuration = minDuration + ((inhDuration - minDuration) * factor) / 100; int tempo = tempoRule(segment); int duration = (normalDuration * tempo) / 100; Element boundary = (Element) boundaries.item(i); if (!boundary.hasAttribute("duration")) { int duration = klattRule1(boundary); boundary.setAttribute("duration", String.valueOf(duration)); calculateAccumulatedDurations(sentence);
public MaryData process(MaryData d) throws Exception { Document doc = d.getDocument(); determineProsodicSettings(doc); addOrDeleteBoundaries(doc); NodeList sentences = doc.getElementsByTagName(MaryXML.SENTENCE); for (int i = 0; i < sentences.getLength(); i++) { Element sentence = (Element) sentences.item(i); processSentence(sentence); } MaryData result = new MaryData(outputType(), d.getLocale()); result.setDocument(doc); return result; }
int breakindex = getBreakindex(boundary); if (breakindex >= 1 && breakindex <= 6) { int durationMeasure = 100; return getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".medium"); } else { if (durationMeasure > 120) { longer = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".verylong"); shorter = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".long"); dist = durationMeasure - 120; } else { longer = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".long"); shorter = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".medium"); dist = durationMeasure - 100; if (durationMeasure < 80) { longer = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".short"); shorter = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".veryshort"); dist = durationMeasure - 60; } else { longer = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".medium"); shorter = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".short"); dist = durationMeasure - 80;
/** * Klatt Rule 10: Shortening in consonant clusters * * @return A percentage value as a factor for duration (100 corresponds to no change). */ private int klattRule10(Element segment) { boolean hasPrecedingConsonant = false; boolean hasFollowingConsonant = false; if (isConsonant(segment)) { Element preceding = getPreviousSegment(segment); if (preceding != null && isConsonant(preceding)) { hasPrecedingConsonant = true; } Element following = getNextSegment(segment); if (following != null && isConsonant(following)) { hasFollowingConsonant = true; } if (hasPrecedingConsonant && hasFollowingConsonant) { return getPropertyAsInteger("rule10.surrounded"); } else if (hasPrecedingConsonant) { return getPropertyAsInteger("rule10.preceded"); } else if (hasFollowingConsonant) { return getPropertyAsInteger("rule10.followed"); } } // default: Rule not applicable return 100; }
/** * For a string containing a percentage delta as judged by <code>isPercentageDelta()</code>, return the numerical value, * rounded to an integer. * * @return the numeric part of the percentage, rounded to an integer, or 0 if the string is not a valid percentage delta. */ private int getPercentageDelta(String string) { String s = string.trim(); if (!isPercentageDelta(s)) return 0; return getNumberDelta(s.substring(0, s.length() - 1)); }
settings.setRate(parentSettings.rate() + getPercentageDelta(prosody.getAttribute("rate"))); settings.setAccentProminence(parentSettings.accentProminence() + getPercentageDelta(prosody.getAttribute("accent-prominence"))); settings.setAccentSlope(parentSettings.accentSlope() + getPercentageDelta(prosody.getAttribute("accent-slope"))); settings.setNumberOfPauses(parentSettings.numberOfPauses() + getPercentageDelta(prosody.getAttribute("number-of-pauses"))); settings.setPauseDuration(parentSettings.pauseDuration() + getPercentageDelta(prosody.getAttribute("pause-duration"))); settings.setVowelDuration(parentSettings.vowelDuration() + getPercentageDelta(prosody.getAttribute("vowel-duration"))); settings.setPlosiveDuration(parentSettings.plosiveDuration() + getPercentageDelta(prosody.getAttribute("plosive-duration"))); settings.setFricativeDuration(parentSettings.fricativeDuration() + getPercentageDelta(prosody.getAttribute("fricative-duration"))); settings.setNasalDuration(parentSettings.nasalDuration() + getPercentageDelta(prosody.getAttribute("nasal-duration"))); settings.setLiquidDuration(parentSettings.liquidDuration() + getPercentageDelta(prosody.getAttribute("liquid-duration"))); settings.setGlideDuration(parentSettings.glideDuration() + getPercentageDelta(prosody.getAttribute("glide-duration"))); } else if (isPercentageDelta(sVolume)) { int newVolume = parentSettings.volume() + getPercentageDelta(sVolume); if (newVolume < 0) newVolume = 0; newVolume = 100; settings.setVolume(newVolume); } else if (isUnsignedNumber(sVolume)) { settings.setVolume(getUnsignedNumber(sVolume)); } else if (sVolume.equals("silent")) { settings.setVolume(0);
/** * Search for boundary and syllable elements following the given syllable. If the next matching element found is a boundary * with breakindex <code>minBreakindex</code> or larger, return true; otherwise, return false. If there is no next node, * return true. */ private boolean isLastBeforeBoundary(Element syllable, int minBreakindex) { Document doc = syllable.getOwnerDocument(); Element sentence = (Element) MaryDomUtils.getAncestor(syllable, MaryXML.SENTENCE); TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(sentence, NodeFilter.SHOW_ELEMENT, new NameNodeFilter( new String[] { MaryXML.SYLLABLE, MaryXML.BOUNDARY }), false); tw.setCurrentNode(syllable); Element next = (Element) tw.nextNode(); if (next == null) { // no matching node after syllable -- // we must be in a final position. return true; } if (next.getNodeName().equals(MaryXML.BOUNDARY)) { if (getBreakindex(next) >= minBreakindex) return true; } // This syllable is either followed by another syllable or // by a boundary with breakindex < minBreakindex return false; }
/** * Klatt Rule 10: Shortening in consonant clusters * * @return A percentage value as a factor for duration (100 corresponds to no change). */ private int klattRule10(Element segment) { boolean hasPrecedingConsonant = false; boolean hasFollowingConsonant = false; if (isConsonant(segment)) { Element preceding = getPreviousSegment(segment); if (preceding != null && isConsonant(preceding)) { hasPrecedingConsonant = true; } Element following = getNextSegment(segment); if (following != null && isConsonant(following)) { hasFollowingConsonant = true; } if (hasPrecedingConsonant && hasFollowingConsonant) { return getPropertyAsInteger("rule10.surrounded"); } else if (hasPrecedingConsonant) { return getPropertyAsInteger("rule10.preceded"); } else if (hasFollowingConsonant) { return getPropertyAsInteger("rule10.followed"); } } // default: Rule not applicable return 100; }
settings.setRate(parentSettings.rate() + getPercentageDelta(prosody.getAttribute("rate"))); settings.setAccentProminence(parentSettings.accentProminence() + getPercentageDelta(prosody.getAttribute("accent-prominence"))); settings.setAccentSlope(parentSettings.accentSlope() + getPercentageDelta(prosody.getAttribute("accent-slope"))); settings.setNumberOfPauses(parentSettings.numberOfPauses() + getPercentageDelta(prosody.getAttribute("number-of-pauses"))); settings.setPauseDuration(parentSettings.pauseDuration() + getPercentageDelta(prosody.getAttribute("pause-duration"))); settings.setVowelDuration(parentSettings.vowelDuration() + getPercentageDelta(prosody.getAttribute("vowel-duration"))); settings.setPlosiveDuration(parentSettings.plosiveDuration() + getPercentageDelta(prosody.getAttribute("plosive-duration"))); settings.setFricativeDuration(parentSettings.fricativeDuration() + getPercentageDelta(prosody.getAttribute("fricative-duration"))); settings.setNasalDuration(parentSettings.nasalDuration() + getPercentageDelta(prosody.getAttribute("nasal-duration"))); settings.setLiquidDuration(parentSettings.liquidDuration() + getPercentageDelta(prosody.getAttribute("liquid-duration"))); settings.setGlideDuration(parentSettings.glideDuration() + getPercentageDelta(prosody.getAttribute("glide-duration"))); } else if (isPercentageDelta(sVolume)) { int newVolume = parentSettings.volume() + getPercentageDelta(sVolume); if (newVolume < 0) newVolume = 0; newVolume = 100; settings.setVolume(newVolume); } else if (isUnsignedNumber(sVolume)) { settings.setVolume(getUnsignedNumber(sVolume)); } else if (sVolume.equals("silent")) { settings.setVolume(0);
/** * For a string containing a percentage delta as judged by <code>isPercentageDelta()</code>, return the numerical value, * rounded to an integer. * * @return the numeric part of the percentage, rounded to an integer, or 0 if the string is not a valid percentage delta. */ private int getPercentageDelta(String string) { String s = string.trim(); if (!isPercentageDelta(s)) return 0; return getNumberDelta(s.substring(0, s.length() - 1)); }
/** * Search for boundary and syllable elements following the given syllable. If the next matching element found is a boundary * with breakindex <code>minBreakindex</code> or larger, return true; otherwise, return false. If there is no next node, * return true. */ private boolean isLastBeforeBoundary(Element syllable, int minBreakindex) { Document doc = syllable.getOwnerDocument(); Element sentence = (Element) MaryDomUtils.getAncestor(syllable, MaryXML.SENTENCE); TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(sentence, NodeFilter.SHOW_ELEMENT, new NameNodeFilter( new String[] { MaryXML.SYLLABLE, MaryXML.BOUNDARY }), false); tw.setCurrentNode(syllable); Element next = (Element) tw.nextNode(); if (next == null) { // no matching node after syllable -- // we must be in a final position. return true; } if (next.getNodeName().equals(MaryXML.BOUNDARY)) { if (getBreakindex(next) >= minBreakindex) return true; } // This syllable is either followed by another syllable or // by a boundary with breakindex < minBreakindex return false; }
Element segment = (Element) segments.item(i); int factor = 100; int klatt0 = klattRule0(segment); int klatt2 = klattRule2(segment); int klatt2a = klattRule2a(segment); int klatt3 = klattRule3(segment); int klatt4 = klattRule4(segment); int klatt5 = klattRule5(segment); int klatt6 = klattRule6(segment); int klatt7 = klattRule7(segment); int klatt8 = klattRule8(segment); int klatt10 = klattRule10(segment); int accentProminence = accentProminenceRule(segment); factor = (factor * klatt0) / 100; factor = (factor * klatt2) / 100; int inhDuration = getInhDuration(segment); int minDuration = getMinDuration(segment); int normalDuration = minDuration + ((inhDuration - minDuration) * factor) / 100; int tempo = tempoRule(segment); int duration = (normalDuration * tempo) / 100; Element boundary = (Element) boundaries.item(i); if (!boundary.hasAttribute("duration")) { int duration = klattRule1(boundary); boundary.setAttribute("duration", String.valueOf(duration)); calculateAccumulatedDurations(sentence);
public MaryData process(MaryData d) throws Exception { Document doc = d.getDocument(); determineProsodicSettings(doc); addOrDeleteBoundaries(doc); NodeList sentences = doc.getElementsByTagName(MaryXML.SENTENCE); for (int i = 0; i < sentences.getLength(); i++) { Element sentence = (Element) sentences.item(i); processSentence(sentence); } MaryData result = new MaryData(outputType(), d.getLocale()); result.setDocument(doc); return result; }
/** * Klatt Rule 10: Shortening in consonant clusters * * @return A percentage value as a factor for duration (100 corresponds to no change). */ private int klattRule10(Element segment) { boolean hasPrecedingConsonant = false; boolean hasFollowingConsonant = false; if (isConsonant(segment)) { Element preceding = getPreviousSegment(segment); if (preceding != null && isConsonant(preceding)) { hasPrecedingConsonant = true; } Element following = getNextSegment(segment); if (following != null && isConsonant(following)) { hasFollowingConsonant = true; } if (hasPrecedingConsonant && hasFollowingConsonant) { return getPropertyAsInteger("rule10.surrounded"); } else if (hasPrecedingConsonant) { return getPropertyAsInteger("rule10.preceded"); } else if (hasFollowingConsonant) { return getPropertyAsInteger("rule10.followed"); } } // default: Rule not applicable return 100; }
settings.setRate(parentSettings.rate() + getPercentageDelta(prosody.getAttribute("rate"))); settings.setAccentProminence(parentSettings.accentProminence() + getPercentageDelta(prosody.getAttribute("accent-prominence"))); settings.setAccentSlope(parentSettings.accentSlope() + getPercentageDelta(prosody.getAttribute("accent-slope"))); settings.setNumberOfPauses(parentSettings.numberOfPauses() + getPercentageDelta(prosody.getAttribute("number-of-pauses"))); settings.setPauseDuration(parentSettings.pauseDuration() + getPercentageDelta(prosody.getAttribute("pause-duration"))); settings.setVowelDuration(parentSettings.vowelDuration() + getPercentageDelta(prosody.getAttribute("vowel-duration"))); settings.setPlosiveDuration(parentSettings.plosiveDuration() + getPercentageDelta(prosody.getAttribute("plosive-duration"))); settings.setFricativeDuration(parentSettings.fricativeDuration() + getPercentageDelta(prosody.getAttribute("fricative-duration"))); settings.setNasalDuration(parentSettings.nasalDuration() + getPercentageDelta(prosody.getAttribute("nasal-duration"))); settings.setLiquidDuration(parentSettings.liquidDuration() + getPercentageDelta(prosody.getAttribute("liquid-duration"))); settings.setGlideDuration(parentSettings.glideDuration() + getPercentageDelta(prosody.getAttribute("glide-duration"))); } else if (isPercentageDelta(sVolume)) { int newVolume = parentSettings.volume() + getPercentageDelta(sVolume); if (newVolume < 0) newVolume = 0; newVolume = 100; settings.setVolume(newVolume); } else if (isUnsignedNumber(sVolume)) { settings.setVolume(getUnsignedNumber(sVolume)); } else if (sVolume.equals("silent")) { settings.setVolume(0);
/** * For a string containing a percentage delta as judged by <code>isPercentageDelta()</code>, return the numerical value, * rounded to an integer. * * @return the numeric part of the percentage, rounded to an integer, or 0 if the string is not a valid percentage delta. */ private int getPercentageDelta(String string) { String s = string.trim(); if (!isPercentageDelta(s)) return 0; return getNumberDelta(s.substring(0, s.length() - 1)); }
int breakindex = getBreakindex(boundary); if (breakindex >= 1 && breakindex <= 6) { int durationMeasure = 100; return getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".medium"); } else { if (durationMeasure > 120) { longer = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".verylong"); shorter = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".long"); dist = durationMeasure - 120; } else { longer = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".long"); shorter = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".medium"); dist = durationMeasure - 100; if (durationMeasure < 80) { longer = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".short"); shorter = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".veryshort"); dist = durationMeasure - 60; } else { longer = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".medium"); shorter = getPropertyAsInteger("rule1.bi" + String.valueOf(breakindex) + ".short"); dist = durationMeasure - 80;
/** * Search for boundary and syllable elements following the given syllable. If the next matching element found is a boundary * with breakindex <code>minBreakindex</code> or larger, return true; otherwise, return false. If there is no next node, * return true. */ private boolean isLastBeforeBoundary(Element syllable, int minBreakindex) { Document doc = syllable.getOwnerDocument(); Element sentence = (Element) MaryDomUtils.getAncestor(syllable, MaryXML.SENTENCE); TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(sentence, NodeFilter.SHOW_ELEMENT, new NameNodeFilter( new String[] { MaryXML.SYLLABLE, MaryXML.BOUNDARY }), false); tw.setCurrentNode(syllable); Element next = (Element) tw.nextNode(); if (next == null) { // no matching node after syllable -- // we must be in a final position. return true; } if (next.getNodeName().equals(MaryXML.BOUNDARY)) { if (getBreakindex(next) >= minBreakindex) return true; } // This syllable is either followed by another syllable or // by a boundary with breakindex < minBreakindex return false; }
Element segment = (Element) segments.item(i); int factor = 100; int klatt0 = klattRule0(segment); int klatt2 = klattRule2(segment); int klatt2a = klattRule2a(segment); int klatt3 = klattRule3(segment); int klatt4 = klattRule4(segment); int klatt5 = klattRule5(segment); int klatt6 = klattRule6(segment); int klatt7 = klattRule7(segment); int klatt8 = klattRule8(segment); int klatt10 = klattRule10(segment); int accentProminence = accentProminenceRule(segment); factor = (factor * klatt0) / 100; factor = (factor * klatt2) / 100; int inhDuration = getInhDuration(segment); int minDuration = getMinDuration(segment); int normalDuration = minDuration + ((inhDuration - minDuration) * factor) / 100; int tempo = tempoRule(segment); int duration = (normalDuration * tempo) / 100; Element boundary = (Element) boundaries.item(i); if (!boundary.hasAttribute("duration")) { int duration = klattRule1(boundary); boundary.setAttribute("duration", String.valueOf(duration)); calculateAccumulatedDurations(sentence);
public MaryData process(MaryData d) throws Exception { Document doc = d.getDocument(); determineProsodicSettings(doc); addOrDeleteBoundaries(doc); NodeList sentences = doc.getElementsByTagName(MaryXML.SENTENCE); for (int i = 0; i < sentences.getLength(); i++) { Element sentence = (Element) sentences.item(i); processSentence(sentence); } MaryData result = new MaryData(outputType(), d.getLocale()); result.setDocument(doc); return result; }