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;
13 import java.io.BufferedReader;
14 import java.io.IOException;
15 import java.io.InputStreamReader;
17 import java.util.HashMap;
18 import java.util.StringTokenizer;
21 * Maintains set of PhoneDuration instances read in from a file. The
22 * format of the file is as follows:
31 * Where <code>phone</code> is the phone name, <code>mean</code> is
32 * a <code>float</code> representing the mean duration of the phone
33 * (typically in seconds), and <code>stddev</code> is a
34 * <code>float</code> representing the standard deviation from the
37 public class PhoneDurationsImpl implements PhoneDurations {
39 * The set of PhoneDuration instances indexed by phone.
41 private HashMap phoneDurations;
44 * Creates a new PhoneDurationsImpl by reading from the given URL.
46 * @param url the input source
48 * @throws IOException if an error occurs
50 public PhoneDurationsImpl(URL url) throws IOException {
51 BufferedReader reader;
54 phoneDurations = new HashMap();
55 reader = new BufferedReader(new
56 InputStreamReader(url.openStream()));
57 line = reader.readLine();
58 while (line != null) {
59 if (!line.startsWith("***")) {
62 line = reader.readLine();
68 * Creates a word from the given input line and adds it to the
71 * @param line the input line
73 private void parseAndAdd(String line) {
74 StringTokenizer tokenizer = new StringTokenizer(line," ");
75 String phone = tokenizer.nextToken();
76 float mean = Float.parseFloat(tokenizer.nextToken());
77 float stddev = Float.parseFloat(tokenizer.nextToken());
78 phoneDurations.put(phone, new PhoneDuration(mean,stddev));
82 * Gets the <code>PhoneDuration</code> for the given phone. If no
83 * duration is applicable, returns <code>null</code>.
85 * @param phone the phone
87 * @return the <code>PhoneDuration</code> for <code>phone</code>
89 public PhoneDuration getPhoneDuration(String phone) {
90 return (PhoneDuration) phoneDurations.get(phone);