From 9f65280ed34e87593bed336077c254113b119d4a Mon Sep 17 00:00:00 2001 From: Albert Ho Date: Wed, 31 Jan 2024 11:35:03 -0800 Subject: [PATCH] update --- .github/workflows/nodejs-perf.yml | 10 ++++++++-- README.md | 20 +++++++++----------- binding/nodejs/src/cobra.ts | 16 +++++----------- demo/nodejs/README.md | 6 +++--- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/.github/workflows/nodejs-perf.yml b/.github/workflows/nodejs-perf.yml index 7ada669..cb08588 100644 --- a/.github/workflows/nodejs-perf.yml +++ b/.github/workflows/nodejs-perf.yml @@ -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 @@ -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 }} @@ -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 diff --git a/README.md b/README.md index 899d222..0735156 100644 --- a/README.md +++ b/README.md @@ -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(); diff --git a/binding/nodejs/src/cobra.ts b/binding/nodejs/src/cobra.ts index e1dc30f..3ed3c84 100644 --- a/binding/nodejs/src/cobra.ts +++ b/binding/nodejs/src/cobra.ts @@ -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( @@ -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) { @@ -167,15 +165,11 @@ export default class Cobra { */ release(): void { if (this._handle !== 0) { - try { - this._pvCobra.delete(this._handle); - } catch (err: any) { - pvStatusToException(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'); } } @@ -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'); } } } diff --git a/demo/nodejs/README.md b/demo/nodejs/README.md index ae05622..4c11906 100644 --- a/demo/nodejs/README.md +++ b/demo/nodejs/README.md @@ -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 @@ -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