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.clunits; 012 013import com.sun.speech.freetts.Item; 014import com.sun.speech.freetts.relp.LPCResult; 015import com.sun.speech.freetts.UtteranceProcessor; 016import com.sun.speech.freetts.Utterance; 017import com.sun.speech.freetts.Relation; 018import com.sun.speech.freetts.ProcessException; 019 020import com.sun.speech.freetts.relp.SampleSet; 021 022/** 023 * 024 * Calculates the pitchmarks. This class is an UtteranceProcessor that 025 * calculates target pitchmarks for the given utterance and adds the 026 * <i>target_lpcres</i> relation to the utterance with the pitchmark 027 * information. 028 * 029 * @see LPCResult 030 */ 031public class ClusterUnitPitchmarkGenerator implements UtteranceProcessor { 032 033 /** 034 * Calculates the pitchmarks for the utterance and adds them as 035 * an LPCResult to the Utterance in a relation named 036 * "target_lpcres". 037 * 038 * @param utterance the utterance to process 039 * 040 * @see LPCResult 041 * 042 * @throws ProcessException if an error occurs while processing 043 * the utterance 044 */ 045 public void processUtterance(Utterance utterance) throws ProcessException { 046 LPCResult lpcResult; 047 int pitchmarks = 0; 048 int uttSize = 0; 049 int unitEntry; 050 int unitStart; 051 int unitEnd; 052 053 SampleSet sts = (SampleSet) utterance.getObject("sts_list"); 054 lpcResult = new LPCResult(); 055 056 for (Item unit = utterance.getRelation(Relation.UNIT).getHead(); 057 unit != null; unit = unit.getNext()) { 058 unitEntry = unit.getFeatures().getInt("unit_entry"); 059 unitStart = unit.getFeatures().getInt("unit_start"); 060 unitEnd = unit.getFeatures().getInt("unit_end"); 061 uttSize += sts.getUnitSize(unitStart, unitEnd); 062 pitchmarks += unitEnd - unitStart; 063 unit.getFeatures().setInt("target_end", uttSize); 064 } 065 066 lpcResult.resizeFrames(pitchmarks); 067 068 pitchmarks = 0; 069 uttSize = 0; 070 071 int[] targetTimes = lpcResult.getTimes(); 072 073 for (Item unit = utterance.getRelation(Relation.UNIT).getHead(); 074 unit != null; unit = unit.getNext()) { 075 unitEntry = unit.getFeatures().getInt("unit_entry"); 076 unitStart = unit.getFeatures().getInt("unit_start"); 077 unitEnd = unit.getFeatures().getInt("unit_end"); 078 for (int i = unitStart; i < unitEnd; i++,pitchmarks++) { 079 uttSize += sts.getSample(i).getResidualSize(); 080 targetTimes[pitchmarks] = uttSize; 081 } 082 } 083 utterance.setObject("target_lpcres", lpcResult); 084 } 085 086 /** 087 * Retrieves the name of this utteranceProcessor. 088 * 089 * @return the name of the utteranceProcessor 090 */ 091 public String toString() { 092 return "ClusterUnitPitchmarkGenerator"; 093 } 094}