且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何实现Text-to-Speech示例?

更新时间:2023-11-15 13:49:34

我也很新,但我会尽力帮助你。

首先,您需要从importet lib导入类。 (您可以在 http://mary.dfki.de/download/index.html 下载[ ^ ]。顺便说一句,它的运行包装,所以你不需要服务器。 ..

要设置界面,您需要以下内容:

import marytts.LocalMaryInterface;

import marytts.MaryInterface;



这个例子是在你系统的tmp文件夹中写一个名为thisIsMyText的wave。

之后你必须打开它然后你才能玩它。

试试这个来玩你项目中的wave。



Im quite new too but i will try to help you with it.
First of all you need to import the classes from your importet lib. (which you can download at http://mary.dfki.de/download/index.html[^]. Btw. its the runtimepackage so you dont need the server...
To set up your interface you need the following:
import marytts.LocalMaryInterface;
import marytts.MaryInterface;

The example is writing a wave called thisIsMyText in your tmp folder on your system.
After this you have to open it and then you can play it.
try this to play the wave within your project.

try {
		    AudioInputStream input = AudioSystem.getAudioInputStream(new File("/tmp/thisIsMyText.wav"));
		    SourceDataLine line = AudioSystem.getSourceDataLine(input.getFormat());
		    line.open(input.getFormat());
		    line.start();
		    byte[] buffer = new byte[1024];
		    int count;
		    while((count = input.read(buffer, 0, 1024)) != -1) {
		        line.write(buffer, 0, count);
		    }
		    line.drain();
		    line.stop();
		    line.close();
		} catch(Exception e) {
		    e.printStackTrace();
		}