eclipse 带有 FreeTTS 的 MBROLA 语音 - Windows
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26236562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MBROLA voices with FreeTTS - Windows
提问by MadCharlie
Using MBROLA voices in a Java program with FreeTTS...
在带有 FreeTTS 的 Java 程序中使用 MBROLA 语音...
I am working on a simple text-to-speechprogram in Java. I have decided to use FreeTTS, but the voices are not really what I was thinking, and I was looking to use a female voice anyway. So I started looking around, and decided that I would use MBROLA to change the voice of my text-to-speechprogram.
我正在用 Java开发一个简单的文本到语音转换程序。我决定使用 FreeTTS,但声音并不是我真正想的那样,无论如何我都希望使用女性声音。所以我开始环顾四周,并决定使用 MBROLA 来改变我的文本转语音程序的声音。
I read that "FreeTTS can use MBROLA voices", but I searched everywhere and couldn't find a clear guide how to set MBROLA up, and what files are needed to do so. There are many forums on MBROLA working alongside FreeTTS, however it also seems that none of the people have any idea what they are doing.
我读到“FreeTTS 可以使用 MBROLA 语音”,但我到处搜索,找不到明确的指南如何设置 MBROLA,以及需要哪些文件。有许多关于 MBROLA 与 FreeTTS 一起工作的论坛,但是似乎也没有人知道他们在做什么。
So the questions:
所以问题:
- What files need to be downloaded?
- Steps to include these into my program?
- Simple FreeTTS example using MBROLA voices?
- 需要下载哪些文件?
- 将这些包含在我的程序中的步骤?
- 使用 MBROLA 语音的简单 FreeTTS 示例?
回答by MadCharlie
Answers to the questions above:
对以上问题的回答:
1. What files need to be downloaded?
1、需要下载哪些文件?
- FreeTTSwith all the libraries (freeTTS 1.2.2-bin)- download here
- MBROLAzip folder mbr301d.zip
- Voiceswhich can be found on the MBROLA website
- 的FreeTTS所有的库(1.2.2的FreeTTS斌)-这里下载
- MBROLAzip 文件夹mbr301d.zip
- 声音可在上找到MBROLA网站
1.1 The FreeTTSlibraries (found in freetts-1.2.2-bin/freetts-1.2/lib):
1.1 FreeTTS库(在 freetts-1.2.2-bin/freetts-1.2/lib 中找到):
- cmu_time_awb.jar
- cmu_us_kal.jar
- cmudict04.jar
- cmulex.jar
- cmutimelex.jar
- en_us.jar
- freetts.jar
- freetts-jsapi10.jar
- mbrola.jar
- cmu_time_awb.jar
- cmu_us_kal.jar
- cmudict04.jar
- cmulex.jar
- cmutimelex.jar
- en_us.jar
- freetts.jar
- freetts-jsapi10.jar
- mbrola.jar
1.2 The MBROLAzip folder will include:
1.2 MBROLAzip 文件夹将包括:
- mbrola.exe
- mbr302a (folder)
- readme.txt
- mbrola.exe
- mbr302a (文件夹)
- 自述文件
1.3 The Voicesare zipped folders that include a single folder named 'us1' or 'af1' etc.
1.3音色是压缩文件夹,其中包括一个名为“ us1”或“ af1”等的文件夹。
2. Steps to include these into my program?
2. 将这些包含到我的程序中的步骤?
NOTE:I had the MBROLA Tooklitinstalled on my computer too, however I am unsure whether it has an impact on the program, but I suspect that it doesn't. EDIT: I have tested to see whether the MBROLA toolkit is needed to run MBROLA alongside FreeTTS, and it turns out that it is not needed.
注意:我的计算机上也安装了MBROLA Tooklit,但是我不确定它是否对程序有影响,但我怀疑它没有。编辑:我已经测试过是否需要 MBROLA 工具包来与 FreeTTS 一起运行 MBROLA,结果证明不需要它。
- Extract freetts-1.2.2-bin
- Copy the libraries to your project and include in build path
- Unzip the mbr301d.zip folder
- Rename 'mbr301d' to 'mbrola'
- Unzip the voices to the folder you named 'mbrola'
- 提取 freetts-1.2.2-bin
- 将库复制到您的项目并包含在构建路径中
- 解压 mbr301d.zip 文件夹
- 将“mbr301d”重命名为“mbrola”
- 将声音解压缩到您命名为“mbrola”的文件夹中
After this is done, your mbrola folder should look like this:
完成后,您的 mbrola 文件夹应如下所示:
- [mbr302a] - folder
- [us1] - folder (name depends on the language you downloaded)
- mbrola.exe - file
- readme.txt - file
- [mbr302a] -文件夹
- [us1] -文件夹(名称取决于您下载的语言)
- mbrola.exe -文件
- readme.txt -文件
You can place all your languages in this folder, and they will just be called from your Java program.
您可以将所有语言放在此文件夹中,它们只会从您的 Java 程序中调用。
3. Simple FreeTTS example using MBROLA voices?
3. 使用 MBROLA 语音的简单 FreeTTS 示例?
I've seen many people get this error:
我见过很多人收到这个错误:
System property "mbrola.base" is undefined. Will not use MBROLA voices.
The mbrola.base
refers to where your mbrola files are located on your computer, and without the property being pointed to the correct location, you will recieve this error.
该mbrola.base
指的是你的mbrola文件位于您的计算机上,并没有财产被指向到正确的位置,您将收到此错误。
To NON-MBROLA users who get this error:Simply remove the mbrola.jar from your referenced libraries if you're only using FreeTTS
对于收到此错误的非 MBROLA 用户:如果您只使用 FreeTTS,只需从引用的库中删除 mbrola.jar
To set the mbrola.base
property, use:
要设置mbrola.base
属性,请使用:
System.setProperty("mbrola.base", "C:/Path/to/your/mbrola")
Below is a simple Example to use the MBROLA voices in your FreeTTS program. Note that the steps above must be done before this will work. Simply changing the name of the voice to "mbrola_us1" will not work if the base isn't set!
下面是在 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 and FreeTTS should now be working together! This code was copied right from my computer and has been tested before putting it down here.
MBROLA 和 FreeTTS 现在应该一起工作了!这段代码是直接从我的电脑上复制的,在把它放在这里之前已经过测试。
回答by Prashant C
Thanks to responses on this forum, I was finally able to make it working. On windows 10; I carried out following steps to make it working:
多亏了这个论坛上的回复,我终于能够让它工作了。在 Windows 10 上;我执行了以下步骤以使其正常工作:
- Download freeTTS libraries and include them in my Java project in eclipse.
- Download mbr301d.zip, extract it in a folder named mbrola within my project
- Download mbrola database for us1, us2, us3 and en1 from http://www.tcts.fpms.ac.be/synthesis/mbrola/mbrcopybin.html
- extract the voice DB zips downloaded in previous step directly in mbrola folder - don't change names of the folders.
- include following code pieces to use it:
Note: if your voice DB folder name is us1; then you should add it above as "mbrola_us1"; if it is en1, then it should be "mbrola_en1". This actually has done the trick for me.System.setProperty("mbrola.base", "ABSOLUTE_PATH_TO_mbrola_directory_ending_with_/"); voiceManager = VoiceManager.getInstance(); voice = voiceManager.getVoice("mbrola_us1");
- 下载 freeTTS 库并将它们包含在我在 Eclipse 中的 Java 项目中。
- 下载mbr301d.zip,将其解压缩到我的项目中名为 mbrola 的文件夹中
- 从http://www.tcts.fpms.ac.be/synthesis/mbrola/mbrcopybin.html下载 us1、us2、us3 和 en1 的 mbrola 数据库
- 直接在 mbrola 文件夹中提取在上一步中下载的语音数据库 zips - 不要更改文件夹的名称。
- 包括以下代码片段以使用它:
注意:如果您的语音数据库文件夹名称是 us1;那么您应该将其添加为“mbrola_us1”;如果是 en1,那么它应该是 "mbrola_en1"。这实际上对我有用。System.setProperty("mbrola.base", "ABSOLUTE_PATH_TO_mbrola_directory_ending_with_/"); voiceManager = VoiceManager.getInstance(); voice = voiceManager.getVoice("mbrola_us1");
回答by sunrise-projects
Please find working example from here:
请从这里找到工作示例:
https://github.com/sunrise-projects/sphinx4/tree/glass
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";
}