亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? animatedaudioplayer.java

?? 一個非常有意思,并且?guī)D像的語音項目,能讀出相應(yīng)的英文,并有口型
?? JAVA
字號:
/**
 * Copyright 2001 Sun Microsystems, Inc.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 */
package com.sun.speech.freetts.audio;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineUnavailableException;

import com.sun.speech.freetts.util.BulkTimer;

/**
 * Provides an implementation of <code>AudioPlayer</code> that creates
 * javax.sound.sampled audio clips and outputs them via the
 * javax.sound API.  The interface provides a highly reliable audio
 * output package. Since audio is batched and not sent to the audio
 * layer until an entire utterance has been processed, this player has
 * higher latency (50 msecs for a typical 4 second utterance).
 *
 * The system property:
 * <code>
	com.sun.speech.freetts.audio.AudioPlayer.debug;
 * </code> if set to <code>true</code> will cause this
 * class to emit debugging information (useful to a developer).
 */
public class AnimatedAudioPlayer implements AudioPlayer {
    
    private volatile boolean paused;
    private volatile boolean done = false;
    private volatile boolean cancelled = false;
    private volatile Clip currentClip;

    private float volume = 1.0f;  // the current volume
    private boolean debug = false;
    private BulkTimer timer = new BulkTimer();
    private AudioFormat defaultFormat = // default format is 8khz
	new AudioFormat(8000f, 16, 1, true, true);
    private AudioFormat currentFormat = defaultFormat;
    private boolean firstSample = true;
    private int curIndex = 0;
    private byte[] outputData;
    private LineListener lineListener = new JavaClipLineListener();
    private long closeDelay;	// workaround for linux sound bug
	private LineListener externalLineListener; // -- added by bd
 	/**
	 * Constructs a default AnimatedAudioPlayer 
	 * -- modified by bd
	 */
	public AnimatedAudioPlayer(LineListener externalLineListener) {
		this.externalLineListener = externalLineListener;
		debug = Boolean.getBoolean
			("com.sun.speech.freetts.audio.AudioPlayer.debug");
		closeDelay = Long.getLong
			("com.sun.speech.freetts.audio.AudioPlayer.closeDelay",
				150L).longValue();
		setPaused(false);
	}
    /**
     * Sets the audio format for this player
     *
     * @param format the audio format
     *
     * @throws UnsupportedOperationException if the line cannot be opened with
     *     the given format
     */
    public synchronized void setAudioFormat(AudioFormat format) {
	currentFormat = format;
    }

    /**
     * Retrieves the audio format for this player
     *
     * @return format the audio format
     */
    public AudioFormat getAudioFormat() {
	return currentFormat;
    }



    /**
     * Pauses audio output.   All audio output is 
     * stopped. Output can be resumed at the
     * current point by calling <code>resume</code>. Output can be
     * aborted by calling <code> cancel </code>
     */
    public synchronized void pause() {
	if (!isPaused()) {
	    setPaused(true);
	    Clip clip = currentClip;
	    if (clip != null) {
	        clip.stop();
	    }
	}
    }

    /**
     * Resumes playing audio after a pause.
     *
     */
    public synchronized void resume() {
	if (isPaused()) {
	    setPaused(false);
	    Clip clip = currentClip;
	    if (clip != null) {
		clip.start();
	    }
	    notify();
	}
    }
	
    /**
     * Cancels all queued audio. Any 'write' in process will return
     * immediately false.
     */
    public synchronized void cancel() {
	cancelled = true;
	Clip clip = currentClip;
	if (clip != null) {
	    clip.close();
	}
    }

    /**
     * Prepares for another batch of output. Larger groups of output
     * (such as all output associated with a single FreeTTSSpeakable)
     * should be grouped between a reset/drain pair.
     */
    public synchronized void reset() {
	timer.start("speakableOut");
    }

    /**
     * Waits for all queued audio to be played
     *
     * @return <code>true</code> if the write completed successfully, 
     *       	<code> false </code>if the write was cancelled.
     */
    public boolean drain()  {
	timer.stop("speakableOut");
	return true;
    }

    /**
     * Closes this audio player
     */
    public synchronized void close() {
	done = true;
	notify();
    }
        

    /**
     * Returns the current volume.
     * @return the current volume (between 0 and 1)
     */
    public float getVolume() {
	return volume;
    }	      

    /**
     * Sets the current volume.
     * @param volume  the current volume (between 0 and 1)
     */
    public void setVolume(float volume) {
	if (volume > 1.0f) {
	    volume = 1.0f;
	}
	if (volume < 0.0f) {
	    volume = 0.0f;
	}
	this.volume = volume;
	Clip clip = currentClip;
	if (clip != null) {
	    setVolume(clip, volume);
	}
    }	      


