Java ogg vorbis编码

时间:2011-02-09 11:14:49

标签: java audio audio-recording

我在ogg-vorbis中使用tritonous包进行音频编码。我在提供音频格式时遇到问题。

 Unsupported conversion: VORBIS 44100.0Hz, unknown bits per sample, mono, unknown frame size,  from PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian

这是我指定格式

的代码
File outputFile = new File(userDir+"//San"+"_"+strFilename + ".spx");

                        // Using PCM 44.1 kHz, 16 bit signed,stereo.
                        if(osName.indexOf("win") >= 0){
                            System.out.println("windows");
                            audioFormat = getWindowsAudioFormat();  
                            sampleRate = 44100.0F;

                        }else {
                            System.out.println("mac");
                            audioFormat = getMacAudioFormat();  
                            sampleRate = 44100.0F;
                        }

                        AudioFormat vorbisFormat = new AudioFormat(VORBIS,
                                sampleRate,
                                AudioSystem.NOT_SPECIFIED,
                                1,
                                AudioSystem.NOT_SPECIFIED,
                                AudioSystem.NOT_SPECIFIED,
                                false);


                        DataLine.Info   info = new DataLine.Info(TargetDataLine.class, audioFormat);
                        TargetDataLine  targetDataLine = null;
                        AudioFileFormat.Type fileType = null;
                        File audioFile = null;
                        fileType = VORBIS;
                        try
                        {
                            targetDataLine = (TargetDataLine) AudioSystem.getLine(info);
                            targetDataLine.open(audioFormat);
                        }
                        catch (LineUnavailableException e)
                        {
                            System.out.println("unable to get a recording line");
                            e.printStackTrace();
                            System.exit(1);
                        }
                        AudioInputStream ais = new AudioInputStream(targetDataLine);

                        ais = AudioSystem.getAudioInputStream(vorbisFormat, ais);
                        final Recorder recorder = new Recorder(targetDataLine,ais,fileType,outputFile);
                        int number = 0;
                        System.out.println("Recording...");

recorder.start();

1 个答案:

答案 0 :(得分:0)

我编写了一个实用程序类,使用libogg和libvorbis的xiph Java端口对Java的OGG Vorbis音频文件进行编码。

https://github.com/xjmusic/java-vorbis-encoder/blob/master/VorbisEncoder.java