Announcement :

Try our newly launched website www.Technicalbaba.com Token Number - 1techbaba1

Sunday 20 October 2013

Text to speech converter in java



So are you really want to talk with your computer ? 
Need java code to do it for you ?

You are at correct place so start with very start ...


A Java Program which can speak :)





Follow these steps and start -


Step 1 - 

You need to download api freetts for text to speech converter in java. don't get panic here is the link - Download Freetts Package


done  :)

you can refer document for your ease - Refer Document 


Step 2 - 

Now setup environment is as follows -

a) extract freetts package 


b) navigate to lib folder and double click on jsapi exe file. it will create a jsapi jar file.

c) Copy speech.properties file from  freetts folder to home directory folder. ie. if your computer name is ABC then your home directory will be like - C:\Users\ABC


done :)


Step 3 - 

Open NetBeans IDE and add usable packages - 

a) Create a new project ie. TextToSpeech

b)  Right click on your project TextToSpeech click on properties.










c) Now a new pop up window will appear , now click on "Libraries" from left pane.  

d) Now click on add jar/folder tab and add these jar files in same order as given bellow - 

now go to lib folder and add these jar files :

1. en_us.jar

2. mbrola.jar
3. jsapi.jar
4. freetts-jsapi10.jar
















Step 4 - Now start code work. write a java file named as -  Text2Speech



Code -


import javax.speech.*;
import java.util.*;
import javax.speech.synthesis.*;

public class Text2Speech
{
    String speaktext;

    public void dospeak(String speak,String  voicename)
    {
        speaktext=speak;
        String voiceName =voicename;
        try
        {
            SynthesizerModeDesc desc = new SynthesizerModeDesc(null,"general",  Locale.US,null,null);
            Synthesizer synthesizer =  Central.createSynthesizer(desc);
            synthesizer.allocate();
            synthesizer.resume();
            desc = (SynthesizerModeDesc)  synthesizer.getEngineModeDesc();
            Voice[] voices = desc.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);
            System.out.print("Speaking : "+speaktext);
            synthesizer.speakPlainText(speaktext, null);
            synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
            synthesizer.deallocate();
        }
        catch (Exception e)
        {
            String message = " missing speech.properties in " + System.getProperty("user.home") + "\n";
            System.out.println(""+e);
            System.out.println(message);
        }
    }

    public static void main(String[] args)
    {
        Text2Speech obj=new Text2Speech(); obj.dospeak("Shashank Mishra I M S Engineering college ghaziabad","kevin16");
    }
}



Now save file and run.

Note -  always run jar file , you can find jar file of your project in dist folder.


Output - 













Feeling any problem ? feel free to leave comment .
Or Try our video tutorial -




don't miss to like our facebook page for further updates.




Share it Please

Unknown

He is a blogger/website designer and developer.he is founder of www.technicalbaba.com and also loves web programming.

17 comments:

  1. working nice , finally got a good solution , thanks.

    ReplyDelete
  2. why this exception?

    Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/speech/freetts/ValidationException

    ReplyDelete
    Replies
    1. speech.properties file copied to your home or not ???

      Delete
    2. This comment has been removed by the author.

      Delete
  3. Im getting Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/speech/freetts/ValidationException

    used to get another error, but then i putted the speech.properties at my home folder, then i just get that one.

    ReplyDelete
  4. getting this eror java.lang.IllegalThreadStateException

    ReplyDelete
  5. add these jar files :

    1. en_us.jar
    2. mbrola.jar
    3. jsapi.jar
    4. freetts-jsapi10.jar

    in same order as given here , copy speech.prop file to your home folder ..

    and then let me know , what is the whole problem .

    ReplyDelete
  6. Or remove the synth.deallocate(); from code and then try.

    ReplyDelete
  7. Add all the jars in lib. Then that classDefnotfound error won't come.

    ReplyDelete
  8. Replies
    1. To run by cmd follow these steps -

      1) Add jar files to your classpath
      2) Compile your code
      3) Convert it to jar file
      4) Run it.

      Delete
  9. Instead of kevin16.. can i use female voices.. I tried using mbrola but didnt work. pplease let me know how to use female voices?

    ReplyDelete
  10. I like it most.10000000000000 likes from me. This is very helpful post for me. Thank you..

    ReplyDelete
  11. hello ! i have problem that this code gets compiled successfully but when i run it displays nullPointerException

    ReplyDelete
  12. Thanks for sharing this amazing post plz visit Text Speaker 3.3 Full Crack

    ReplyDelete
  13. Are you a YouTuber? A content creator? Or a movie maker?
    As a result, you might need voice services.
    You can try this tool to listen to the natural pronunciations from a ton of languages: Talk With AI. It is a FREE online tool to convert text into audio files
    https://tts.adcrew.us
    Intro Video:
    https://youtu.be/NaWcJr07UTM
    How to Use:
    https://youtu.be/p_Hk7Hi4obo

    ReplyDelete

We welcome's you to post your comments here , Our editorial team will review and reply to your valuable comment.Thank you to connect with us.














1. HTC offers bloggers to write a post for us , you can use your links too.


2. HTC offers ad networks to publish their ads in very low cost.


Copyright @ 2013 Ability 2 Crack. Designed by Templateism | Re-designed By Shashank MIshra