Java ogg vorbis 编码

发布于 2024-10-16 07:36:03 字数 2518 浏览 2 评论 0原文

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

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

i am using tritonous package for audio encoding in ogg-vorbis. I face a problem when i am giving the audio format.

 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

This is my code where i am specifying the format

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花期渐远 2024-10-23 07:36:03

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

https://github.com/xjmusic/java-vorbis-编码器/blob/master/VorbisEncoder.java

I wrote a utility class to encode OGG Vorbis audio files from Java, using the xiph Java ports of libogg and libvorbis.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文