在FreeTTS的Java程序中使用MBROLA语音...
我正在使用Java编写一个简单的 text-to-speech 程序。我决定使用FreeTTS,但声音并不是我想的,而且我还是想用一个女声。所以我开始环顾四周,并决定使用MBROLA来改变我的文本到语音程序的声音。
我读到 " FreeTTS可以使用MBROLA语音" ,但我搜索到的所有地方都无法找到明确指南如何设置MBROLA,以及需要哪些文件。 MBROLA上有许多论坛与FreeTTS一起工作,但似乎没有人知道他们在做什么。
所以问题:
答案 0 :(得分:12)
上述问题的答案:
<强> 1。需要下载哪些文件?
1.1 FreeTTS 库(在freetts-1.2.2-bin / freetts-1.2 / lib中找到):
1.2 MBROLA zip文件夹包含:
1.3 语音是压缩文件夹,其中包含名为“ us1 ”或“ af1 ”等的单个文件夹。
<强> 2。将这些内容纳入我的计划的步骤?
注意:我的计算机上也安装了MBROLA Tooklit,但我不确定它是否对程序有影响,但我怀疑它没有。编辑:我已经测试过,看看MBROLA工具包是否需要与FreeTTS一起运行MBROLA,结果证明它不需要。
完成此操作后,您的mbrola文件夹应如下所示:
您可以将所有语言放在此文件夹中,只需从Java程序中调用它们即可。
<强> 3。使用MBROLA语音的简单FreeTTS示例?
我见过很多人都会收到这个错误:
System property "mbrola.base" is undefined. Will not use MBROLA voices.
mbrola.base
指的是您的mbrola文件在计算机上的位置,如果没有将属性指向正确的位置,您将收到此错误。
对于收到此错误的NON-MBROLA用户:如果您只使用FreeTTS,只需从引用的库中删除mbrola.jar
要设置mbrola.base
属性,请使用:
System.setProperty("mbrola.base", "C:/Path/to/your/mbrola")
以下是在FreeTTS程序中使用MBROLA语音的简单示例。请注意,必须先执行上述步骤才能执行此操作。如果未设置基础,只需将声音名称更改为“mbrola_us1”即可生效!
package com.madmob.test;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class TestTTS {
VoiceManager freettsVM;
Voice freettsVoice;
public TestTTS(String words) {
// Most important part!
System.setProperty("mbrola.base", "C:/mbrola");
freettsVM = VoiceManager.getInstance();
// Simply change to MBROLA voice
freettsVoice = freettsVM.getVoice("mbrola_us1");
// Allocate your chosen voice
freettsVoice.allocate();
sayWords(words);
}
public void sayWords(String words) {
// Make her speak!
freettsVoice.speak(words);
}
public static void main(String [] args) {
new TestTTS("Hello there! Now M BROLA and Free T T S work together!");
}
}
MBROLA和FreeTTS现在应该合作!这段代码是直接从我的电脑上复制过来的,经过测试后再将它放在这里。
答案 1 :(得分:2)
感谢这个论坛的回复,我终于能够让它发挥作用。 在Windows 10上;我执行了以下步骤以使其正常工作:
System.setProperty("mbrola.base", "ABSOLUTE_PATH_TO_mbrola_directory_ending_with_/");
voiceManager = VoiceManager.getInstance();
voice = voiceManager.getVoice("mbrola_us1");
注意:如果您的语音数据库文件夹名称是us1;那么你应该把它添加到&#34; mbrola_us1&#34 ;;如果它是en1,那么它应该是&#34; mbrola_en1&#34; 。这实际上是我的伎俩。答案 2 :(得分:1)
请从这里找到工作示例:
https://github.com/sunrise-projects/sphinx4/tree/glass
package com.sunriseprojects.freetts.demo;
import java.beans.PropertyVetoException;
import java.util.Locale;
import javax.speech.AudioException;
import javax.speech.Central;
import javax.speech.EngineException;
import javax.speech.EngineStateError;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;
import javax.speech.synthesis.Voice;
public class SpeechUtils {
SynthesizerModeDesc desc;
Synthesizer synthesizer;
Voice voice;
public void init(String voiceName) throws EngineException, AudioException,
EngineStateError, PropertyVetoException {
if (desc == null) {
//default
// System.setProperty("freetts.voices",
// "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
//have to be setup
System.setProperty("freetts.voices",
"de.dfki.lt.freetts.en.us.MbrolaVoiceDirectory");
desc = new SynthesizerModeDesc(Locale.US);
Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
synthesizer = Central.createSynthesizer(desc);
synthesizer.allocate();
synthesizer.resume();
SynthesizerModeDesc smd = (SynthesizerModeDesc) synthesizer
.getEngineModeDesc();
Voice[] voices = smd.getVoices();
Voice voice = null;
for (int i = 0; i < voices.length; i++) {
if (voices[i].getName().equals(voiceName)) {
voice = voices[i];
break;
}
}
synthesizer.getSynthesizerProperties().setVoice(voice);
}
}
public void terminate() throws EngineException, EngineStateError {
synthesizer.deallocate();
}
public void doSpeak(String speakText) throws EngineException,
AudioException, IllegalArgumentException, InterruptedException {
synthesizer.speakPlainText(speakText, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
}
public static void main(String[] args) throws Exception {
System.setProperty("mbrola.base", "C:\\lnx1\\home\\ggon\\git-projects\\mbrola");
SpeechUtils su = new SpeechUtils();
//have to be setup on your env
su.init("mbrola_us1");
//default
//su.init("kevin16");
//su.init("kevin");
//su.doSpeak("Hello world!");
su.doSpeak(SAMPLE);
su.terminate();
}
final static String SAMPLE = "Wiki said, Floyd Mayweather, Jr. is an American professional boxer. He is currently undefeated as a professional and is a five-division world champion, having won ten world titles and the lineal championship in four different weight classes";
}