0

Fairy new to programming, 2nd post here. I'm attempting to make a personal project that takes an article(like a reddit article) and saves it to an mp3 or wav file that can be burned to a CD and listened to. I am using the java JSoup library to grab the paragraph elements from the article and save them to a .txt file, which is working. I am also using java swing with freetts(currently in a separate project) to convert text to speech, which is also working. My best guess as to the next step is to get the freetts to save the text to an audio file. Im trying to use a method called dumpAudio that i found on the freetts site, and i cant get it to work. So my question is,what am i doing wrong?

Here is my attempt at this(i only included the freetts code for brevity):

public class MyRedditProject extends javax.swing.JFrame {
// code is from https://www.youtube.com/watch?v=swuYhvwHw9w
/**
 * Creates new form RedditProject
 */
public MyRedditProject() {
    initComponents();
}

@SuppressWarnings("unchecked")


private static final String VOICENAME = "kevin16";
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    Voice voice;
    VoiceManager vm = VoiceManager.getInstance();
    voice = vm.getVoice(VOICENAME);

    voice.allocate();

    try
    {
       voice.speak(jTextArea1.getText());
       //trying to use dumpAudio to save text to audio file. I found the
       //dumpAudio method on the freetts site
         vm.dumpAudio("C:\\Users\\david\\Documents\\Reddit_Project\\dumpAudio.wav");          
    }             
    catch(Exception e)
    {

    }
progyammer
  • 1,498
  • 3
  • 17
  • 29
doc29
  • 79
  • 1
  • 7
  • 1
    in the `VoiceManager` [documentation](http://freetts.sourceforge.net/javadoc/com/sun/speech/freetts/VoiceManager.html) there is no `dumpAudio()` method, how are you calling it from the vm instance? – aleb2000 Nov 04 '16 at 15:11
  • 4
    It is also a superbad idea to go with an **empty** catch block. If that thing fails, wouldn't you be interested in error messages?! Then: you should separate *concerns* here. The code that "dumps" to audio has **nothing** to do with AWT, events, whatever. Start with a simple static main that does nothing else but takes text and turns that into audio! And when that works; **then** put an UI around it. – GhostCat Nov 04 '16 at 15:16
  • you're right. Here's where i saw the dumpAudio() method. http://freetts.sourceforge.net/docs/index.php#test_program – doc29 Nov 04 '16 at 15:16
  • 2
    This answer may help you: http://stackoverflow.com/questions/4027853/how-can-i-store-output-voice-to-an-audio-file-in-freetts – aleb2000 Nov 04 '16 at 15:17
  • 1
    Looks like Voice has a [setAudioPlayer](http://freetts.sourceforge.net/javadoc/com/sun/speech/freetts/Voice.html#setAudioPlayer(com.sun.speech.freetts.audio.AudioPlayer)), which can be set to a [SingleFileAudioPlayer](http://freetts.sourceforge.net/javadoc/com/sun/speech/freetts/audio/SingleFileAudioPlayer.html). – pathfinderelite Nov 04 '16 at 15:18
  • 1
    There is no `dumpAudio()` method, the one you have seen are arguments you may pass to the freetts test program. – aleb2000 Nov 04 '16 at 15:19
  • 1
    *"Im trying to use a method called dumpAudio that i found on the freetts site"* Link? Or do you expect us to guess that code? In fact, For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). Preferably of just saving audio that is generated in the code. – Andrew Thompson Nov 04 '16 at 15:21
  • 1
    Also look at this [complete working version](http://stackoverflow.com/a/4040386/418556) on SO. – Andrew Thompson Nov 04 '16 at 15:24
  • This is tremendously helpful information, thank you. – doc29 Nov 04 '16 at 15:34
  • *"This is tremendously helpful information"* Who are you replying to? Tip: Add @aleb2000 (or whoever, the `@` is important) to *notify* the person of a new comment. – Andrew Thompson Nov 04 '16 at 19:26

0 Answers0