    /**
     * Sets pause mode
     * @param state true if we are paused
     */
    private void setPaused(boolean state) {
	paused = state;
    }

    /**
     * Returns true if we are in pause mode
     *
     * @return <code> true </code>if paused; 
     *		otherwise returns <code>false</code>
     */
    private boolean isPaused() {
	return paused;
    }

    /**
     * Sets the volume on the given clip
     *
     * @param line the line to set the volume on
     * @param vol the volume (range 0 to 1)
     */
    private void setVolume(Clip clip, float vol) {
	if (clip.isControlSupported (FloatControl.Type.MASTER_GAIN)) {
	    FloatControl volumeControl = 
		(FloatControl) clip.getControl (FloatControl.Type.MASTER_GAIN);
	    float range = volumeControl.getMaximum() -
			  volumeControl.getMinimum();
	    volumeControl.setValue(vol * range + volumeControl.getMinimum());
	}
    }




    /**
     * Returns the current position in the output stream since the
     * last <code>resetTime</code> 
     *
     * Currently not supported.
     *
     * @return the position in the audio stream in milliseconds
     *
     */
    public synchronized long getTime()  {
        return -1L;
    }


    /**
     * Resets the time for this audio stream to zero
     */
    public synchronized void resetTime() {
    }
    

    /**
     *  Starts the output of a set of data. Audio data for a single
     *  utterance should be grouped between begin/end pairs.
     *
     * @param size the size of data between now and the end
     *
     */
    public void begin(int size) {
	cancelled = false;
	timer.start("utteranceOutput");
	curIndex = 0;
	outputData = new byte[size];
    }

    /**
     *  Marks the end a set of data. Audio data for a single utterance should
     *  be grouped between begin/end pairs.
     *
     *  @return <code>true</code> if the audio was output properly, 
     * 		<code>false </code> if the output was cancelled 
     *		or interrupted.
     */
    public synchronized boolean  end()  {
	boolean ok = true;

	while (!done && !cancelled && isPaused()) {
	    try { 
		wait();
	    } catch (InterruptedException ie) {
		return false;
	    }
	}

	if (done || cancelled) {
	    cancelled = false;
	    return false;
	}

	timer.start("clipGeneration");
	try {
	    DataLine.Info info = new DataLine.Info(Clip.class, currentFormat);
	    Clip clip = (Clip) AudioSystem.getLine(info);

	    clip.addLineListener(lineListener);
	    clip.addLineListener(externalLineListener); // -- added by bd
	    clip.open(currentFormat, outputData, 0, outputData.length);
	    setVolume(clip, volume);

	    if (currentClip != null) {
		throw new IllegalStateException("clip already set");
	    }
	    currentClip = clip;
	    clip.start();

	    try {
		while (currentClip != null) {
		    wait();	// drain does not work 
		}
	    } catch (InterruptedException ie) {
		ok = false;
	    }
	} catch (LineUnavailableException lue) {
	    System.err.println("Line unavailable");
	    System.err.println("Format is " + currentFormat);
	    ok = false;
	}

	timer.stop("clipGeneration");
	timer.stop("utteranceOutput");
	ok = !cancelled;
	cancelled = false;
	return ok;
    }

    
    /**
     * Writes the given bytes to the audio stream
     *
     * @param audioData audio data to write to the device
     *
     * @return <code>true</code> if the write completed successfully, 
     *       	<code> false </code>if the write was cancelled.
     */
    public boolean write(byte[] audioData) {
	return write(audioData, 0, audioData.length);
    }
    
    /**
     * Writes the given bytes to the audio stream
     *
     * @param bytes audio data to write to the device
     * @param offset the offset into the buffer
     * @param size the size into the buffer
     *
     * @return <code>true</code> if the write completed successfully, 
     *       	<code> false </code>if the write was cancelled.
     */
    public boolean write(byte[] bytes, int offset, int size) {

	if (firstSample) {
	    firstSample = false;
	    timer.stop("firstAudio");
	}
	System.arraycopy(bytes, offset, outputData, curIndex, size);
	curIndex += size;
	return true;
    }


    /**
     * Returns the name of this audio player
     *
     * @return the name of the audio player
     */
    public String toString() {
	return "JavaClipAudioPlayer";
    }


    /**
     * Outputs the given msg if debugging is enabled for this
     * audio player.
     */
    private void debugPrint(String msg) {
	if (debug) {
	    System.out.println(toString() + ": " + msg);
	}
    }

