How to save encoded Opus stream file as .ogg/.opus with its header in Android

911 Views Asked by At

I am using this library (https://github.com/theeasiestway/android-opus-codec) to encode and decode audio files. I can store the encoded opus file then decode and play via AudioTrack. But i need to save it as .opus/.ogg file with its header, then only i can play via android inbuilt opus decoder (for mediaplayer). At present i am converting the decoded PCM to WAVE to play via media Player. Any help will be appreciated, forgive my bad English.

1

There are 1 best solutions below

0
arun On

I solved the issue with the help of this library( https://github.com/Gagravarr/VorbisJava ).

    OpusInfo info = new OpusInfo();
    info.setNumChannels(1);
    info.setSampleRate(16000);
    OpusTags tags = new OpusTags();
    OpusFile file = new OpusFile(fileOutputStream, info, tags);
    OpusAudioData data = new OpusAudioData(encoded);
                        file.writeAudioData(data);