This discussion is archived
12 Replies Latest reply: Jul 16, 2010 5:10 AM by 843802 RSS

how to craete wav file using freetts

843802 Newbie
Currently Being Moderated

package tts;
import com.sun.speech.freetts.FreeTTS;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;

/**
*
* @author vijay
*/
public class Main {

/**
* @param args the command line arguments
*/
static Voice voice;
static
{      
voice=VoiceManager.getInstance().getVoice("kevin16");
if(voice!=null)
{
voice.allocate();
}
FreeTTS freetts=new FreeTTS(voice);
voice.speak("hello,world");
freetts.startup();
freetts.setAudioFile("c:/test.wav");
freetts.shutdown();
}
public static void main(String[] args) {
// TODO code application logic here
}

}


by using this code iam trying to carete a test.wav file which contains the out put produced at voice.speak() method,
but, here i can play the sound but unable to create the wav file.
how can i create wav file by using the output produced at voice.speak() method....


thanks
  • 1. Re: how to craete wav file using freetts
    843802 Newbie
    Currently Being Moderated
    i solved the problem!!
    now i can able to create wave file for giving text.

    thanks

    katta vijay
  • 2. Re: how to craete wav file using freetts
    843802 Newbie
    Currently Being Moderated
    Hi,

    Can anyone tell me how to do this?
    I have followed the above program but it is not working.

    Regards,
    Collins.
  • 3. Re: how to craete wav file using freetts
    843802 Newbie
    Currently Being Moderated
    try this piece of code...
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package com.scima;
    import com.sun.speech.freetts.FreeTTS;
    import com.sun.speech.freetts.Voice;
    import com.sun.speech.freetts.VoiceManager;
    import com.sun.speech.freetts.audio.SingleFileAudioPlayer;
    import java.io.FileInputStream;


    /**
    *
    * @author vijay
    */
    public class Main {

    /**
    * @param args the command line arguments
    */
    void call(String msg){
    System.out.println("U r here");
    Voice voice;
    FreeTTS freetts;
    System.out.println("---------**************");
    VoiceManager vm=VoiceManager.getInstance();
    System.out.println("--------------////");
    voice=vm.getVoice("kevin16");
    System.setProperty("com.sun.speech.freetts.voice.defaultAudioPlayer", "com.sun.speech.freetts.audio.SingleFileAudioPlayer");
    FileInputStream fis ;
    SingleFileAudioPlayer sfap;
    if(voice==null)
    System.out.println("voice is null");
    System.out.println("---0---");
    if(voice!=null)
    {
    voice.allocate();
    }
    System.out.println("---1---");
    freetts=new FreeTTS(voice);
    String text = new String(msg);
    byte b[] = text.getBytes();
    if(b==null)
    {
    System.out.println("no byte array");
    System.exit(1);
    }
    try
    {
    sfap = (SingleFileAudioPlayer)voice.getDefaultAudioPlayer();
    sfap.write(b);


    }
    catch(Exception e)
    {

    }
    voice.speak(msg);
    voice.deallocate();

    System.out.println("---------?????-----------");
    try {
    System.out.println("inside copy try block");
    String command="copy \"C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.18\\bin\\freetts.wav\" \"C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.18\\webapps\"";
    System.out.println("copying file from "+command);
    Runtime.getRuntime().exec("cmd.exe /c"+command);
    System.out.println("file copied");
    } catch (Exception e) {
    e.printStackTrace();
    }

    // freetts.setStreamingAudio(true);
    // freetts.urlToSpeech("http://10.0.0.109:8084/");
    System.out.println("---2---");
    // freetts.setAudioFile("c:\\test.wav");
    // freetts.shutdown();
    System.out.println("calling wav file");
    //AePlayWave aw=new AePlayWave("C:/Program Files/Apache Software Foundation/Apache Tomcat 6.0.18/bin/freetts.wav");


    System.out.println("---last---");

    }
    Main(){

    }
    // static Voice voice;
    // static FreeTTS freetts;
    // static
    // {
    // voice=VoiceManager.getInstance().getVoice("kevin16");
    // if(voice!=null)
    // {
    // voice.allocate();
    // }
    // freetts=new FreeTTS(voice);
    // voice.speak("hello,world");
    //
    // freetts.startup();
    // freetts.urlToSpeech("http://10.0.0.109:8080/");
    // freetts.setAudioFile("c:/test.wav");
    // freetts.shutdown();
    // }
    Main(String str){

    System.out.println("Inside main");
    //freetts.setAudioFile("c:/test.wav");
    }
    public static void main(String[] args)throws Exception {
    // TODO code application logic here
    }

    }
  • 4. Re: how to craete wav file using freetts
    843802 Newbie
    Currently Being Moderated
    Hi,

    Thx for replying...i'm facing the below problem..

    i'm getting NullPointerException at
    sfap = (SingleFileAudioPlayer)voice.getDefaultAudioPlayer();

    i have this class file in freetts.jar

    can u suggest a solution for this problem.
  • 5. Re: how to craete wav file using freetts
    843802 Newbie
    Currently Being Moderated
    i think this is the problem with availability of jar files,
    add total jar file to your class path.
  • 6. Re: how to craete wav file using freetts
    843802 Newbie
    Currently Being Moderated
    Hi,

    Added follwing JAR files....

    freetts.jar
    jsapi.jar
    en_us.jar
    cmutimelex.jar
    cmulex.jar
    cmu_time_awb.jar
    cmu_us_kal.jar
    cmudict04.jar

    Any other JAR file required?
  • 7. Re: how to craete wav file using freetts
    843802 Newbie
    Currently Being Moderated
    once copy the all those jar file to jre\lib\ext here and try again!!

    which type of application ur developing web based or standalone ...
  • 8. Re: how to craete wav file using freetts
    843802 Newbie
    Currently Being Moderated
    I'm developing standalone in Eclipse IDE.
  • 9. Re: how to craete wav file using freetts
    843802 Newbie
    Currently Being Moderated
    first test the sample application for playing the text,
    if so, according to my knowledge this is also works.

    make sure that speech.properties file should be in either user home or java home.

    still you have problem fell free to ask us.

    katta vijay
  • 10. Re: how to craete wav file using freetts
    843802 Newbie
    Currently Being Moderated
    This has become such a nightmare, I'm about to pull my hair out. I won't give up though.
  • 11. Re: how to craete wav file using freetts
    843802 Newbie
    Currently Being Moderated
    Hello. I need develop a webservice that return a .wav or .au that generate wiht the input text.
    how Can i do it?
  • 12. Re: how to craete wav file using freetts
    843802 Newbie
    Currently Being Moderated
    Hi,

    I just copied the example code you gave into the Netbeans IDE, and am unsure what is to be un-commented or not, as nothing happens when I run the file. Unless I am doing something wrong.

    I'd really like to get it working, as I am doing something similar in my undergraduate final year project, and have been stuck on getting it to output for days!!

    thanks,
    Fiona