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");
}
}
上面的代码导致以下错误:
系统属性“mbrola.base”未定义。不会使用 MBROLA 声音 没有可用的语音 java.lang.NullPointerException 在 Demofreetts.doSpeak(Demofreetts.java:24) 在 Demofreetts.main(Demofreetts.java:39)