Skip to content

Commit

Permalink
version 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
GiviMAD committed Sep 5, 2023
1 parent 972e0fa commit 1328584
Show file tree
Hide file tree
Showing 17 changed files with 1,140 additions and 408 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI

Check failure on line 1 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / build-lib-macos

.github/workflows/main.yml#L1

This run was manually canceled.

Check failure on line 1 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / build-lib-debian-arm

.github/workflows/main.yml#L1

This run was manually canceled.

Check failure on line 1 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / build-lib-debian-arm64

.github/workflows/main.yml#L1

This run was manually canceled.

Check failure on line 1 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / build-lib-debian-x86_64

.github/workflows/main.yml#L1

This run was manually canceled.

Check failure on line 1 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / build-lib-windows

.github/workflows/main.yml#L1

This run was manually canceled.
on:
push:
tags: [ "v*.*.*" ]
tags: [ "v*.*.*", "v*.*.*-*", "v*.*.*-*.*" ]
workflow_dispatch:
jobs:
build-lib-debian-x86_64:
Expand Down Expand Up @@ -29,16 +29,16 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Docker Setup Buildx
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Build binaries
run: |
cd binding
mkdir -p dist
docker build -f docker/Dockerfile . -t rustpotter_binary:arm --platform arm --load
docker build -f docker/Dockerfile --build-arg RUSTFLAGS="-C target-feature=+fp16" . -t rustpotter_binary:arm --platform arm --load
DOCKER_BUILDKIT=1 docker run --platform=arm -v $(pwd)/dist:/out rustpotter_binary:arm bash -c "cp /code/dist/* /out/"
- name: artifact debian arm
uses: actions/upload-artifact@v3
Expand All @@ -51,16 +51,16 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Docker Setup Buildx
uses: docker/setup-buildx-action@v1.6.0
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Build binaries
run: |
cd binding
mkdir -p dist
docker build -f docker/Dockerfile . -t rustpotter_binary:arm64 --platform arm64 --load
docker build -f docker/Dockerfile --build-arg RUSTFLAGS="-C target-feature=+fp16" . -t rustpotter_binary:arm64 --platform arm64 --load
DOCKER_BUILDKIT=1 docker run --platform=arm64 -v $(pwd)/dist:/out rustpotter_binary:arm64 bash -c "cp /code/dist/* /out/"
- name: artifact debian arm64
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
needs: [build-lib-debian-x86_64,build-lib-debian-arm,build-lib-debian-arm64,build-lib-windows,build-lib-macos]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
- name: check tree
run: ls -R
Expand All @@ -143,9 +143,11 @@ jobs:
mv ./macos-binary-x86_64/librustpotter_java_macos_x86_64.dylib ./src/main/resources/librustpotter_java_macos_x86_64.dylib
mv ./macos-binary-arm64/librustpotter_java_macos_aarch64.dylib ./src/main/resources/librustpotter_java_macos_aarch64.dylib
- name: Set up Maven Central Repository
uses: actions/setup-java@v1
uses: actions/setup-java@v2
with:
java-version: 11
java-package: jdk
distribution: 'zulu'
server-id: sonatype-nexus-staging
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
Expand Down
65 changes: 3 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
<img src="./logo.png?raw=true" width="400px"</img>
</div>

## Description
## Overview

Java wrapper for [Rustpotter](https://github.com/GiviMAD/rustpotter) (an open source wakeword spotter forged in rust).

For an usage example, please refer to the "getDetectionsInFile" test implementation.

## Installation

This package is available on the [Maven Central Repository](https://search.maven.org/artifact/io.github.givimad/rustpotter-java).
Expand All @@ -17,64 +19,3 @@ The distributed package support the following platforms:
* debian (arm, arm64, x86_64)
* macOS (arm64, x86_64)
* windows (x86_64)

## Examples

### Initialize the Detector:

```java
var rustpotterBuilder = new RustpotterBuilder();
rustpotterBuilder.setThreshold(config.threshold);
rustpotterBuilder.setAveragedThreshold(config.averagedThreshold);
rustpotterBuilder.setComparatorRef(config.comparatorRef);
rustpotterBuilder.setComparatorBandSize(config.comparatorBandSize);
rustpotterBuilder.setBitsPerSample(bitDepth);
rustpotterBuilder.setSampleRate(frequency);
rustpotterBuilder.setChannels(channels);
rustpotterBuilder.setEndianness(Endianness.Little);
var rustpotter = rustpotterBuilder.build();
rustpotterBuilder.delete();
// Add wakeword model
rustpotter.addWakewordModelFile(modelPath.toString());
```

### Detect Wakewords:

```java
private void processAudioStream(Rustpotter rustpotter, Consumer<String> listener, InputStream audioStream, AtomicBoolean aborted) {
int numBytesRead;
var frameSize = (int) rustpotter.getSamplesPerFrame();
var bufferSize = frameSize * 2;
ByteBuffer captureBuffer = ByteBuffer.allocate(bufferSize);
captureBuffer.order(ByteOrder.LITTLE_ENDIAN);
short[] audioBuffer = new short[frameSize];
while (!aborted.get()) {
try {
// read a buffer of audio
numBytesRead = audioStream.read(captureBuffer.array(), 0, captureBuffer.capacity());
if (aborted.get()) {
break;
}
if (numBytesRead != bufferSize) {
// do not pass incomplete buffers
Thread.sleep(100);
continue;
}
captureBuffer.asShortBuffer().get(audioBuffer);
var result = rustpotter.processSort(audioBuffer);
if (result.isPresent()) {
var detection = result.get();
var word = detection.getName();
logger.debug("keyword '{}' detected with score {}!", detection.getName(), detection.getScore());
detection.delete();
listener.accept(word);
}
} catch (IOException | InterruptedException e) {
String errorMessage = e.getMessage();
throw e; // another consumer for the errors makes more sense as this function is intended to run on a separate thread.
}
}
rustpotter.delete();
logger.debug("rustpotter stopped");
}
```
Loading

0 comments on commit 1328584

Please sign in to comment.