Troubleshooting “System property mbrola.base is un

2019-08-17 15:58发布

问题:

 import com.sun.speech.freetts.*;
 import java.util.*; 

 public class Demofreetts
  {
   private String speaktext;
   public void doSpeak(String speak, String voice)
    {
     speaktext = speak;
     try
      {
       VoiceManager voiceManager = VoiceManager.getInstance();
       Voice voices = voiceManager.getVoice(voice);
       Voice sp = null;

       if(voices != null)
         sp = voices;

       else
         System.out.println("No Voice Available");



        sp.allocate();
        sp.speak(speaktext);
        sp.deallocate();



      }
     catch(Exception e)
      {
       e.printStackTrace();
      }
    }
   public static void main(String[]args)
   {
    Demofreetts obj = new Demofreetts();
    obj.doSpeak(args[0],"Kelvin16");
   }
  } 

The above code causes the following error:

System property "mbrola.base" is undefined.  Will not use MBROLA voices
No Voice Available
java.lang.NullPointerException
        at Demofreetts.doSpeak(Demofreetts.java:24)
        at Demofreetts.main(Demofreetts.java:39)

回答1:

You can convert the text to speech in Java using freetts1.2 API. It is quite simple to use. This link could be useful for you. It has an example program

http://learnsharelive.blogspot.com/2011/01/convert-text-to-speech-java-freetts12.html



回答2:

just add System.setProperty

  System.setProperty("mbrola.base", "C:\\Users\\iup\\workspace\\newpro\\mbrola");
  VoiceManager voiceManager = VoiceManager.getInstance();



回答3:

Here is the solution

Change the string voice parameter to one of the following.

1.kevin16 (all letters should be written in small case) 2.alan (this is also your next option alternate to kevin16 voice. but the message System property "mbrola.base" is undefined. Will not use MBROLA voices. Still exist but you can get the voice that you need.fortunately you can solve this problem by setting the property of mbrola voice. Using

     System.setProperty (" mbrola.base" ,"here the pathof property");.

Anyways it works for me please give it a try.