upstream version 1.2.2
[debian/freetts] / com / sun / speech / freetts / cart / Intonator.java
1 /**
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.
6  * 
7  * See the file "license.terms" for information on usage and
8  * redistribution of this file, and for a DISCLAIMER OF ALL 
9  * WARRANTIES.
10  */
11 package com.sun.speech.freetts.cart;
12
13 import com.sun.speech.freetts.Item;
14 import com.sun.speech.freetts.ProcessException;
15 import com.sun.speech.freetts.Relation;
16 import com.sun.speech.freetts.Utterance;
17 import com.sun.speech.freetts.UtteranceProcessor;
18
19 /**
20  * Annotates the <code>Relation.SYLLABLE</code> relations of an
21  * utterance with "accent"
22  * and "endtone" features.  Though not required, a typical use of
23  * this is to use the ToBI (tones and break indeces) scheme for
24  * transcribing intonation and accent in English, developed by Janet
25  * Pierrehumbert and Mary Beckman.  This implementation is independent
26  * of the ToBI scheme:  ToBI annotations are not
27  * used by this class, but are merely copied from the CART result
28  * to the "accent" and "endtone" features of the
29  * <code>Relation.SYLLABLE</code> relation.
30  */
31 public class Intonator implements UtteranceProcessor {
32
33     /**
34      * The accent CART used for this Intonation UtteranceProcessor.  It is
35      * passed into the constructor.
36      */
37     protected CART accentCart;
38     
39     /**
40      * The tone CART used for this Intonation UtteranceProcessor.  It is
41      * passed into the constructor.
42      */
43     protected CART toneCart;
44     
45     /**
46      * Creates a new Intonation UtteranceProcessor with the given
47      * CARTs.
48      *
49      * @param accentCart the CART for doing accents
50      * @param toneCart the CART for doing end tones
51      */
52     public Intonator(CART accentCart, CART toneCart) {
53         this.accentCart = accentCart;
54         this.toneCart = toneCart;
55     }
56     
57     /**
58      * Annotates the <code>Relation.SYLLABLE</code> relations of an
59      * utterance with "accent"
60      * and "endtone" features.  Depends upon "NONE" being returned by
61      * either the accent or tone CART to indicate there isn't an
62      * intonation feature for a syllable.
63      *
64      * @param  utterance  the utterance to process/tokenize
65      *
66      * @throws ProcessException if an IOException is thrown during the
67      *         processing of the utterance
68      */
69     public void processUtterance(Utterance utterance) throws ProcessException {
70         String results;
71         for (Item syllable =
72                  utterance.getRelation(Relation.SYLLABLE).getHead();
73              syllable != null;
74              syllable = syllable.getNext()) {
75             results = (String) accentCart.interpret(syllable);
76             if (!results.equals("NONE")) {
77                 syllable.getFeatures().setString("accent", results);
78             }
79             results = (String) toneCart.interpret(syllable);
80             if (!results.equals("NONE")) {
81                 syllable.getFeatures().setString("endtone", results);
82             }
83         }
84     }
85
86     // inherited from Object
87     public String toString() {
88         return "CARTIntonator";
89     }
90 }