简体   繁体   English

如何更改Java的TTS语音

[英]How to Change voice of TTS for Java

I am using FreeTTS to speak out some text in my java program. 我正在使用FreeTTS在我的Java程序中说出一些文本。 I want to embed MBROLA Voices in it. 我想将MBROLA声音嵌入其中。 I followed the instructions , but I got stuck here: 我遵循了说明 ,但是我被卡在这里:

Enable FreeTTS Support for MBROLA 为MBROLA启用FreeTTS支持

To enable FreeTTS support for MBROLA, merely copy mbrola/mbrola.jar to lib/mbrola.jar. 要启用对MBROLA的FreeTTS支持,只需将mbrola / mbrola.jar复制到lib / mbrola.jar。 Then, whenever you run any FreeTTS application, specify the "mbrola.base" directory as a system property: 然后,无论何时运行任何FreeTTS应用程序,都将“ mbrola.base”目录指定为系统属性:

java -Dmbrola.base=/home/jim/mbrola -jar bin/FreeTTSHelloWorld.jar mbrola_us1

In the tutorial what they are doing is, they type this line in cmd to make a jar file speak in the voice they are telling (us1) but what i have to do is that, i already have a java program and i want to change the voice it speaks. 在本教程中,他们正在做的是,他们在cmd中键入此行以使jar文件以他们正在说的声音(us1)说话,但是我要做的是,我已经有一个Java程序,我想更改它说话的声音。 How to do this? 这个怎么做?

I tried to change the vm options but that does not help. 我试图更改vm选项,但这无济于事。

Note: I am using Netbeans IDE and i also have the file 'FreeTTSHelloWorld.jar' 注意:我正在使用Netbeans IDE,并且我也有文件'FreeTTSHelloWorld.jar'

So in short, i am looking for a clear explanation on how to proceed/add MBROLA Voices into FreeTTS library in java(for a newbie)... 简而言之,我正在寻找有关如何继续/将MBROLA音色添加到Java中的FreeTTS库中的明确解释(对于新手)...

What do you say? 你说什么? should i consider changing my OS to Ubuntu for Java Development??? 我应该考虑将操作系统更改为Ubuntu进行Java开发吗???

Into the terminal:-)This means you need to run your program from command line, here is nice tutorial how to do that. 进入终端:-)这意味着您需要从命令行运行程序, 是一个不错的教程。

But I think it can be also run from the NetBeans, go to the Properties of your project, go to Run and paste -Dmbrola.base=/home/jim/mbrola into VM options . 但是我认为也可以从NetBeans运行它,转到项目的Properties ,转到Run ,然后将-Dmbrola.base=/home/jim/mbrolaVM options You will of course need FreeTTSHelloWorld.jar on the classpath (you can add it through Properties -> Libraries -> Add JAR/Folder ). 当然,您将在类路径上需要FreeTTSHelloWorld.jar (可以通过Properties -> Libraries -> Add JAR/Folder来添加它)。

-D is used to provide a system property to your java program. -D用于为Java程序提供系统属性。 So you need to provide it while running your java program: 因此,您需要在运行Java程序时提供它:

java -Dmbrola.base=/home/jim/mbrola -jar bin/FreeTTSHelloWorld.jar mbrola_us1 yourJavaClass

If you are using an IDE such as eclipse then you can do the same by going to: 如果您使用的是诸如eclipse之类的IDE,则可以执行以下操作:

Run -> Run configurations, select project, second tab: “Arguments”. 运行->运行配置,选择项目,第二个选项卡:“参数”。 Top box is for your program, bottom box is for VM arguments, eg -Dmbrola.base=/home/jim/mbrola -jar bin/FreeTTSHelloWorld.jar mbrola_us1 顶部框用于您的程序,底部框用于VM参数,例如-Dmbrola.base = / home / jim / mbrola -jar bin / FreeTTSHelloWorld.jar mbrola_us1

Have you tried something like: 您是否尝试过类似的方法:

public static void main(String[] args) {
    System.setProperty("mbrola.base", "your/mbrola/base/directory");
    VoiceManager voiceManager = VoiceManager.getInstance();
    String voice = "mbrola_us1";
    Voice helloVoice = voiceManager.getVoice(voice);
    if (helloVoice == null) {
        Voice[] availableVoices = voiceManager.getVoices();
        List<String> voiceList = new ArrayList<>();
        for (Voice v : availableVoices) voiceList.add(v.getName());
        System.out.println("Not a valid voice: " + voice + "\nValid voices: " + voiceList);
        return;
    }
    helloVoice.allocate();

    /* Synthesize speech. */
    helloVoice.speak("Thank you for giving me a voice. " + "I'm so glad to say hello to this world.");

    /* Clean up and leave. */
    helloVoice.deallocate();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM