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

Web sdk #5

Merged
merged 16 commits into from
Jan 15, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
review feedback
albho committed Jan 11, 2024

Verified

This commit was signed with the committer’s verified signature.
vzaliva Vadim Zaliva
commit 0cd6ed96b2556fe261527ca24bbdd74c1b492904
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ Falcon is an on-device speaker diarization engine. Falcon is:
- Cross-Platform:
- Linux (x86_64), macOS (x86_64, arm64), Windows (x86_64)
- Raspberry Pi (4, 3) and NVIDIA Jetson Nano
- Chrome, Safari, Firefox, and Edge

## Table of Contents

@@ -28,9 +29,11 @@ Falcon is an on-device speaker diarization engine. Falcon is:
- [Demos](#demos)
- [Python Demos](#python-demos)
- [C Demos](#c-demos)
- [Web Demos](#web-demos)
- [SDKs](#sdks)
- [Python](#python)
- [C](#c)
- [Web](#web)
- [Releases](#releases)
- [FAQ](#faq)

@@ -85,6 +88,24 @@ Run the demo:
./demo/c/build/falcon_demo -a ${ACCESS_KEY} -l ${LIBRARY_PATH} -m ${MODEL_PATH} ${AUDIO_PATH}
```

### Web Demos

From [demo/web](demo/web) run the following in the terminal:

```console
yarn
yarn start
```

(or)

```console
npm install
npm run start
```

Open `http://localhost:5000` in your browser to try the demo.

## SDKs

### Python
@@ -160,6 +181,42 @@ Finally, when done be sure to release resources acquired:
pv_falcon_delete(falcon);
```

### Web

Install the web SDK using yarn:

```console
yarn add @picovoice/falcon-web
```

or using npm:

```console
npm install --save @picovoice/falcon-web
```

Create an instance of the engine using `FalconWorker` and diarize an audio file:

```typescript
import { Falcon } from "@picovoice/falcon-web";
import falconParams from "${PATH_TO_BASE64_FALCON_PARAMS}";

function getAudioData(): Int16Array {
// ... function to get audio data
return new Int16Array();
}

const falcon = await FalconWorker.create(
"${ACCESS_KEY}",
{ base64: falconParams }
);

const { segments } = await falcon.process(getAudioData());
console.log(segments);
```

Replace `${ACCESS_KEY}` with yours obtained from [Picovoice Console](https://console.picovoice.ai/). Finally, when done release the resources using `falcon.release()`.

## Releases

### v1.0.0 — November 28th, 2023
6 changes: 4 additions & 2 deletions binding/web/README.md
Original file line number Diff line number Diff line change
@@ -10,11 +10,13 @@ Falcon is an on-device speaker diarization engine. Falcon is:
- Cross-Platform:
- Linux (x86_64), macOS (x86_64, arm64), Windows (x86_64)
- Raspberry Pi (4, 3) and NVIDIA Jetson Nano
- Chrome, Safari, Firefox, and Edge

## Compatibility

- Python 3.7+
- Runs on Linux (x86_64), macOS (x86_64, arm64), Windows (x86_64), Raspberry Pi (4, 3), and NVIDIA Jetson Nano.
- Chrome / Edge
- Firefox
- Safari

### Restrictions

2 changes: 1 addition & 1 deletion binding/web/package.json
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@
"test-perf": "cypress run --spec test/falcon_perf.test.ts"
},
"dependencies": {
"@picovoice/web-utils": "=1.3.1"
"@picovoice/web-utils": "=1.3.2"
},
"devDependencies": {
"@babel/core": "^7.21.3",
8 changes: 4 additions & 4 deletions binding/web/src/falcon.ts
Original file line number Diff line number Diff line change
@@ -310,11 +310,11 @@ export class Falcon {
const segments: FalconSegment[] = [];
for (let i = 0; i < numSegments; i++) {
const startSec = memoryBufferView.getFloat32(ptr, true);
ptr += Uint32Array.BYTES_PER_ELEMENT;
ptr += Float32Array.BYTES_PER_ELEMENT;
const endSec = memoryBufferView.getFloat32(ptr, true);
ptr += Uint32Array.BYTES_PER_ELEMENT;
ptr += Float32Array.BYTES_PER_ELEMENT;
const speakerTag = memoryBufferView.getInt32(ptr, true);
ptr += Uint32Array.BYTES_PER_ELEMENT;
ptr += Int32Array.BYTES_PER_ELEMENT;
segments.push({ startSec, endSec, speakerTag });
}

@@ -350,7 +350,7 @@ export class Falcon {
modelPath: string
): Promise<any> {
// A WebAssembly page has a constant size of 64KiB. -> 1MiB ~= 16 pages
const memory = new WebAssembly.Memory({ initial: 11500 });
const memory = new WebAssembly.Memory({ initial: 130 });

const memoryBufferUint8 = new Uint8Array(memory.buffer);

21 changes: 13 additions & 8 deletions binding/web/test/falcon_perf.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { Falcon, FalconWorker } from '../';

const ACCESS_KEY = Cypress.env('ACCESS_KEY');
const NUM_TEST_ITERATIONS = Number(Cypress.env('NUM_TEST_ITERATIONS'));
const INIT_PERFORMANCE_THRESHOLD_SEC = Number(
Cypress.env('INIT_PERFORMANCE_THRESHOLD_SEC')
);
const PROC_PERFORMANCE_THRESHOLD_SEC = Number(
Cypress.env('PROC_PERFORMANCE_THRESHOLD_SEC')
);
// const ACCESS_KEY = Cypress.env('ACCESS_KEY');
// const NUM_TEST_ITERATIONS = Number(Cypress.env('NUM_TEST_ITERATIONS'));
// const INIT_PERFORMANCE_THRESHOLD_SEC = Number(
// Cypress.env('INIT_PERFORMANCE_THRESHOLD_SEC')
// );
// const PROC_PERFORMANCE_THRESHOLD_SEC = Number(
// Cypress.env('PROC_PERFORMANCE_THRESHOLD_SEC')
// );

const ACCESS_KEY = 'mW3jTf9S6NUBzDHDpN/lNLNE9k8wk2ERjIKPGeX3tM62LzxFbdFtIQ==';
const NUM_TEST_ITERATIONS = 15;
const INIT_PERFORMANCE_THRESHOLD_SEC = 4.5;
const PROC_PERFORMANCE_THRESHOLD_SEC = 0.3;

async function testPerformance(
instance: typeof Falcon | typeof FalconWorker,
20 changes: 10 additions & 10 deletions binding/web/yarn.lock
Original file line number Diff line number Diff line change
@@ -1108,12 +1108,12 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@picovoice/web-utils@=1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@picovoice/web-utils/-/web-utils-1.3.1.tgz#d417e98604a650b54a8e03669015ecf98c2383ec"
integrity sha512-jcDqdULtTm+yJrnHDjg64hARup+Z4wNkYuXHNx6EM8+qZkweBq9UA6XJrHAlUkPnlkso4JWjaIKhz3x8vZcd3g==
"@picovoice/web-utils@=1.3.2":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@picovoice/web-utils/-/web-utils-1.3.2.tgz#9fe0a798a1f016fa8d8c28e48537466aa2854ca3"
integrity sha512-jDZn+kxVUyzM84kGVmq9hU6N60K2VH3sDevpZSw4CNDx3ppSz9Biz7aPHs+i16ssYJCxJweiJ44XhI+5Lo5ZjQ==
dependencies:
commander "^9.2.0"
commander "^10.0.1"

"@rollup/plugin-babel@^6.0.3":
version "6.0.4"
@@ -1687,6 +1687,11 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
dependencies:
delayed-stream "~1.0.0"

commander@^10.0.1:
version "10.0.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.1.tgz#881ee46b4f77d1c1dccc5823433aa39b022cbe06"
integrity sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==

commander@^2.20.0:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
@@ -1697,11 +1702,6 @@ commander@^6.2.1:
resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c"
integrity sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==

commander@^9.2.0:
version "9.5.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30"
integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==

common-tags@^1.8.0:
version "1.8.2"
resolved "https://registry.yarnpkg.com/common-tags/-/common-tags-1.8.2.tgz#94ebb3c076d26032745fd54face7f688ef5ac9c6"
2 changes: 1 addition & 1 deletion demo/web/package.json
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
"Falcon",
"browser",
"voice ai",
"speech recognition"
"speaker diarization"
],
"author": "Picovoice Inc",
"license": "Apache-2.0",
14 changes: 13 additions & 1 deletion demo/web/yarn.lock
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
"@picovoice/falcon-web@file:../../binding/web":
version "1.0.0"
dependencies:
"@picovoice/web-utils" "=1.3.1"
"@picovoice/web-utils" "=1.3.2"

"@picovoice/web-utils@=1.3.1":
version "1.3.1"
@@ -14,6 +14,13 @@
dependencies:
commander "^9.2.0"

"@picovoice/web-utils@=1.3.2":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@picovoice/web-utils/-/web-utils-1.3.2.tgz#9fe0a798a1f016fa8d8c28e48537466aa2854ca3"
integrity sha512-jDZn+kxVUyzM84kGVmq9hU6N60K2VH3sDevpZSw4CNDx3ppSz9Biz7aPHs+i16ssYJCxJweiJ44XhI+5Lo5ZjQ==
dependencies:
commander "^10.0.1"

"@picovoice/web-voice-processor@~4.0.8":
version "4.0.8"
resolved "https://registry.yarnpkg.com/@picovoice/web-voice-processor/-/web-voice-processor-4.0.8.tgz#95247a5393cac4d16490a53feb0f413c902ee5fa"
@@ -71,6 +78,11 @@ color-name@~1.1.4:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==

commander@^10.0.1:
version "10.0.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.1.tgz#881ee46b4f77d1c1dccc5823433aa39b022cbe06"
integrity sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==

commander@^9.2.0:
version "9.5.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30"