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.relp;
13 import java.util.logging.Level;
14 import java.util.logging.Logger;
16 import javax.sound.sampled.AudioFormat;
18 import com.sun.speech.freetts.ProcessException;
19 import com.sun.speech.freetts.Utterance;
20 import com.sun.speech.freetts.UtteranceProcessor;
21 import com.sun.speech.freetts.audio.AudioPlayer;
24 * Supports generating audio output from an utterance. This is an
25 * utterance processor. The primary method, <code> procesUtterance </code>
26 * takes an utterance and hands it off to the LPCResult to be sent to the
27 * proper audio player.
31 public class AudioOutput implements UtteranceProcessor {
32 /** Logger instance. */
33 private static final Logger LOGGER =
34 Logger.getLogger(AudioOutput.class.getName());
36 private final static AudioFormat AUDIO_8KHZ =
37 new AudioFormat(8000.0f, 16, 1, true, true);
38 private final static AudioFormat AUDIO_16KHZ =
39 new AudioFormat(16000.0f, 16, 1, true, true);
42 * Generates audio waves for the given Utterance. The audio data
43 * is decoded using the Linear Predictive Decoder
45 * @param utterance the utterance to generate waves
49 * @throws ProcessException if an IOException is thrown during the
50 * processing of the utterance
52 public void processUtterance(Utterance utterance) throws ProcessException {
53 LPCResult lpcResult = (LPCResult) utterance.getObject("target_lpcres");
54 SampleInfo sampleInfo =
55 (SampleInfo) utterance.getObject(SampleInfo.UTT_NAME);
56 AudioPlayer audioPlayer = utterance.getVoice().getAudioPlayer();
58 audioPlayer.setAudioFormat(getAudioFormat(sampleInfo));
59 audioPlayer.setVolume(utterance.getVoice().getVolume());
61 if (LOGGER.isLoggable(Level.FINE)) {
63 utterance.getString("input_text"));
65 if (!lpcResult.playWave(audioPlayer, utterance)) {
66 throw new ProcessException("Output Cancelled");
72 * Gets the current audio format.
73 * Given a sample info return an appropriate audio format. A cache
74 * of common audio formats is used to reduce unnecessary object
75 * creation. Note that this method always returns an AudioFormat
76 * that uses 16-bit samples.
78 * @param sampleInfo the sample info
80 * @return an audio format
82 private AudioFormat getAudioFormat(SampleInfo sampleInfo) {
83 if (sampleInfo.getSampleRate() == 8000) {
85 } else if (sampleInfo.getSampleRate() == 16000) {
88 return new AudioFormat(sampleInfo.getSampleRate(),
95 * Returns the string form of this object
97 * @return the string form of this object
99 public String toString() {
100 return "AudioOutput";