MBROLA voices with FreeTTS - Windows

前端 未结 3 524
无人及你
无人及你 2020-12-03 13:09

Using MBROLA voices in a Java program with FreeTTS...

I am working on a simple text-to-speech program in Java. I have decided to use FreeTT

相关标签:
3条回答
  • 2020-12-03 13:43

    Please find working example from here:

    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";
    }

    0 讨论(0)
  • 2020-12-03 13:45

    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:

    1. Download freeTTS libraries and include them in my Java project in eclipse.
    2. Download mbr301d.zip, extract it in a folder named mbrola within my project
    3. Download mbrola database for us1, us2, us3 and en1 from http://www.tcts.fpms.ac.be/synthesis/mbrola/mbrcopybin.html
    4. extract the voice DB zips downloaded in previous step directly in mbrola folder - don't change names of the folders.
    5. include following code pieces to use it:
      System.setProperty("mbrola.base", "ABSOLUTE_PATH_TO_mbrola_directory_ending_with_/");
      voiceManager = VoiceManager.getInstance();
      voice = voiceManager.getVoice("mbrola_us1");
      
      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.
    0 讨论(0)
  • 2020-12-03 13:50

    Answers to the questions above:

    1. What files need to be downloaded?

    1. FreeTTS with all the libraries (freeTTS 1.2.2-bin) - download here
    2. MBROLA zip folder mbr301d.zip
    3. Voices which can be found on the MBROLA website

    1.1 The FreeTTS libraries (found in 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

    1.2 The MBROLA zip folder will include:

    • mbrola.exe
    • mbr302a (folder)
    • readme.txt

    1.3 The Voices are zipped folders that include a single folder named 'us1' or 'af1' etc.


    2. Steps to include these into my program?

    NOTE: I had the MBROLA Tooklit installed 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.

    1. Extract freetts-1.2.2-bin
    2. Copy the libraries to your project and include in build path
    3. Unzip the mbr301d.zip folder
    4. Rename 'mbr301d' to 'mbrola'
    5. Unzip the voices to the folder you named 'mbrola'

    After this is done, your mbrola folder should look like this:

    • [mbr302a] - folder
    • [us1] - folder (name depends on the language you downloaded)
    • mbrola.exe - file
    • readme.txt - file

    You can place all your languages in this folder, and they will just be called from your Java program.


    3. Simple FreeTTS example using MBROLA voices?

    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.

    To NON-MBROLA users who get this error: Simply remove the mbrola.jar from your referenced libraries if you're only using FreeTTS

    To set the mbrola.base property, use:

    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!

    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.

    0 讨论(0)
提交回复
热议问题