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

v2.0 node #293

Merged
merged 4 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions .github/workflows/nodejs-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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]

steps:
- uses: actions/checkout@v3
Expand All @@ -43,8 +43,9 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- name: Pre-build dependencies
run: npm install yarn
- name: Build Node.js SDK
run: yarn && yarn build
working-directory: binding/nodejs

- name: Install dependencies
run: yarn install
Expand All @@ -62,8 +63,9 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Pre-build dependencies
run: npm install --global yarn
- name: Build Node.js SDK
run: yarn && yarn build
working-directory: binding/nodejs

- name: Install dependencies
run: yarn install
Expand All @@ -77,18 +79,18 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [lts/*]

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
- name: Use Node.js LTS
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
node-version: lts/*

- name: Pre-build dependencies
run: npm install yarn
- name: Build Node.js SDK
run: yarn && yarn build
working-directory: binding/nodejs

- name: Install dependencies
run: yarn install
26 changes: 10 additions & 16 deletions .github/workflows/nodejs-perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- os: ubuntu-latest
init_performance_threshold_sec: 2.0
proc_performance_threshold_sec: 0.7
- os: windows-latest
init_performance_threshold_sec: 2.5
proc_performance_threshold_sec: 0.9
- os: windows-latest
init_performance_threshold_sec: 2.5
proc_performance_threshold_sec: 1.1
- os: macos-latest
init_performance_threshold_sec: 3.5
proc_performance_threshold_sec: 0.9
init_performance_threshold_sec: 4.0
proc_performance_threshold_sec: 2.0


steps:
Expand All @@ -50,9 +50,6 @@ jobs:
with:
node-version: 18.x

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

- name: Install dependencies
run: yarn install

Expand All @@ -69,26 +66,23 @@ jobs:
include:
- machine: rpi3-32
init_performance_threshold_sec: 7.6
proc_performance_threshold_sec: 3.3
proc_performance_threshold_sec: 4.5
- machine: rpi3-64
init_performance_threshold_sec: 8.4
proc_performance_threshold_sec: 3.3
proc_performance_threshold_sec: 4.5
- machine: rpi4-32
init_performance_threshold_sec: 5.7
proc_performance_threshold_sec: 2.1
proc_performance_threshold_sec: 3.3
- machine: rpi4-64
init_performance_threshold_sec: 5.1
proc_performance_threshold_sec: 2.0
proc_performance_threshold_sec: 3.2
- machine: jetson
init_performance_threshold_sec: 5.1
proc_performance_threshold_sec: 2.0
proc_performance_threshold_sec: 3.2

steps:
- uses: actions/checkout@v3

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

- name: Install dependencies
run: yarn install

Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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]

steps:
- uses: actions/checkout@v3
Expand All @@ -45,9 +45,6 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

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

- name: Install dependencies
run: yarn install

Expand All @@ -64,9 +61,6 @@ jobs:
steps:
- uses: actions/checkout@v3

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

- name: Install dependencies
run: yarn install

Expand Down
4 changes: 2 additions & 2 deletions binding/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Leopard is an on-device speech-to-text engine. Leopard is:

## Compatibility

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

## Installation
Expand All @@ -37,7 +37,7 @@ Create an instance of the engine and transcribe an audio file:
```javascript
const {Leopard} = require("@picovoice/leopard-node");

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

const result = handle.processFile('${AUDIO_PATH}');
Expand Down
6 changes: 3 additions & 3 deletions binding/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@picovoice/leopard-node",
"version": "1.2.0",
"version": "2.0.0",
"description": "Picovoice Leopard Node.js binding",
"main": "dist/index.js",
"types": "dist/types/index.d.ts",
Expand Down Expand Up @@ -38,7 +38,7 @@
"homepage": "https://picovoice.ai/products/leopard/",
"devDependencies": {
"@types/jest": "^27.4.1",
"@types/node": "^17.0.21",
"@types/node": "^18.11.9",
"@typescript-eslint/eslint-plugin": "^5.19.0",
"@typescript-eslint/parser": "^5.19.0",
"eslint": "^8.13.0",
Expand All @@ -53,7 +53,7 @@
"wavefile": "^11.0.0"
},
"engines": {
"node": ">=12.0.0"
"node": ">=16.0.0"
},
"cpu": [
"!ia32",
Expand Down
68 changes: 51 additions & 17 deletions binding/nodejs/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,81 @@

import PvStatus from './pv_status_t';

export class LeopardError extends Error {}
export class LeopardError extends Error {
private readonly _message: string;
private readonly _messageStack: string[];

constructor(message: string, messageStack: string[] = []) {
super(LeopardError.errorToString(message, messageStack));
this._message = message;
this._messageStack = messageStack;
}

get message(): string {
return this._message;
}

get messageStack(): string[] {
return this._messageStack;
}

private static errorToString(
initial: string,
messageStack: string[]
): string {
let msg = initial;

if (messageStack.length > 0) {
msg += `: ${messageStack.reduce(
(acc, value, index) => acc + '\n [' + index + '] ' + value,
''
)}`;
}

return msg;
}
}

export class LeopardOutOfMemoryError extends LeopardError {}
export class LeopardIoError extends LeopardError {}
export class LeopardIOError extends LeopardError {}
export class LeopardInvalidArgumentError extends LeopardError {}
export class LeopardStopIterationError extends LeopardError {}
export class LeopardKeyError extends LeopardError {}
export class LeopardInvalidStateError extends LeopardError {}
export class LeopardRuntimeError extends LeopardError {}
export class LeopardActivationError extends LeopardError {}
export class LeopardActivationLimitReached extends LeopardError {}
export class LeopardActivationThrottled extends LeopardError {}
export class LeopardActivationRefused extends LeopardError {}
export class LeopardActivationLimitReachedError extends LeopardError {}
export class LeopardActivationThrottledError extends LeopardError {}
export class LeopardActivationRefusedError extends LeopardError {}

export function pvStatusToException(
pvStatus: PvStatus,
errorMessage: string
errorMessage: string,
messageStack: string[] = []
): void {
switch (pvStatus) {
case PvStatus.OUT_OF_MEMORY:
throw new LeopardOutOfMemoryError(errorMessage);
throw new LeopardOutOfMemoryError(errorMessage, messageStack);
case PvStatus.IO_ERROR:
throw new LeopardIoError(errorMessage);
throw new LeopardIOError(errorMessage, messageStack);
case PvStatus.INVALID_ARGUMENT:
throw new LeopardInvalidArgumentError(errorMessage);
throw new LeopardInvalidArgumentError(errorMessage, messageStack);
case PvStatus.STOP_ITERATION:
throw new LeopardStopIterationError(errorMessage);
throw new LeopardStopIterationError(errorMessage, messageStack);
case PvStatus.KEY_ERROR:
throw new LeopardKeyError(errorMessage);
throw new LeopardKeyError(errorMessage, messageStack);
case PvStatus.INVALID_STATE:
throw new LeopardInvalidStateError(errorMessage);
throw new LeopardInvalidStateError(errorMessage, messageStack);
case PvStatus.RUNTIME_ERROR:
throw new LeopardRuntimeError(errorMessage);
throw new LeopardRuntimeError(errorMessage, messageStack);
case PvStatus.ACTIVATION_ERROR:
throw new LeopardActivationError(errorMessage);
throw new LeopardActivationError(errorMessage, messageStack);
case PvStatus.ACTIVATION_LIMIT_REACHED:
throw new LeopardActivationLimitReached(errorMessage);
throw new LeopardActivationLimitReachedError(errorMessage, messageStack);
case PvStatus.ACTIVATION_THROTTLED:
throw new LeopardActivationThrottled(errorMessage);
throw new LeopardActivationThrottledError(errorMessage, messageStack);
case PvStatus.ACTIVATION_REFUSED:
throw new LeopardActivationRefused(errorMessage);
throw new LeopardActivationRefusedError(errorMessage, messageStack);
default:
// eslint-disable-next-line no-console
console.warn(`Unmapped error code: ${pvStatus}`);
Expand Down
16 changes: 8 additions & 8 deletions binding/nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import { Leopard } from './leopard';

import {
LeopardActivationError,
LeopardActivationLimitReached,
LeopardActivationRefused,
LeopardActivationThrottled,
LeopardActivationLimitReachedError,
LeopardActivationRefusedError,
LeopardActivationThrottledError,
LeopardError,
LeopardInvalidArgumentError,
LeopardInvalidStateError,
LeopardIoError,
LeopardIOError,
LeopardKeyError,
LeopardOutOfMemoryError,
LeopardRuntimeError,
Expand All @@ -38,16 +38,16 @@ import {
export {
Leopard,
LeopardActivationError,
LeopardActivationLimitReached,
LeopardActivationRefused,
LeopardActivationThrottled,
LeopardActivationLimitReachedError,
LeopardActivationRefusedError,
LeopardActivationThrottledError,
LeopardOptions,
LeopardError,
LeopardInitOptions,
LeopardInputOptions,
LeopardInvalidArgumentError,
LeopardInvalidStateError,
LeopardIoError,
LeopardIOError,
LeopardKeyError,
LeopardOutOfMemoryError,
LeopardRuntimeError,
Expand Down
Loading