2 * Copyright 2002 DFKI GmbH.
3 * All Rights Reserved. Use is subject to license terms.
5 * See the file "license.terms" for information on usage and
6 * redistribution of this file, and for a DISCLAIMER OF ALL
10 package de.dfki.lt.freetts.mbrola;
12 import com.sun.speech.freetts.Item;
13 import com.sun.speech.freetts.ProcessException;
14 import com.sun.speech.freetts.Relation;
15 import com.sun.speech.freetts.Utterance;
16 import com.sun.speech.freetts.UtteranceProcessor;
19 * Utterance processor converting phoneme timing and f0-time targets
22 public class ParametersToMbrolaConverter implements UtteranceProcessor {
25 * Convert phoneme timing and f0-time targets
26 * into MBROLA format. The results are saved in the Segment relations,
27 * as features <code>"mbr_dur"</code> (int-valued) and
28 * <code>"mbr_targets"</code> (String-valued). MBROLA-converted targets
29 * are saved in the Segment relation because in MBROLA input, targets
30 * are represented as properties of the segments during which they occur.
32 * @param utterance the utterance to process
34 * @throws ProcessException if an error occurs while
35 * processing of the utterance
37 public void processUtterance(Utterance utterance) throws ProcessException {
38 Relation segmentRelation = utterance.getRelation(Relation.SEGMENT);
39 Relation targetRelation = utterance.getRelation(Relation.TARGET);
41 Item segment = segmentRelation.getHead();
43 if (targetRelation != null) target = targetRelation.getHead();
45 while (segment != null) {
46 // String name = segment.getFeatures().getString("name");
47 // Accumulated duration of all segments in the utterance,
49 float end = segment.getFeatures().getFloat("end");
50 // Individual duration of segment, in milliseconds:
51 int dur = (int) ((end - prevEnd) * 1000);
52 StringBuffer targetStringBuffer = new StringBuffer();
53 while (target != null &&
54 target.getFeatures().getFloat("pos") <= end) {
55 float pos = target.getFeatures().getFloat("pos");
56 // time axis as percentage of segment duration:
57 int percentage = ((int) ((pos - prevEnd) * 1000)) * 100 / dur;
59 int f0 = (int) target.getFeatures().getFloat("f0");
60 targetStringBuffer.append(" ");
61 targetStringBuffer.append(percentage);
62 targetStringBuffer.append(" ");
63 targetStringBuffer.append(f0);
64 target = target.getNext();
66 // System.err.println(name + " " + dur + targetStringBuffer);
67 segment.getFeatures().setInt("mbr_dur", dur);
68 segment.getFeatures().setString("mbr_targets",
69 targetStringBuffer.toString().trim());
71 segment = segment.getNext();
75 public String toString() {
76 return "ParametersToMbrolaConverter";