Android wrapper around libopus 1.3.1 written on C++ and Kotlin.
armeabi-v7a, arm64-v8a, x86, x86_64
val SAMPLE_RATE = Constants.SampleRate._48000() // samlpe rate of the input audio
val CHANNELS = Constants.Channels.stereo() // type of the input audio mono or stereo
val APPLICATION = Constants.Application.audio() // coding mode of the encoder
var FRAME_SIZE = Constants.FrameSize._120() // default frame size for 48000Hz
val codec = Opus() // getting Codec instance
codec.encoderInit(SAMPLE_RATE, CHANNELS, APPLICATION) // init encoder
codec.decoderInit(SAMPLE_RATE, CHANNELS) // init decoder
/* this step is optional because the encoder can use default values */
val COMPLEXITY = Constants.Complexity.instance(10) // encoder's algorithmic complexity
val BITRATE = Constants.Bitrate.max() // encoder's bitrate
codec.encoderSetComplexity(COMPLEXITY) // complexity setup
codec.encoderSetBitrate(BITRATE) // bitrate setup
val frame = ... // get a chunk of audio from some source as an array of bytes or shorts
val encoded = codec.encode(frame, FRAME_SIZE) // encode the audio chunk into Opus
if (encoded != null) Log.d("Opus", "encoded chunk size: ${encoded.size}")
val decoded = codec.decode(encoded, FRAME_SIZE) // decode a chunk of audio into PCM
if (decoded != null) Log.d("Opus", "decoded chunk size: ${decoded.size}")
codec.encoderRelease()
codec.decoderRelease()
dependencies {
api fileTree(dir: 'libs', include: '*.jar') // this line is necessary in order to allow gradle to take opus.aar from "libs" dir
api files('libs/opus.aar') // dependency for opus.aar library
... // other dependencies
}