我在 Java 中使用了一组名为(MaryTTS
[实际上还有更多])的库来text to speech
为此目的进行转换,使用了以下代码:
public class TextToSpeech {
private AudioPlayer tts;
private MaryInterface marytts;
Map<Integer,String> numbersMap = new HashMap<>();
/**
* Constructor
*/
public TextToSpeech() {
try {
marytts = new LocalMaryInterface();
// Available voices
Voice.getAvailableVoices().stream().forEach(System.out::println);
marytts.setVoice("cmu-slt-hsmm");
} catch (MaryConfigurationException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
numbersMap.put(1, "one");
numbersMap.put(2, "two");
numbersMap.put(3, "three");
numbersMap.put(4, "four");
numbersMap.put(5, "five");
numbersMap.put(6, "six");
numbersMap.put(7, "seven");
numbersMap.put(8, "eight");
numbersMap.put(9, "nine");
}
public void setVoice(String voice) {
marytts.setVoice(voice);
}
/**
* Transform number to speech
*
* @param number
*/
public void speak(int number) {
speak(numbersMap.get(number));
}
/**
* Transform text to speech
*
* @param text
*/
public void speak(String text) {
// Stop the previous player
if (tts != null)
tts.cancel();
try (AudioInputStream audio = marytts.generateAudio(text)) {
// Player is a thread(threads can only run one time) so it can be
// used has to be initiated every time
tts = new AudioPlayer();
tts.setAudio(audio);
tts.setDaemon(true);
tts.start();
} catch (SynthesisException ex) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Error saying phrase.", ex);
} catch (IOException ex) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "IO Exception", ex);
}
}
}
问题:
我正在搜索文档,但它有点混乱,我对此很陌生。
有用的链接:
http://mary.dfki.de/javadoc/index.html
http://mary.dfki.de/download/index.html
https://github.com/marytts/marytts
我想知道如何将效果应用于我使用的声音。
我的意思是说?
看看这个现场演示http://mary.dfki.de:59125/