Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
albho committed Jan 31, 2024
1 parent ac210e9 commit 9f65280
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/nodejs-perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- os: ubuntu-latest
num_test_iterations: 50
init_performance_threshold_sec: 0.001
proc_performance_threshold_sec: 0.005
- os: windows-latest
num_test_iterations: 50
init_performance_threshold_sec: 0.5
proc_performance_threshold_sec: 0.005
- os: macos-latest
num_test_iterations: 50
init_performance_threshold_sec: 0.005
proc_performance_threshold_sec: 0.005

steps:
- uses: actions/checkout@v3
Expand All @@ -50,7 +56,7 @@ jobs:
run: yarn install

- name: Test
run: yarn test perf.test.ts --access_key=${{secrets.PV_VALID_ACCESS_KEY}} --num_test_iterations=50 --init_performance_threshold_sec=${{matrix.init_performance_threshold_sec}} --proc_performance_threshold_sec=0.005
run: yarn test perf.test.ts --access_key=${{secrets.PV_VALID_ACCESS_KEY}} --num_test_iterations=${{matrix.num_test_iterations}} --init_performance_threshold_sec=${{matrix.init_performance_threshold_sec}} --proc_performance_threshold_sec=${{matrix.proc_performance_threshold_sec}}

perf-self-hosted:
runs-on: ${{ matrix.machine }}
Expand Down Expand Up @@ -91,7 +97,7 @@ jobs:
run: bash machine-state.sh

- name: Test
run: yarn test perf.test.ts --access_key=${{secrets.PV_VALID_ACCESS_KEY}} --num_test_iterations=${{matrix.num_test_iterations}} --init_performance_threshold_sec=0.005 --proc_performance_threshold_sec=0.05
run: yarn test perf.test.ts --access_key=${{secrets.PV_VALID_ACCESS_KEY}} --num_test_iterations=${{matrix.num_test_iterations}} --init_performance_threshold_sec=0.01 --proc_performance_threshold_sec=0.05

- name: Machine state after
working-directory: res/scripts
Expand Down
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,28 +346,26 @@ Create instances of the Cobra class:
```javascript
const { Cobra } = require("@picovoice/cobra-node");

// Obtained from the Picovoice Console (https://console.picovoice.ai/)
const accessKey = "${ACCESS_KEY}";

const accessKey = "${ACCESS_KEY}"; // Obtained from the Picovoice Console (https://console.picovoice.ai/)
const handle = new Cobra(accessKey);
```

When instantiated, `handle` can process audio via its `.process` method.

```javascript
let getNextAudioFrame = function() {
...
};
function getNextAudioFrame() {
// ...
return audioFrame;
}

while (true) {
let voiceProbability = handle.process(getNextAudioFrame());
if (voiceProbability !== -1) {
// detection event callback
}
const audioFrame = getNextAudioFrame();
const voiceProbability = handle.process(audioFrame);
console.log(voiceProbability);
}
```

When done be sure to release resources acquired by WebAssembly using `release()`:
When done be sure to release resources using `release()`:

```javascript
handle.release();
Expand Down
16 changes: 5 additions & 11 deletions binding/nodejs/src/cobra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ export default class Cobra {
throw new CobraInvalidArgumentError(`No AccessKey provided to Cobra`);
}

const {
libraryPath = getSystemLibraryPath(),
} = options;
const { libraryPath = getSystemLibraryPath() } = options;

if (!fs.existsSync(libraryPath)) {
throw new CobraInvalidArgumentError(
Expand All @@ -75,7 +73,7 @@ export default class Cobra {

let cobraHandleAndStatus: CobraHandleAndStatus | null = null;
try {
pvCobra.set_sdk("nodejs");
pvCobra.set_sdk('nodejs');

cobraHandleAndStatus = pvCobra.init(accessKey);
} catch (err: any) {
Expand Down Expand Up @@ -167,15 +165,11 @@ export default class Cobra {
*/
release(): void {
if (this._handle !== 0) {
try {
this._pvCobra.delete(this._handle);
} catch (err: any) {
pvStatusToException(<PvStatus>err.code, err);
}
this._pvCobra.delete(this._handle);
this._handle = 0;
} else {
// eslint-disable-next-line no-console
console.warn('Cobra is not initialized');
console.warn('Cobra is not initialized; nothing to destroy');
}
}

Expand All @@ -184,7 +178,7 @@ export default class Cobra {
if (errorObject.status === PvStatus.SUCCESS) {
pvStatusToException(status, message, errorObject.message_stack);
} else {
pvStatusToException(status, "Unable to get Cobra error state");
pvStatusToException(status, 'Unable to get Cobra error state');
}
}
}
6 changes: 3 additions & 3 deletions demo/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Cobra is an on-device voice activity detection engine. Cobra is:

## Compatibility

- Node.js 12+
- Node.js 16+
- Runs on Linux (x86_64), macOS (x86_64, arm64), Windows (x86_64), Raspberry Pi (2, 3, 4, 5), NVIDIA Jetson Nano, and BeagleBone.

## Installation
Expand All @@ -41,8 +41,8 @@ Run the following in the terminal:
cobra-file-demo --access_key ${ACCESS_KEY} --input_audio_file_path ${AUDIO_PATH}
```

Replace `${ACCESS_KEY}` with yours obtained from Picovoice Console and `${AUDIO_PATH}` with a path to an audio file for which you
wish to detect voice activity.
Replace `${ACCESS_KEY}` with yours obtained from Picovoice Console and `${AUDIO_PATH}` with a path to an audio file you
wish to use for voice activity detection.

### Microphone Demo

Expand Down

0 comments on commit 9f65280

Please sign in to comment.