首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Java ogg vorbis编码

Java ogg vorbis编码
EN

Stack Overflow用户
提问于 2011-02-09 19:14:49
回答 1查看 2.2K关注 0票数 1

我在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();

EN

回答 1

Stack Overflow用户

发布于 2018-08-02 06:34:40

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4944086

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档