2010-10-26 14 views
7

में ऑडियो फ़ाइल में कैसे स्टोर कर सकता हूं, मैं एक साधारण जावा एप्लिकेशन के लिए फ्रेट्स का उपयोग करने की कोशिश कर रहा हूं लेकिन मुझे समस्या का सामना करना पड़ रहा है, क्या कोई मुझे बता सकता है कि मैं आउटपुट वॉयस को कैसे सहेज सकता हूं जो टेक्स्ट से कनवर्ट किया गया है मेरे कार्यक्रम में एक लहर फ़ाइल में भाषण। मैं इसे कोड के माध्यम से करना चाहता हूं।मैं आउटपुट वॉयस को फ्रेट्स

यह नमूना HelloWorld आवेदन जो नमूना

/** 
* Copyright 2003 Sun Microsystems, Inc. 
* 
* See the file "license.terms" for information on usage and 
* redistribution of this file, and for a DISCLAIMER OF ALL 
* WARRANTIES. 
*/ 
import com.sun.speech.freetts.FreeTTS; 
import com.sun.speech.freetts.Voice; 
import com.sun.speech.freetts.VoiceManager; 
import com.sun.speech.freetts.audio.JavaClipAudioPlayer; 

/** 
* Simple program to demonstrate the use of the FreeTTS speech 
* synthesizer. This simple program shows how to use FreeTTS 
* without requiring the Java Speech API (JSAPI). 
*/ 
public class FreeTTSHelloWorld { 

    /** 
    * Example of how to list all the known voices. 
    */ 


    public static void main(String[] args) { 

     // listAllVoices(); 

     FreeTTS freetts; 

     String voiceName = "kevin16"; 

     System.out.println(); 
     System.out.println("Using voice: " + voiceName); 

     /* The VoiceManager manages all the voices for FreeTTS. 
     */ 
     VoiceManager voiceManager = VoiceManager.getInstance(); 
     Voice helloVoice = voiceManager.getVoice(voiceName); 

     if (helloVoice == null) { 
      System.err.println(
       "Cannot find a voice named " 
       + voiceName + ". Please specify a different voice."); 
      System.exit(1); 
     } 

     /* Allocates the resources for the voice. 
     */ 
     helloVoice.allocate(); 

     /* Synthesize speech. 
     */ 


     helloVoice.speak("Thank you for giving me a voice. " 
         + "I'm so glad to say hello to this world."); 


     /* Clean up and leave. 
     */ 
     helloVoice.deallocate(); 
     System.exit(0); 
    } 
} 

इस कोड को ठीक काम कर रहा है मैं अपने डिस्क पर एक ऑडियो फ़ाइल के रूप में उत्पादन को बचाने के लिए चाहते हो के साथ दिया जाता है।

धन्यवाद प्रणय

उत्तर

10

मैं पता लगा कि कैसे आप बस SingleFileAudioPlayer उपयोग करने के लिए की तरह फ़ाइल नाम और फ़ाइल प्रकार जो आप चाहते हैं नमूना घोषणा हो जाएगा पारित किया है कि ऐसा करने के लिए:

audioPlayer = new SingleFileAudioPlayer("output",Type.WAVE); 

अब आप को SinglefileAudioplayer वस्तु संलग्न करना अपने VoiceManager ऑब्जेक्ट: उदाहरण के लिए

helloVoice.setAudioPlayer(audioPlayer); 

अब का उपयोग करें:

hellovoice.speak("zyxss"); 

इस बात में वहाँ जो कुछ के साथ फ़ाइल बचत होगी। ऑडिओप्लेयर को बंद करना याद रखें अन्यथा फ़ाइल सहेजी नहीं जाएगी। बाहर निकलने से पहले audioPlayer.close(); रखो।

यहाँ पूरा काम कर कोड है जो अपने सी निर्देशिका में फाइल डंप हो जाएगा जवाब के लिए

/** 
    * Copyright 2003 Sun Microsystems, Inc. 
    * 
    * See the file "license.terms" for information on usage and 
    * redistribution of this file, and for a DISCLAIMER OF ALL 
    * WARRANTIES. 
    */ 
    import com.sun.speech.freetts.FreeTTS; 
    import com.sun.speech.freetts.Voice; 
    import com.sun.speech.freetts.VoiceManager; 
    import com.sun.speech.freetts.audio.AudioPlayer; 
    import com.sun.speech.freetts.audio.SingleFileAudioPlayer; 
    import javax.sound.sampled.AudioFileFormat.Type; 

    /** 
    * Simple program to demonstrate the use of the FreeTTS speech 
    * synthesizer. This simple program shows how to use FreeTTS 
    * without requiring the Java Speech API (JSAPI). 
    */ 
    public class FreeTTSHelloWorld { 

     /** 
     * Example of how to list all the known voices. 
     */ 


     public static void main(String[] args) { 

      // listAllVoices(); 

      FreeTTS freetts; 
     AudioPlayer audioPlayer = null; 
      String voiceName = "kevin16"; 

      System.out.println(); 
      System.out.println("Using voice: " + voiceName); 

      /* The VoiceManager manages all the voices for FreeTTS. 
      */ 
      VoiceManager voiceManager = VoiceManager.getInstance(); 
      Voice helloVoice = voiceManager.getVoice(voiceName); 

      if (helloVoice == null) { 
       System.err.println(
        "Cannot find a voice named " 
        + voiceName + ". Please specify a different voice."); 
       System.exit(1); 
      } 

      /* Allocates the resources for the voice. 
      */ 
      helloVoice.allocate(); 

      /* Synthesize speech. 
      */ 
//create a audioplayer to dump the output file 
      audioPlayer = new SingleFileAudioPlayer("C://output",Type.WAVE); 
    //attach the audioplayer 
      helloVoice.setAudioPlayer(audioPlayer); 



      helloVoice.speak("Thank you for giving me a voice. " 
          + "I'm so glad to say hello to this world."); 



      /* Clean up and leave. 
      */ 
      helloVoice.deallocate(); 
//don't forget to close the audioplayer otherwise file will not be saved 
      audioPlayer.close(); 
      System.exit(0); 
     } 
    } 
+0

अच्छा solution..thanks बहुत काम नहीं करते है – hemant

0

मैं FreeTTS इस्तेमाल कभी नहीं किया है, लेकिन Javadocs के एक त्वरित स्कैन Voice.setWaveDumpFile(String) पता चलता है। क्या ऐसा आवश्यक है?

+0

हाय धन्यवाद लेकिन इस –

संबंधित मुद्दे