Skip to content

plasmoapp/opus-jni-rust

Repository files navigation

opus-jni-rust

Simple JNI wrapper for the opus-rs using jni-rs.

Adding dependency to the project

version

repositories {
    maven("https://repo.plasmoverse.com/releases")
}

dependencies {
    implementation("com.plasmoverse:opus-jni-rust:$version")
}

Usage

Sample code from OpusTest.java

/**
 * Encoding
 */
short[] rawSamples = new short[960];

// Creates a new encoder in mono with 1024 mtu size and application mode VOIP
OpusEncoder encoder = OpusEncoder.create(48_000, false, 1024, OpusMode.VOIP);

// Sets encoder bitrate to 50k
encoder.setBitrate(50_000);

// Encodes the raw audio samples
byte[] encoded = encoder.encode(rawSamples);

// Resets the encoder state
encoder.reset();

// Closes the encoder, releasing allocated resources
encoder.close();

/**
 * Decoding
 */

// Creates a new decoder in mono with 960 frame size
OpusDecoder decoder = OpusDecoder.create(48_000, false, 960);

// Decodes the encoded audio data into an audio samples
short[] decoded = decoder.decode(encoded);

// Resets the decoder state
decoder.reset();

// Closes the decoder, releasing allocated resources
decoder.close();

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published