1

I am using FreeTTS to speak out some text in my java program. I want to embed MBROLA Voices in it. I followed the instructions, but I got stuck here:

Enable FreeTTS Support for MBROLA

To enable FreeTTS support for MBROLA, merely copy mbrola/mbrola.jar to lib/mbrola.jar. Then, whenever you run any FreeTTS application, specify the "mbrola.base" directory as a system property:

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. How to do this?

I tried to change the vm options but that does not help.

Note: I am using Netbeans IDE and i also have the file '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)...

What do you say? should i consider changing my OS to Ubuntu for Java Development???

Daksh Shah
  • 2,997
  • 6
  • 37
  • 71

3 Answers3

4

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. You will of course need FreeTTSHelloWorld.jar on the classpath (you can add it through Properties -> Libraries -> Add JAR/Folder).

Petr Mensik
  • 26,874
  • 17
  • 90
  • 115
  • What do you mean by "You will of course need FreeTTSHelloWorld.jar on the classpath." - i dint get you – Daksh Shah Jan 03 '14 at 13:53
  • Exactly "FreeTTSHelloWorld.jar"?? – Daksh Shah Jan 03 '14 at 13:54
  • It's a library you are passing to your command so I guess you need it in order to run your application. – Petr Mensik Jan 03 '14 at 13:55
  • Sure, the GUI will help you select it:) – Petr Mensik Jan 03 '14 at 13:55
  • Cant i type the whole "java -Dmbrola.base=/home/jim/mbrola -jar bin/FreeTTSHelloWorld.jar mbrola_us1 yourJavaClass" instead of just "-Dmbrola.base=/home/jim/mbrola"?? – Daksh Shah Jan 03 '14 at 13:56
  • No, you can't, `java` is a tool which comes directly from JRE and it's meant to run compiled Java programs. And it can have various parameters, one of them is `-DtypeAnyPropertyYouWant` and this is what you need to fill in in the NetBeans `VM options` field. – Petr Mensik Jan 03 '14 at 13:58
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/44424/discussion-between-daksh-shah-and-petr-mensik) – Daksh Shah Jan 03 '14 at 14:15
1

-D is used to provide a system property to your java program. So you need to provide it while running your java program:

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:

Run -> Run configurations, select project, second tab: “Arguments”. Top box is for your program, bottom box is for VM arguments, e.g. -Dmbrola.base=/home/jim/mbrola -jar bin/FreeTTSHelloWorld.jar mbrola_us1

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
0

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();
}
assylias
  • 321,522
  • 82
  • 660
  • 783
  • This seems a bit complicated, so i will set up a new separate project to test this out first; so i have to create a new project according to FreeTTS, make sure that FreeTTS Work and then follow the tutorial, download the voices and MBROLA and all and then copy paste this code? – Daksh Shah Jan 05 '14 at 16:21
  • @DakshShah You can just insert that code in your existing Java program - the if block is not required, it is there in case `mbrola_us1` is not found, to show you what other voices are available. Note that I have never used that library or tested that code but based on their tutorial it should work. – assylias Jan 05 '14 at 16:26
  • Can you please help me, with chatting? if you are free – Daksh Shah Jan 05 '14 at 16:38
  • @DakshShah In the tutorial you linked, it is the "*base directory to put both MBROLA binary and MBROLA voice databases*" that they call `/home/jim/mbrola`. So wherever you placed those files. – assylias Jan 05 '14 at 17:20
  • I am using windows and those guys are using MAC, so when i was following the tutorial again this time, they said that download the binaries install them and then in a folder do all that stuff. Maybe for mac users this makes sense but not for me. When i went to their downloads for windows, they had a exe, i downloaded and installed it. But where is that folder they keep talking about is? I also looked up at the place i have installed it (in C Drive) in a README they said if you have unpacked the rar successfully... but there is no RAR. What to do? I am a windows guy. (Sorry if i sound lame) – Daksh Shah Jan 05 '14 at 17:41
  • And if i compare files listed in the tutorial with the place my files installed some of them are same but the thing is that the main file is mbroli.exe (i can send a list of all if req.) but if it is so it is just a click and run application :P – Daksh Shah Jan 05 '14 at 17:44
  • Not sure to be honest - I have not used that library so I don't know how to install it... Sorry I could not help. – assylias Jan 05 '14 at 17:49
  • No No you did help, i will figure that part out on myself; tell me that if my folder resides in "C:\Program Files (x86)\Mbrola Tools" do i have to type this in java? – Daksh Shah Jan 05 '14 at 17:51
  • You can try `"C:/Program Files (x86)/Mbrola Tools"` or `"C:\\Program Files (x86)\\Mbrola Tools"` - one of the two should work. – assylias Jan 05 '14 at 17:57
  • and also... your "List voiceList = new ArrayList<>();" shows error; can you please tell me what should be the correct line instead of this – Daksh Shah Jan 05 '14 at 17:58
  • Yah i already tried with "C:\\Program Files (x86)\\Mbrola Tools" [studied about these escape characters in C :P] – Daksh Shah Jan 05 '14 at 17:59
  • @DakshShah The error on list can be either because you are missing an import or because you use Java 6 or below (in which case it's time to upgrade!): in that case, try `List voiceList = new ArrayList();` instead. – assylias Jan 05 '14 at 18:00
  • 1
    it shows error: run: Could not validate any MBROLA voices at C:\Program Files (x86)\Mbrola Tools Make sure you FULLY specify the path to the MBROLA directory using the mbrola.base system property. Exception in thread "main" java.lang.NullPointerException at embed.Embed.main(Embed.java:20) Java Result: 1 – Daksh Shah Jan 05 '14 at 18:04
  • At least it seems to have read the directory properly. Not sure what those files are - are you sure there are in that folder? – assylias Jan 05 '14 at 18:12
  • Yes they are but the main file is mbroli.exe and not some mbrola(there is one mbrola.txt) so i think that is the problem. But if i rename mbroli.exe to mbrola.exe and run the java program the java program executes by opening me up the mbrola.exe and poping some msg in it and then if i close that window, it ends with "Processing Utterance: com.sun.speech.freetts.ProcessException: No audio data read" in Netbeans. By the way, that mbroli.exe opens some kind of windows in which you can enter the text and then click the speak button. a view (https://www.dropbox.com/s/3a1chbhpj90a0li/Mbroli.png) – Daksh Shah Jan 05 '14 at 18:18
  • But the drawback in mbroli is that, that right now it just shows us1 not us2 and us3 and it is also not able to speak out anything. but i can make that work(it once worked yesterday but i have reinstalled; but i think i can make that work) but the point is that what i want is that like in the sample program it should say that text "Hello wor...." in a nice (us1) voice directly and not open a separate window for user to enter the text.. :( – Daksh Shah Jan 05 '14 at 18:21