Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0 node #690

Merged
merged 17 commits into from
Oct 25, 2023
Prev Previous commit
Next Next commit
update nodejs
  • Loading branch information
ksyeo1010 committed Oct 20, 2023

Verified

This commit was signed with the committer’s verified signature.
kraftbj Brandon Kraft
commit b79a2ad9593b65c3838e7a35b78dc30ca4c27e01
26 changes: 25 additions & 1 deletion .github/workflows/nodejs-demos.yml
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [16.x, 18.x, 20.x]
include:
- os: ubuntu-latest
platform: linux
@@ -46,6 +46,18 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- name: Local Porcupine dependency
run: yarn && yarn build
working-directory: resources/porcupine/binding/nodejs

- name: Local Rhino dependency
run: yarn && yarn build
working-directory: resources/rhino/binding/nodejs

- name: Local dependency
run: yarn && yarn build
working-directory: sdk/nodejs

- name: Pre-build dependencies
run: npm install yarn

@@ -89,6 +101,18 @@ jobs:
- name: Pre-build dependencies
run: npm install --global yarn

- name: Local Porcupine dependency
run: yarn && yarn build
working-directory: resources/porcupine/binding/nodejs

- name: Local Rhino dependency
run: yarn && yarn build
working-directory: resources/rhino/binding/nodejs

- name: Local dependency
run: yarn && yarn build
working-directory: sdk/nodejs

- name: Install dependencies
run: yarn install

4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
@@ -61,7 +61,7 @@ jobs:
run: yarn install

- name: Test
run: yarn test --access_key=${{secrets.PV_VALID_ACCESS_KEY}}
run: yarn test --access_key=${{secrets.PV_VALID_ACCESS_KEY}}

