将FreeTTS的发音输出到外部文件 use freetts to generate a wave file

本文原帖在这:http://sourceforge.net/projects/freetts/forums/forum/137669/topic/1166875

为了让你看的方便,直接把关键的东西给你算了。省得自己找半天,嘿嘿

源码如下:

	public static void main(String[] args) throws InstantiationException {
		System.setProperty("com.sun.speech.freetts.voice.defaultAudioPlayer", "com.sun.speech.freetts.audio.SingleFileAudioPlayer"); 
		SingleFileAudioPlayer sfap;

		System.out.println("Using voice: " + "kevin16");
     
		/* The VoiceManager manages all the voices for FreeTTS.
		 */
		VoiceManager voiceManager = VoiceManager.getInstance();
		Voice helloVoice = voiceManager.getVoice("kevin16");

		if (helloVoice == null) {
			System.err.println(
					"Cannot find a voice named "
					+ "kevin16" + ".  Please specify a different voice.");
			System.exit(1);
		}
     
		/* Allocates the resources for the voice.
		 */
		helloVoice.allocate();
		sfap = (SingleFileAudioPlayer)helloVoice.getDefaultAudioPlayer();
		helloVoice.setAudioPlayer(sfap);
		helloVoice.speak("Thank you for giving me a voice. "
                      + "I'm so glad to say hello to this world.");
		sfap.close();//write data to file at here.
		/* Clean up and leave.
		 */
		helloVoice.deallocate();
		System.exit(0);
	}


 

你可能感兴趣的:(String,File,null,UP,resources)