    /**
     * Shows metrics for this audio player
     */
    public void showMetrics() {
	timer.show(toString());
    }

    /**
     * Starts the first sample timer
     */
    public void startFirstSampleTimer() {
	timer.start("firstAudio");
	firstSample = true;
    }


    /**
     * Provides a LineListener for this clas.
     */
    private class JavaClipLineListener implements LineListener {


	/**
	 * Implements update() method of LineListener interface. Responds
	 * to the line events as appropriate.
	 *
	 * @param event the LineEvent to handle
	 */
	public void update(LineEvent event) {
	    if (event.getType().equals(LineEvent.Type.START)) {
		debugPrint("Event  START");
	    } else if (event.getType().equals(LineEvent.Type.STOP)) {
		debugPrint("Event  STOP");
		// A line may be stopped for three reasons:
		//    the clip has finished playing
		//    the clip has been paused
		//    the clip has been cancelled (i.e. closed)
		// if the clip has stopped because it has finished
		// playing, then we should close the clip, otherwise leave
		// it alone
		synchronized(AnimatedAudioPlayer.this) {
		    if (!cancelled && !isPaused()) {

	// BUG:
	// There is a javax.sound bug that causes a crash on linux
	// it is described here:
	// http://developer.java.sun.com/developer/bugParade/bugs/4498848.html
	// The bug seems to be related to synchronization of the close
	// call on the clip.  If we delay before the close by 
	// a small amount, the crash is averted.  This is a WORKAROUND
	// only and should be removed once the javax.sound bug is
	// fixed.  We get the delay from the property:
	//
	// com.sun.speech.freetts.audio.AudioPlayer.closeDelay
	// 
	// 
			try {
			    if (closeDelay > 0L) {
				Thread.sleep(closeDelay);
			    }
		    	} catch (InterruptedException ie) {
			}
			currentClip.close();
		    }
		}
	    }  else if (event.getType().equals(LineEvent.Type.OPEN)) {
		debugPrint("Event OPEN");
	    }  else if (event.getType().equals(LineEvent.Type.CLOSE)) {
		// When a clip is closed we no longer need it, so 
		// set currentClip to null and notify anyone who may
		// be waiting on it.
		debugPrint("EVNT CLOSE");
		synchronized (AnimatedAudioPlayer.this) {
		    currentClip = null;
		    AnimatedAudioPlayer.this.notify();
		}
	    }
	}
    }
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美大片在线观看一区二区| 欧美日韩一区不卡| 久久久久国产一区二区三区四区| 免费在线看成人av| 欧美一级二级三级乱码| 老司机一区二区| 国产日韩欧美精品在线| 成人黄色电影在线| 亚洲资源中文字幕| 欧美一区二区在线免费观看| 国产中文字幕精品| 欧美韩日一区二区三区四区| 日本道免费精品一区二区三区| 亚洲国产精品久久人人爱蜜臀| 欧美一区二区三区白人| 国产高清不卡二三区| 一区视频在线播放| 91麻豆精品国产91久久久资源速度| 久久精品国产久精国产| 国产精品第13页| 欧美绝品在线观看成人午夜影视| 激情五月婷婷综合网| 中文字幕五月欧美| 6080午夜不卡| 成人av电影在线| 日本vs亚洲vs韩国一区三区| 欧美激情一区二区在线| 欧美视频在线播放| 国产精品18久久久久久久久 | 中文成人av在线| 在线观看日韩av先锋影音电影院| 九九视频精品免费| 亚洲精选免费视频| 久久久亚洲综合| 欧美日产在线观看| 成人精品亚洲人成在线| 日韩1区2区3区| 亚洲国产电影在线观看| 欧美无人高清视频在线观看| 国产精品伊人色| 午夜av区久久| 综合电影一区二区三区| 欧美精品一区二区三区蜜臀| 欧美视频自拍偷拍| 成人的网站免费观看| 久久国产免费看| 国产美女一区二区| 午夜一区二区三区视频| 中文字幕一区二区三区在线不卡| 日韩一级视频免费观看在线| av在线播放不卡| 国产又黄又大久久| 婷婷六月综合网| 亚洲免费在线观看视频| 欧美激情一区二区在线| 精品88久久久久88久久久| 欧美午夜不卡在线观看免费| 91浏览器入口在线观看| 国产福利精品一区| 精品亚洲porn| 久久精品国产精品亚洲综合| 性欧美疯狂xxxxbbbb| 亚洲视频一区二区免费在线观看| 久久久综合九色合综国产精品| 欧美一区二区三区视频免费| 欧美乱熟臀69xxxxxx| 欧美日韩精品一区二区| 在线视频欧美精品| 91成人免费在线视频| 99国产精品视频免费观看| 国产成人亚洲综合a∨猫咪| 激情伊人五月天久久综合| 精品在线播放午夜| 精品中文av资源站在线观看| 九一九一国产精品| 精品亚洲免费视频| 国产高清亚洲一区| 国产盗摄女厕一区二区三区| 91精品国产美女浴室洗澡无遮挡| 欧洲视频一区二区| 91激情五月电影| 欧美日韩三级视频| 3d动漫精品啪啪| 日韩欧美一级二级三级| 欧美成人福利视频| 欧美成人a视频| 久久综合丝袜日本网| 精品成人一区二区三区| 久久久亚洲高清| 国产精品美女久久久久久2018| 国产精品久久久久毛片软件| 亚洲天堂免费看| 一区2区3区在线看| 日韩国产一二三区| 韩国成人在线视频| av在线播放一区二区三区| 91久久精品一区二区三| 欧美日韩国产影片| 精品久久久久久久久久久久包黑料 | 欧美一区二区国产| 日韩精品专区在线影院观看| 久久久久久9999| 亚洲欧洲综合另类在线| 视频一区免费在线观看| 国模一区二区三区白浆| 成人午夜免费电影| 欧美亚洲一区三区| 日韩欧美亚洲国产精品字幕久久久| 精品成人私密视频| 中文字幕一区二区三区在线不卡| 亚洲综合一区在线| 狠狠色综合日日| 91小视频免费观看| 日韩欧美一区二区三区在线| 中文字幕不卡的av| 三级欧美在线一区| 懂色av噜噜一区二区三区av | 欧美精品乱码久久久久久| 久久综合色8888| 亚洲免费av高清| 精品一二三四区| 欧美性感一类影片在线播放| 精品va天堂亚洲国产| 亚洲综合偷拍欧美一区色| 国产伦精品一区二区三区视频青涩 | 亚洲一区二区在线观看视频 | 一区二区在线观看视频在线观看| 另类小说欧美激情| 91国偷自产一区二区开放时间| 日韩欧美一区二区久久婷婷| 一区二区三区在线观看国产 | av亚洲精华国产精华精华| 日韩午夜中文字幕| 亚洲欧美色图小说| 国产永久精品大片wwwapp| 欧美巨大另类极品videosbest | 国产福利不卡视频| 自拍偷拍亚洲综合| 国产综合色产在线精品| 欧美性淫爽ww久久久久无| 久久综合久久久久88| 日韩中文字幕不卡| 色八戒一区二区三区| 亚洲国产成人在线| 国产一区在线精品| 日韩一卡二卡三卡国产欧美| 一区二区免费在线播放| 国产99精品国产| 久久亚洲一区二区三区明星换脸 | 国产成人一级电影| 日韩精品最新网址| 日韩电影在线观看电影| 色中色一区二区| 国产精品国产三级国产普通话三级 | 青青草97国产精品免费观看无弹窗版 | 日韩电影在线免费| 欧美日韩亚洲综合| 一区二区成人在线观看| 91同城在线观看| 亚洲欧洲日韩综合一区二区| 国产精品一区二区不卡| 欧美成人性福生活免费看| 日韩精品成人一区二区在线| 欧美亚洲高清一区二区三区不卡| 中文字幕一区二区不卡| 成人爱爱电影网址| 国产精品麻豆视频| 成人午夜精品在线| 国产亚洲欧美色| 国产福利视频一区二区三区| 久久久久久**毛片大全| 国产美女视频91| 国产日产欧产精品推荐色| 国产麻豆成人精品| 亚洲国产成人一区二区三区| 成人亚洲精品久久久久软件| 国产欧美日韩精品a在线观看| 成人深夜在线观看| 中文字幕中文字幕一区| 色偷偷久久人人79超碰人人澡| 亚洲欧美国产77777| 欧洲在线/亚洲| 五月婷婷久久综合| 欧美mv和日韩mv国产网站| 国产在线观看一区二区| 日本一区二区不卡视频| 色综合中文字幕| 天天综合日日夜夜精品| 欧美一区二区国产| 国产精品一区二区三区网站| 17c精品麻豆一区二区免费| 欧美午夜精品一区二区三区| 免费一级欧美片在线观看| 久久久一区二区| 日本韩国视频一区二区| 同产精品九九九| 国产午夜精品福利| 在线日韩一区二区| 在线观看区一区二| 蜜桃视频一区二区|