2 * Portions Copyright 2001 Sun Microsystems, Inc.
3 * Portions Copyright 1999-2001 Language Technologies Institute,
4 * Carnegie Mellon University.
5 * All Rights Reserved. Use is subject to license terms.
7 * See the file "license.terms" for information on usage and
8 * redistribution of this file, and for a DISCLAIMER OF ALL
11 package com.sun.speech.freetts.cart;
13 import com.sun.speech.freetts.Item;
14 import com.sun.speech.freetts.PathExtractor;
15 import com.sun.speech.freetts.PathExtractorImpl;
16 import com.sun.speech.freetts.PhoneDuration;
17 import com.sun.speech.freetts.PhoneDurations;
18 import com.sun.speech.freetts.ProcessException;
19 import com.sun.speech.freetts.Relation;
20 import com.sun.speech.freetts.Utterance;
21 import com.sun.speech.freetts.UtteranceProcessor;
24 * Determines duration timing for
25 * <code>Relation.SEGMENT</code> relations in an utterance.
26 * Annotates the <code>Relation.SEGMENT</code> relation with an
29 * <p>[[[TODO: The mean words-per-minute rate should become part
30 * of the CART data. For now, it is passed into the constructor.]]]
32 * @see Relation#SEGMENT
34 public class Durator implements UtteranceProcessor {
36 * The nominal speaking rate in words per minute. Set in the
39 private final float meanRate;
42 * The CART used for this duration UtteranceProcessor. It is
43 * passed into the constructor.
45 protected final CART cart;
48 * The PhoneDurations used for this duration UtteranceProcessor.
49 * It is passed into the constructor.
51 protected final PhoneDurations durations;
54 private static final PathExtractor DURATION_STRETCH_PATH =
55 new PathExtractorImpl(
56 "R:SylStructure.parent.parent.R:Token.parent.local_duration_stretch",
60 * Creates a new duration UtteranceProcessor with the given
61 * CART and phone durations.
63 * @param cart contains zscore duration data
64 * @param meanRate the mean words per minute rate of the CART data
65 * @param durations contains mean and standard deviation phone durations
67 public Durator(CART cart, float meanRate, PhoneDurations durations) {
69 this.meanRate = meanRate;
70 this.durations = durations;
74 * Annotates the <code>Relation.SEGMENT</code> relations with
75 * cumulative "end" time
76 * features based on phone durations. Expects the CART to return
77 * a zscore for each phone, which specifies the number of standard
78 * deviations from the mean. This is coupled with a phone
79 * durations table that returns the mean and standard deviation
82 * @param utterance the utterance to process
84 * @throws ProcessException if a problem is encountered during the
85 * processing of the utterance
87 public void processUtterance(Utterance utterance) throws ProcessException {
89 PhoneDuration durStat;
90 float durationStretch = utterance.getVoice().getDurationStretch();
94 float localDurationStretch;
96 // Figure out how far to stretch the durations (speed things
97 // up or slow them down.
100 durStretch = meanRate / utterance.getVoice().getRate();
102 // Go through each of the segments and calculate a duration
103 // for it. Store the cumulative end time for the duration in
104 // the "end" feature of the segment.
107 utterance.getRelation(Relation.SEGMENT).getHead();
108 segment != null; segment = segment.getNext()) {
109 zdur = ((Float) cart.interpret(segment)).floatValue();
110 durStat = durations.getPhoneDuration(
111 segment.getFeatures().getString("name"));
113 Object tval = DURATION_STRETCH_PATH.findFeature(segment);
114 localDurationStretch = Float.parseFloat(tval.toString());
116 if (localDurationStretch == 0.0) {
117 localDurationStretch = durationStretch;
119 localDurationStretch *= durationStretch;
122 dur = localDurationStretch * ((zdur*durStat.getStandardDeviation())
123 + durStat.getMean());
125 segment.getFeatures().setFloat("end", end);
129 // inherited from Object
130 public String toString() {
131 return "CARTDurator";