Page 1 of 2 12 LastLast
Results 1 to 20 of 30
  1. #1
    chaminga is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Post java speech Synthesizer

    i'm new to java speech api. and i want to build simple java speech application. This is the code

    Java Code:
    import javax.speech.*;
    import javax.speech.synthesis.*;
    import java.util.Locale;
    
    public class HelloWorld {
    	public static void main(String args[]) {
    		try {
    			// Create a synthesizer for English
    			Synthesizer synth = Central.createSynthesizer(
    				new SynthesizerModeDesc(Locale.ENGLISH));
    
    			// Get it ready to speak
    			synth.allocate();
    			synth.resume();
    
    			// Speak the "Hello world" string
    			synth.speakPlainText("Hello, world!", null);
    
    			// Wait till speaking is done
    			synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
    
    			// Clean up
    			synth.deallocate();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    }
    when i use this code it gives java.lang.NullPointerException.
    I would be great full if anybody can explain the reason for the exception.

    Reguards
    Chaminga.
    Last edited by Eranga; 07-07-2010 at 05:58 AM. Reason: code tags added

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    And also please use the code tags next time when you are posting here in the forum. Unformated codes are really hard to read. If you don't know how to do it, check my forum signature.

  4. #4
    chaminga is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Default

    I would be really thank full to your reply.
    Complete error message is
    java.lang.NullPointerException at HelloWorld.main(HelloWorld.java:17)

  5. #5
    chaminga is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Default

    Error occurred because of synth.allocate();

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    What you've on line 17? I cannot see any line numbers, so it's better to sent it.

    Actually what you've post in the above post is not the complete error, or the stack trace you comes with. Post the complete message.

  7. #7
    chaminga is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Default

    line 17th is synth.allocate();
    may i know the reason for the Nullpoint Exception.
    thank you

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  9. #9
    chaminga is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Default

    hmmmm i checked :(

    really really thankful to ur help.

  10. #10
    chaminga is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Default

    hmmmm i checked :(

    really really thankful to ur help.

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default

    Quote Originally Posted by chaminga View Post
    line 17th is synth.allocate();
    may i know the reason for the Nullpoint Exception.
    thank you
    Have you actually installed one of the available speech systems? Note that this Java extension (javax.speech) just offers the 'Java way' of a speech synthesis system, you need an actual system to do the job; compare this with the jdbc framework: you still need a database engine to do the job; the jdbc classes just give you the API.

    kind regards,

    Jos

  12. #12
    chaminga is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Default

    Thank u jos.

    Do i need to install any other application to avoid this problem.

    regards,
    Malmi.

  13. #13
    chaminga is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Default

    What is FreeTTS 1.2
    is that support for java speech api.

    regards,
    Chaminga.

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default

    Quote Originally Posted by chaminga View Post
    What is FreeTTS 1.2
    is that support for java speech api.

    regards,
    Chaminga.
    Yes, use that one; I did the same today and incorporated it in my own private language; it comes with two APIs: its own and the JSAPI stuff; it's a bit of a hassle to install everything properly but it works with a few different voices and they keep on whining about a 'mbrola' database not being installed; the documentation tells you more about that mbrola initiative (it doesn't run properly with MS Windows).

    kind regards,

    Jos

  15. #15
    chaminga is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Default

    Thank u Jos.

    Regards,
    Chaminga.

  16. #16
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default

    Quote Originally Posted by chaminga View Post
    Thank u Jos.
    You're welcome of course; so which interface did you use? The official (but a bit stripped down) JSAPI or FreeTTS's own interface? I used the latter because for me the JSAPI didn't work (I still have to figure out what I did wrong).

    kind regards,

    Jos

  17. #17
    chaminga is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Default

    Hi Jos,

    I tried using FreeTTS but still i cannot find the reason for the error.
    I really really want to build speaking application but i'm still on the start. :(

    regards,
    Chaminga.

  18. #18
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default

    Quote Originally Posted by chaminga View Post
    I tried using FreeTTS but still i cannot find the reason for the error.
    What errors? This is my little test program and it works (you have to make most of the jars visible in the ./lib folder). Note the nasty mbrola blahblahblah message on stdout. Also note that I'm using freeTTS's own API ...

    Java Code:
    import com.sun.speech.freetts.Voice;
    import com.sun.speech.freetts.VoiceManager;
    
    public class T {
    
        public static void main(String[] args) {
    
            String voiceName = "kevin16"; // the only usable general purpose voice
    
            VoiceManager voiceManager = VoiceManager.getInstance();
            
            Voice voice = voiceManager.getVoice(voiceName);
    
            // some effects:
            // helloVoice.setPitch(20.0f);
            // helloVoice.setDurationStretch(0.3f);
            // helloVoice.setRate(100.0f);
            // helloVoice.setVolume(1.0f);
            
            voice.allocate();        
            voice.speak("Oh man this is a crappy voice");
            voice.deallocate();
        }
    }
    kind regards,

    Jos

  19. #19
    chaminga is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Default

    I used this code

    then i got this error. May i know the reason for that sir.


    System property "mbrola.base" is undefined. Will not use MBROLA voices.
    Jul 8, 2010 2:30:13 PM com.sun.speech.freetts.Voice allocate
    SEVERE: Can't load voice java.util.zip.ZipException: ZipFile closed
    Exception in thread "main" java.lang.Error: java.util.zip.ZipException: ZipFile closed
    at com.sun.speech.freetts.Voice.allocate(Voice.java:3 51)
    at T.main(T.java:21)
    Caused by: java.util.zip.ZipException: ZipFile closed
    at java.util.zip.ZipFile.ensureOpenOrZipException(Zip File.java:413)
    at java.util.zip.ZipFile.access$1100(ZipFile.java:29)
    at java.util.zip.ZipFile$ZipFileInputStream.read(ZipF ile.java:445)
    at java.util.zip.ZipFile$1.fill(ZipFile.java:230)
    at java.util.zip.InflaterInputStream.read(InflaterInp utStream.java:141)
    at java.io.FilterInputStream.read(FilterInputStream.j ava:116)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.j ava:264)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.ja va:306)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:1 58)
    at java.io.InputStreamReader.read(InputStreamReader.j ava:167)
    at java.io.BufferedReader.fill(BufferedReader.java:13 6)
    at java.io.BufferedReader.readLine(BufferedReader.jav a:299)
    at java.io.BufferedReader.readLine(BufferedReader.jav a:362)
    at com.sun.speech.freetts.en.us.PronounceableFSM.load Text(PronounceableFSM.java:91)
    at com.sun.speech.freetts.en.us.PronounceableFSM.<ini t>(PronounceableFSM.java:60)
    at com.sun.speech.freetts.en.us.PrefixFSM.<init>(Pref ixFSM.java:26)
    at com.sun.speech.freetts.en.us.CMUVoice.setupUtteran ceProcessors(CMUVoice.java:116)
    at com.sun.speech.freetts.en.us.CMUVoice.loader(CMUVo ice.java:77)
    at com.sun.speech.freetts.Voice.allocate(Voice.java:3 48)
    ... 1 more




    regards,
    Chaminga.

  20. #20
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default

    Quote Originally Posted by chaminga View Post
    I used this code

    then i got this error. May i know the reason for that sir.


    System property "mbrola.base" is undefined. Will not use MBROLA voices.
    Jul 8, 2010 2:30:13 PM com.sun.speech.freetts.Voice allocate
    SEVERE: Can't load voice java.util.zip.ZipException: ZipFile closed
    Exception in thread "main" java.lang.Error: java.util.zip.ZipException: ZipFile closed
    at com.sun.speech.freetts.Voice.allocate(Voice.java:3 51)
    at T.main(T.java:21)
    Caused by: java.util.zip.ZipException: ZipFile closed
    at java.util.zip.ZipFile.ensureOpenOrZipException(Zip File.java:413)
    at java.util.zip.ZipFile.access$1100(ZipFile.java:29)
    at java.util.zip.ZipFile$ZipFileInputStream.read(ZipF ile.java:445)
    at java.util.zip.ZipFile$1.fill(ZipFile.java:230)
    at java.util.zip.InflaterInputStream.read(InflaterInp utStream.java:141)
    at java.io.FilterInputStream.read(FilterInputStream.j ava:116)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.j ava:264)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.ja va:306)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:1 58)
    at java.io.InputStreamReader.read(InputStreamReader.j ava:167)
    at java.io.BufferedReader.fill(BufferedReader.java:13 6)
    at java.io.BufferedReader.readLine(BufferedReader.jav a:299)
    at java.io.BufferedReader.readLine(BufferedReader.jav a:362)
    at com.sun.speech.freetts.en.us.PronounceableFSM.load Text(PronounceableFSM.java:91)
    at com.sun.speech.freetts.en.us.PronounceableFSM.<ini t>(PronounceableFSM.java:60)
    at com.sun.speech.freetts.en.us.PrefixFSM.<init>(Pref ixFSM.java:26)
    at com.sun.speech.freetts.en.us.CMUVoice.setupUtteran ceProcessors(CMUVoice.java:116)
    at com.sun.speech.freetts.en.us.CMUVoice.loader(CMUVo ice.java:77)
    at com.sun.speech.freetts.Voice.allocate(Voice.java:3 48)
    ... 1 more




    regards,
    Chaminga.
    Not all the .jar files are visible from your class (also reread my previous reply). For the time being stick them all in the lib/ext directory of your JRE so they always can be found. You need all the cmu*.jar files, the en_us.jar file, freetts, jsapi, mbrola and the voices jar files.

    kind regards,

    Jos

Page 1 of 2 12 LastLast

Similar Threads

  1. Speech in Web Application
    By vinoopraj in forum Advanced Java
    Replies: 0
    Last Post: 06-23-2010, 11:27 AM
  2. Speech Recognition In Java
    By hackernewbie in forum Advanced Java
    Replies: 6
    Last Post: 01-18-2010, 11:06 PM
  3. Java Speech Processing
    By redvirus in forum CLDC and MIDP
    Replies: 2
    Last Post: 10-03-2009, 12:16 AM
  4. Help with Java Speech API (Synthesizer)
    By mohitkhanna3v_infinate in forum Advanced Java
    Replies: 1
    Last Post: 07-23-2009, 06:21 PM
  5. Java Speech Recognizer
    By Lynx09 in forum Advanced Java
    Replies: 0
    Last Post: 03-30-2009, 08:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •