gpt4 book ai didi

Java - 将效果应用于 MaryTTS 语音

转载 作者:行者123 更新时间:2023-11-29 08:41:14 26 4
gpt4 key购买 nike

我在 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/

最佳答案

这也是我正在研究的事情。我遇到了这个非常重要的问题,但我没有找到太多活跃的例子。通过反复试验,我发现了一些东西。

首先要获得所有可能的效果,您可以运行此命令:

for (AudioEffect e : AudioEffects.getEffects()) {
System.out.println(e.getName());
System.out.println(e.getHelpText());
System.out.println();
}

这将打印出名称和您可以设置的各种参数。然后您可以像这样设置字符串:

LocalMaryInterface mary = new LocalMaryInterface();
mary.setAudioEffects("Robot(amount:100)+Stadium(amount:200)");

然而,他们的意图似乎是让人们像这样使用它:

RobotiserEffect robotiserEffect = new RobotiserEffect();
robotiserEffect.setParams("amount:100");
StadiumEffect stadiumEffect = new StadiumEffect();
stadiumEffect.setParams("amount:100");
mary.setAudioEffects(robotiserEffect.getFullEffectAsString() + '+' +
stadiumEffect.getFullEffectAsString());

还有一个名为 EffectsApplier 的类,看起来它应该能够处理和优化您拥有的效果的顺序,但我没有时间进一步研究不幸的是。

我有一个工作 github example , 希望这有帮助。

关于Java - 将效果应用于 MaryTTS 语音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40134409/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com