Skip to content

Commit

Permalink
feat: vad jni
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed Dec 1, 2023
0 parents commit a588174
Show file tree
Hide file tree
Showing 30 changed files with 1,420 additions and 0 deletions.
133 changes: 133 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: Deploy

on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"

jobs:
build-rust:
name: Build Binaries
runs-on: ${{ matrix.os }}

strategy:
matrix:
include:
- build: linux-x86
os: ubuntu-latest
target: i686-unknown-linux-gnu

- build: linux-x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-gnu

- build: linux-aarch64
os: ubuntu-latest
target: aarch64-unknown-linux-gnu

- build: win-x86
os: windows-latest
target: i686-pc-windows-msvc

- build: win-x86_64
os: windows-latest
target: x86_64-pc-windows-msvc

- build: mac-x86_64
os: macos-11
target: x86_64-apple-darwin

- build: mac-aarch64
os: macos-11
target: aarch64-apple-darwin


steps:
- name: Clone repository
uses: actions/checkout@v3

- name: Get the release version from the tag
shell: bash
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: Install Rust
uses: dtolnay/rust-toolchain@nightly
with:
targets: ${{ matrix.target }}

- name: Install gcc-aarch64-linux-gnu
if: matrix.build == 'linux-aarch64'
run: sudo apt-get update && sudo apt-get install gcc-aarch64-linux-gnu -y

- name: Install gcc-i686-linux-gnu
if: matrix.build == 'linux-x86'
run: sudo apt-get update && sudo apt-get install gcc-i686-linux-gnu libc6-dev-i386 -y

- name: Build
uses: actions-rs/cargo@v1
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
with:
command: build
args: --release --target ${{ matrix.target }} --manifest-path rust/Cargo.toml

- name: Create platform dir
shell: bash
run: |
binary_name="vad_jni_rust"
dirname="src/main/resources/natives/${{ matrix.build }}"
mkdir "$dirname"
if [ "${{ matrix.os }}" = "windows-latest" ]; then
mv "rust/target/${{ matrix.target }}/release/$binary_name.dll" "$dirname"
elif [ "${{ matrix.os }}" = "macos-11" ]; then
mv "rust/target/${{ matrix.target }}/release/lib$binary_name.dylib" "$dirname"
else
mv "rust/target/${{ matrix.target }}/release/lib$binary_name.so" "$dirname"
fi
echo "ASSET=$dirname" >> $GITHUB_ENV
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.build }}
path: ${{ env.ASSET }}

build:
name: Build & Publish Jar
runs-on: ubuntu-latest
needs: build-rust

steps:
- name: Clone repository
uses: actions/checkout@v3

- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: src/main/resources/natives

- name: Get the release version from the tag
shell: bash
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin

- name: Build with Gradle
uses: gradle/gradle-build-action@v2
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
with:
arguments: publish -x test -Pversion=${{ env.VERSION }}

- name: Upload artifact
uses: softprops/action-gh-release@v1
with:
files: |
build/libs/vad-jni-rust-${{ env.VERSION }}.jar
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
.gradle/
.idea/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Plasmo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# vad-jni-rust
Simple JNI wrapper for the [webrtc-vad](https://github.com/kaegi/webrtc-vad) using [jni-rs](https://github.com/jni-rs/jni-rs).

### Adding dependency to the project
<img alt="version" src="https://img.shields.io/badge/dynamic/xml?label=%20&query=/metadata/versioning/versions/version[not(contains(text(),'%2B'))][last()]&url=https://repo.plasmoverse.com/releases/com/plasmoverse/vad-jni-rust/maven-metadata.xml">

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

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

### Usage
```java
// Creates a new VAD instance
Vad vad = Vad.create(48_000, VadMode.QUALITY);

// Checks if provided frame is voice
boolean isVoiceSegment = vad.isVoiceSegment(frame);

// Closes the VAD, releasing allocated resources
vad.close();
```
45 changes: 45 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
plugins {
java
`maven-publish`
}

repositories {
mavenCentral()
}

dependencies {
testCompileOnly(libs.junit.api)
testAnnotationProcessor(libs.junit.api)
testRuntimeOnly(libs.junit.engine)
}

tasks {
java {
withSourcesJar()

toolchain.languageVersion.set(JavaLanguageVersion.of(8))
}

test {
useJUnitPlatform()
}
}

publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
}
}

repositories {
maven("https://repo.plasmoverse.com/releases") {
name = "PlasmoVerseReleases"

credentials {
username = System.getenv("MAVEN_USERNAME")
password = System.getenv("MAVEN_PASSWORD")
}
}
}
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
group=com.plasmoverse
version=1.0.0-SNAPSHOT
6 changes: 6 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[versions]
junit5 = "5.8.2"

[libraries]
junit-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit5" }
junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit5" }
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit a588174

Please sign in to comment.