⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playermodelimpl.java

📁 使用Exlipse编写的一个语音程序
💻 JAVA
字号:
/*******************************************************************************
 * Copyright (c) 2004 Berthold Daum. All rights reserved. This program and the
 * accompanying materials are made available under the terms of the Common
 * Public License v1.0 which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors: Berthold Daum
 ******************************************************************************/

package com.bdaum.dukeSpeake;
import com.sun.speech.freetts.Voice;
/** * @author Berthold Daum * * created: 13.08.2002  */public class PlayerModelImpl implements PlayerModel {	// the Voice instance used in this model	private Voice voice;	// Semaphore for inhibiting double playing	private boolean playing = false;	/**	 * Method PlayerModelImpl.	 * @param voice a FreeTTS voice object.	 */	public PlayerModelImpl(Voice voice) {		this.voice = voice;	}	/**	 * @see PlayerModel#play(String)	 */	public void play(final String text) {		// do nothing if player runs already.		if (playing)			return;		// Set semaphore to true		playing = true;		// The speech process runs in a separate thread 
		// that is managed by the SwingWorker instance worker 
		final SwingWorker worker = new SwingWorker() {			public Object construct() {				// This is where we speak				voice.speak(text);				return null;			}		};
		worker.start();		// Reset semaphore		playing = false;	}	/**	 * @see PlayerModel#getVolume()	 */	public float getVolume() {		// Get volume from Voice instance		// and convert to scale range 0-10		float adjustedVolume = voice.getVolume();		return (adjustedVolume < 0.5)			? 0f			: (float) ((adjustedVolume - 0.5) * 20);	}	/**	 * @see PlayerModel#setVolume(float)	 */	public void setVolume(float volume) {		// Set volume in Voice instance		// convert from scale range 0-10 to Voice range 0.5-1.0		float adjustedVolume = (float) (volume / 20 + 0.5);		voice.setVolume(adjustedVolume);	}	/**	 * @see PlayerModel#getSpeakingRate()	 */	public float getSpeakingRate() {		// Get speaking rate from Voice instance		return voice.getRate();	}	/**	 * @see PlayerModel#setSpeakingRate(float)	 */	public void setSpeakingRate(float wordsPerMin) {		// Set speaking rate in Voice instance		voice.setRate(wordsPerMin);	}	/**	 * @see PlayerModel#getPitch()	 */	public float getPitch() {		// Get pitch from Voice instance		return voice.getPitch();	}	/**	 * @see PlayerModel#setPitch(float)	 */	public void setPitch(float pitch) {		// Set pitch in Voice instance		voice.setPitch(pitch);	}	/**	 * @see PlayerModel#getRange()	 */	public float getRange() {		// Get variation from Voice instance		return voice.getPitchRange();	}	/**	 * @see PlayerModel#setRange(float)	 */	public void setRange(float range) {		// Set variation in Voice instance		voice.setPitchRange(range);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -