001/** 002 * Portions Copyright 2001 Sun Microsystems, Inc. 003 * Portions Copyright 1999-2001 Language Technologies Institute, 004 * Carnegie Mellon University. 005 * All Rights Reserved. Use is subject to license terms. 006 * 007 * See the file "license.terms" for information on usage and 008 * redistribution of this file, and for a DISCLAIMER OF ALL 009 * WARRANTIES. 010 */ 011package com.sun.speech.freetts.cart; 012 013import com.sun.speech.freetts.Item; 014import com.sun.speech.freetts.ProcessException; 015import com.sun.speech.freetts.Relation; 016import com.sun.speech.freetts.Utterance; 017import com.sun.speech.freetts.UtteranceProcessor; 018 019/** 020 * Annotates the <code>Relation.SYLLABLE</code> relations of an 021 * utterance with "accent" 022 * and "endtone" features. Though not required, a typical use of 023 * this is to use the ToBI (tones and break indeces) scheme for 024 * transcribing intonation and accent in English, developed by Janet 025 * Pierrehumbert and Mary Beckman. This implementation is independent 026 * of the ToBI scheme: ToBI annotations are not 027 * used by this class, but are merely copied from the CART result 028 * to the "accent" and "endtone" features of the 029 * <code>Relation.SYLLABLE</code> relation. 030 */ 031public class Intonator implements UtteranceProcessor { 032 033 /** 034 * The accent CART used for this Intonation UtteranceProcessor. It is 035 * passed into the constructor. 036 */ 037 protected CART accentCart; 038 039 /** 040 * The tone CART used for this Intonation UtteranceProcessor. It is 041 * passed into the constructor. 042 */ 043 protected CART toneCart; 044 045 /** 046 * Creates a new Intonation UtteranceProcessor with the given 047 * CARTs. 048 * 049 * @param accentCart the CART for doing accents 050 * @param toneCart the CART for doing end tones 051 */ 052 public Intonator(CART accentCart, CART toneCart) { 053 this.accentCart = accentCart; 054 this.toneCart = toneCart; 055 } 056 057 /** 058 * Annotates the <code>Relation.SYLLABLE</code> relations of an 059 * utterance with "accent" 060 * and "endtone" features. Depends upon "NONE" being returned by 061 * either the accent or tone CART to indicate there isn't an 062 * intonation feature for a syllable. 063 * 064 * @param utterance the utterance to process/tokenize 065 * 066 * @throws ProcessException if an IOException is thrown during the 067 * processing of the utterance 068 */ 069 public void processUtterance(Utterance utterance) throws ProcessException { 070 String results; 071 for (Item syllable = 072 utterance.getRelation(Relation.SYLLABLE).getHead(); 073 syllable != null; 074 syllable = syllable.getNext()) { 075 results = (String) accentCart.interpret(syllable); 076 if (!results.equals("NONE")) { 077 syllable.getFeatures().setString("accent", results); 078 } 079 results = (String) toneCart.interpret(syllable); 080 if (!results.equals("NONE")) { 081 syllable.getFeatures().setString("endtone", results); 082 } 083 } 084 } 085 086 // inherited from Object 087 public String toString() { 088 return "CARTIntonator"; 089 } 090}