build-self-hosted:
runs-on: ${{ matrix.machine }}
6 changes: 3 additions & 3 deletions demo/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@picovoice/picovoice-node-demo",
"version": "2.2.2",
"version": "3.0.0",
"description": "Picovoice SDK for NodeJS file-based and microphone demos",
"scripts": {
"file": "node file.js",
@@ -16,7 +16,7 @@
"author": "Picovoice Inc.",
"license": "Apache-2.0",
"dependencies": {
"@picovoice/picovoice-node": "2.2.1",
"@picovoice/picovoice-node": "file:../../sdk/nodejs",
"@picovoice/pvrecorder-node": "1.2.1",
"commander": "^6.1.0",
"wavefile": "^11.0.0"
@@ -29,7 +29,7 @@
"directory": "demo/nodejs"
},
"engines": {
"node": ">=12.0.0"
"node": ">=16.0.0"
},
"cpu": [
"!ia32",
22 changes: 8 additions & 14 deletions demo/nodejs/yarn.lock
Original file line number Diff line number Diff line change
@@ -2,28 +2,22 @@
# yarn lockfile v1


"@picovoice/[email protected]":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@picovoice/picovoice-node/-/picovoice-node-2.2.1.tgz#62052b18ae276d3fa9467239221182d1755e4165"
integrity sha512-Ml9tFlJGrep4Dqvk07Nu3JCpCWkJSRmE/bKbO2c1meWRltOwqP//W78R/QiC30zv763nWGKGPwXh95Lvm7YYkA==
"@picovoice/picovoice-node@file:../../sdk/nodejs":
version "3.0.0"
dependencies:
"@picovoice/porcupine-node" "=2.2.1"
"@picovoice/rhino-node" "=2.2.1"
"@picovoice/porcupine-node" "file:../../../../../.cache/yarn/v6/npm-@picovoice-picovoice-node-3.0.0-5840f3c4-e246-4354-b070-bc9a5847b11d-1697586335625/node_modules/resources/porcupine/binding/nodejs"
"@picovoice/rhino-node" "file:../../../../../.cache/yarn/v6/npm-@picovoice-picovoice-node-3.0.0-5840f3c4-e246-4354-b070-bc9a5847b11d-1697586335625/node_modules/resources/rhino/binding/nodejs"

"@picovoice/porcupine-node@=2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@picovoice/porcupine-node/-/porcupine-node-2.2.1.tgz#5055d87c0b7e3039c8835fceb972dde4ea2c27ae"
integrity sha512-+sc3uY2ZdZabUW7kYZ2wDezg2CZYy729Xy387fMuNw8fa2aoHuU9pcpaUR2KfLDRC+s2hbWdAqnxjCuSvt/NYw==
"@picovoice/porcupine-node@file:../../resources/porcupine/binding/nodejs":
version "3.0.0"

"@picovoice/[email protected]":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@picovoice/pvrecorder-node/-/pvrecorder-node-1.2.1.tgz#8e112ecc7a4836aa4fa92d62ac7942d8a2366db8"
integrity sha512-7TtRMh04PSVn542Oq1v/MGLFuNPdUrrv+f7qbCGOWRc8y6ox+FATigdQqLRbRey4kZWf40dNHQFdVPCk5ZcXnQ==

"@picovoice/rhino-node@=2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@picovoice/rhino-node/-/rhino-node-2.2.1.tgz#83c420736d54314c7a842845096873be8c65fb0e"
integrity sha512-Alh3FrfWxzu4k2rrkls1YZGZVuKHfXiRtXJXh5IBDosvSgBFKYQ/eCclTw/reSr03Cl7BmZaBmISmGIoU1Hwqg==
"@picovoice/rhino-node@file:../../resources/rhino/binding/nodejs":
version "3.0.0"

commander@^6.1.0:
version "6.2.1"
32 changes: 19 additions & 13 deletions sdk/nodejs/src/picovoice.ts
Original file line number Diff line number Diff line change
@@ -213,9 +213,15 @@ export default class Picovoice {
* or when process was stopped while processing a stream of audio.
*/
reset(): void {
if (this.porcupine === null || this.rhino === null) {
throw new PicovoiceErrors.PicovoiceInvalidStateError(
'Attempting to reset but resources have been released.'
);
}

try {
this.isWakeWordDetected = false;
this._rhino.reset();
this.rhino.reset();
} catch (error: any) {
throw this.mapToPicovoiceError(error);
}
@@ -235,28 +241,28 @@ export default class Picovoice {
}
}

private mapToPicovoiceError(e: PorcupineErrors.PicovoiceError | RhinoErrors.RhinoError) {
if (e instanceof PorcupineErrors.PicovoiceOutOfMemoryError || e instanceof RhinoErrors.RhinoOutOfMemoryError) {
private mapToPicovoiceError(e: PorcupineErrors.PorcupineError | RhinoErrors.RhinoError) {
if (e instanceof PorcupineErrors.PorcupineOutOfMemoryError || e instanceof RhinoErrors.RhinoOutOfMemoryError) {
return new PicovoiceErrors.PicovoiceOutOfMemoryError(e.message);
} else if (e instanceof PorcupineErrors.PicovoiceIOError || e instanceof RhinoErrors.RhinoIOError) {
} else if (e instanceof PorcupineErrors.PorcupineIOError || e instanceof RhinoErrors.RhinoIOError) {
return new PicovoiceErrors.PicovoiceIOError(e.message);
} else if (e instanceof PorcupineErrors.PicovoiceInvalidArgumentError || e instanceof RhinoErrors.RhinoInvalidArgumentError) {
} else if (e instanceof PorcupineErrors.PorcupineInvalidArgumentError || e instanceof RhinoErrors.RhinoInvalidArgumentError) {
return new PicovoiceErrors.PicovoiceInvalidArgumentError(e.message);
} else if (e instanceof PorcupineErrors.PicovoiceStopIterationError || e instanceof RhinoErrors.RhinoStopIterationError) {
} else if (e instanceof PorcupineErrors.PorcupineStopIterationError || e instanceof RhinoErrors.RhinoStopIterationError) {
return new PicovoiceErrors.PicovoiceStopIterationError(e.message);
} else if (e instanceof PorcupineErrors.PicovoiceKeyError || e instanceof RhinoErrors.RhinoKeyError) {
} else if (e instanceof PorcupineErrors.PorcupineKeyError || e instanceof RhinoErrors.RhinoKeyError) {
return new PicovoiceErrors.PicovoiceKeyError(e.message);
} else if (e instanceof PorcupineErrors.PicovoiceInvalidStateError || e instanceof RhinoErrors.RhinoInvalidStateError) {
} else if (e instanceof PorcupineErrors.PorcupineInvalidStateError || e instanceof RhinoErrors.RhinoInvalidStateError) {
return new PicovoiceErrors.PicovoiceInvalidStateError(e.message);
} else if (e instanceof PorcupineErrors.PicovoiceRuntimeError || e instanceof RhinoErrors.RhinoRuntimeError) {
} else if (e instanceof PorcupineErrors.PorcupineRuntimeError || e instanceof RhinoErrors.RhinoRuntimeError) {
return new PicovoiceErrors.PicovoiceRuntimeError(e.message);
} else if (e instanceof PorcupineErrors.PicovoiceActivationError || e instanceof RhinoErrors.RhinoActivationError) {
} else if (e instanceof PorcupineErrors.PorcupineActivationError || e instanceof RhinoErrors.RhinoActivationError) {
return new PicovoiceErrors.PicovoiceActivationError(e.message);
} else if (e instanceof PorcupineErrors.PicovoiceActivationLimitReachedError || e instanceof RhinoErrors.RhinoActivationLimitReachedError) {
} else if (e instanceof PorcupineErrors.PorcupineActivationLimitReached || e instanceof RhinoErrors.RhinoActivationLimitReachedError) {
return new PicovoiceErrors.PicovoiceActivationLimitReachedError(e.message);
} else if (e instanceof PorcupineErrors.PicovoiceActivationThrottledError || e instanceof RhinoErrors.RhinoActivationThrottledError) {
} else if (e instanceof PorcupineErrors.PorcupineActivationThrottledError || e instanceof RhinoErrors.RhinoActivationThrottledError) {
return new PicovoiceErrors.PicovoiceActivationThrottledError(e.message);
} else if (e instanceof PorcupineErrors.PicovoiceActivationRefusedError || e instanceof RhinoErrors.RhinoActivationRefusedError) {
} else if (e instanceof PorcupineErrors.PorcupineActivationRefusedError || e instanceof RhinoErrors.RhinoActivationRefusedError) {
return new PicovoiceErrors.PicovoiceActivationRefusedError(e.message);
} else {
return new PicovoiceErrors.PicovoiceError(e.message);
6 changes: 3 additions & 3 deletions sdk/nodejs/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -199,9 +199,9 @@ describe('getter functions', () => {
() => {}
);

expect(handle.porcupineVersion).toEqual('2.2.0');
expect(handle.rhinoVersion).toEqual('2.2.0');
expect(handle.version).toEqual('2.2.0');
expect(handle.porcupineVersion).toEqual('3.0.0');
expect(handle.rhinoVersion).toEqual('3.0.0');
expect(handle.version).toEqual('3.0.0');

handle.release();
});
2 changes: 1 addition & 1 deletion sdk/nodejs/yarn.lock
Original file line number Diff line number Diff line change
@@ -588,7 +588,7 @@
version "3.0.0"

"@picovoice/rhino-node@file:../../resources/rhino/binding/nodejs":
version "2.2.1"
version "3.0.0"

"@sinonjs/commons@^1.7.0":
version "1.8.6"