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.en;
13 import com.sun.speech.freetts.UtteranceProcessor;
14 import com.sun.speech.freetts.Utterance;
15 import com.sun.speech.freetts.FeatureSet;
16 import com.sun.speech.freetts.Item;
17 import com.sun.speech.freetts.Relation;
18 import com.sun.speech.freetts.PathExtractorImpl;
19 import com.sun.speech.freetts.PathExtractor;
20 import com.sun.speech.freetts.ProcessException;
21 import com.sun.speech.freetts.Voice;
22 import java.io.BufferedInputStream;
23 import java.io.InputStream;
24 import java.io.FileInputStream;
25 import java.io.IOException;
26 import java.util.List;
27 import java.util.LinkedList;
28 import java.util.Iterator;
32 * Annotates an utterance with pause information.
34 public class PauseGenerator implements UtteranceProcessor {
35 private final static PathExtractor segmentPath = new
36 PathExtractorImpl("R:SylStructure.daughtern.daughtern.R:Segment", false);
37 private final static PathExtractor puncPath =
38 new PathExtractorImpl("R:Token.parent.punc", true);
41 * Constructs a PauseGenerator
43 public PauseGenerator() {
47 * Annotates an utterance with pause information.
49 * @param utterance the utterance to process
51 * @throws ProcessException if an error occurs while
52 * processing of the utterance
54 public void processUtterance(Utterance utterance) throws ProcessException {
55 String silence = utterance.getVoice().getFeatures().
56 getString(Voice.FEATURE_SILENCE);
58 Item phraseHead = utterance.getRelation(Relation.PHRASE).getHead();
60 // If there are not any phrases at all, then just skip
63 if (phraseHead == null) {
67 // insert initial silence
68 Relation segment = utterance.getRelation(Relation.SEGMENT);
69 Item s = segment.getHead();
71 s = segment.appendItem(null);
73 s = s.prependItem(null);
75 s.getFeatures().setString("name", silence);
77 for (Item phrase = phraseHead;
79 phrase = phrase.getNext()) {
80 Item word = phrase.getLastDaughter();
81 while (word != null) {
82 Item seg = segmentPath.findItem(word);
83 // was this an explicit change or a lost bug fix
84 //if (seg != null && !"".equals(puncPath.findFeature(word))) {
86 Item pause = seg.appendItem(null);
87 pause.getFeatures().setString("name", silence);
90 word = word.getPrevious();
96 * Returns the string representation of the object
98 * @return the string representation of the object
100 public String toString() {
101 return "PauseGenerator";