解决方案 »

  1.   


    synthesizer.speak("Hello I am a <PROS PITCH=\"10%\">computer</PROS>", null);这个意思?
      

  2.   


    按照你这个意思修改了下,然后又出现了另外两个错误,一一改正后代码如下:
    import javax.speech.Central;
    import javax.speech.EngineException;
    import javax.speech.synthesis.*;
    public class TrySpeech {
    static Synthesizer synthesizer;
    public static void main(String[] args) {
    try {
    synthesizer = Central.createSynthesizer(null);
    synthesizer.allocate();  //这行运行时抛出空指针异常
    } catch (EngineException e) { }
    try { synthesizer.speak("Hello I am a computer", null);
    synthesizer.speak("Hello I am a <EMP>computer</EMP>", null);
    synthesizer.speak(
    "Hello I am a <PROS PITCH=\" 10% \">computer</PROS>", null);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }然后运行的时候出现抛出异常:Exception in thread "main" java.lang.NullPointerException
    at traslation.TrySpeech.main(TrySpeech.java:14)补充一些这段代码的功能:
     这段代码是为了实现Java Speech API中的语音合成,并使用 JSML 来控制合成器朗读文本的方式(定义音高、速度、重音等等)原先我是没有javax.speech这个包的,在CSDN下载了一个别人上传的这个包,没有源代码,不知道这个抛出空指针异常如何解决?
      

  3.   

    下载地址
    http://sourceforge.net/projects/jsapi/?source=typ_redirectDoc
    http://docs.oracle.com/cd/E17802_01/products/products/java-media/speech/forDevelopers/jsapi-doc/你的异常很显然是
    synthesizer = Central.createSynthesizer(null);
    返回null,扫了一眼doc里面
    createSynthesizerpublic static final Synthesizer createSynthesizer(EngineModeDesc require)
                                                                     throws IllegalArgumentException,
                                                                            EngineException
    Create a Synthesizer with specified required properties. If there is no Synthesizer with the required properties the method returns null.其他的就祝你好运了
      

  4.   


    谢谢伱的用心回帖,我会再仔细看看Doc的 ( ^_^ )