どのように私はfreettsのオーディオファイルへの出力音声を保存することができます

StackOverflow https://stackoverflow.com/questions/4027853

  •  26-09-2019
  •  | 
  •  

質問

缶誰もが私は私のプログラムでwaveファイルにテキストから音声に変換され、出力音声を保存することができますどのように私に教えて、私は単純なJavaアプリケーションのためのfreettsを使用しようとしていますが、私は問題に直面しています。私は、コードを経由して、それをやりたい。

これはサンプルが付与されたサンプル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);
    }
}

このコードは正常に動作している私は、ディスク上のオーディオファイルとして出力を保存したい。

のおかげで Pranay

役に立ちましたか?

解決

私は、あなたは、単にあなたのようになりますサンプル宣言をしたいファイル名とファイルタイプを渡しSingleFileAudioPlayerを使用する必要があることを行う方法を考え出しました

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

今すぐあなたのSinglefileAudioplayerオブジェクトにVoiceManagerオブジェクトを添付する必要があります。たとえば、

helloVoice.setAudioPlayer(audioPlayer);

今使用します:

hellovoice.speak("zyxss"); 

これは話すそこに何を使用してファイルを保存します。そうでない場合は、ファイルが保存されませんaudioplayerを閉じることを忘れないでください。終了する前にaudioPlayer.close();を置きます。

ここにあなたのCディレクトリ内のファイルをダンプする完全な作業コードがある

    /**
     * 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);
        }
    }

他のヒント

私はFreeTTSを使用したことがない、しかしのJavaDocのクイックスキャンは、<のhref = "http://freetts.sourceforge.net/javadoc/com/sun/speech/freetts/Voice.html#setWaveDumpFile%28javaを明らかにする。 %29" のrel = "nofollowを"> Voice.setWaveDumpFile(文字列)にlang.String。必要とされるものでしょうか?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top