Skip to content

Commit

Permalink
Web sdk (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
albho authored Jan 15, 2024
1 parent 6564380 commit c8d4a3c
Show file tree
Hide file tree
Showing 45 changed files with 7,751 additions and 2 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/web-codestyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Web Codestyle

on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- '**/web/*.js'
- '**/web/*.ts'
- '.github/workflows/web-codestyle.yml'
pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- '**/web/*.js'
- '**/web/*.ts'
- '.github/workflows/web-codestyle.yml'

jobs:
check-web-codestyle:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Node.js LTS
uses: actions/setup-node@v3
with:
node-version: lts/*

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

- name: Run Binding Linter
run: yarn && yarn lint
working-directory: binding/web
42 changes: 42 additions & 0 deletions .github/workflows/web-demos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Web Demos

on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- 'demo/web/**'
- '!demo/web/README.md'
- '.github/workflows/web-demos.yml'
pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- 'demo/web/**'
- '!demo/web/README.md'
- '.github/workflows/web-demos.yml'

defaults:
run:
working-directory: demo/web

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3

- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

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

- name: Install dependencies
run: yarn install
58 changes: 58 additions & 0 deletions .github/workflows/web-perf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Web Performance

on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- 'lib/wasm/**'
- 'lib/common/**'
- '.github/workflows/web-perf.yml'
pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- 'lib/wasm/**'
- 'lib/common/**'
- '.github/workflows/web-perf.yml'

defaults:
run:
working-directory: binding/web

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [lts/*]
include:
- node-version: lts/*
initPerformanceThresholdSec: 9.0
procPerformanceThresholdSec: 0.8

steps:
- uses: actions/checkout@v3

- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

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

- name: Install dependencies
run: yarn install

- name: Copy libs
run: yarn copywasm

- name: Build
run: yarn build

- name: Prepare Test
run: yarn setup-test

- name: Test
run: yarn test-perf --env ACCESS_KEY=${{secrets.PV_VALID_ACCESS_KEY}},NUM_TEST_ITERATIONS=20,INIT_PERFORMANCE_THRESHOLD_SEC=${{matrix.initPerformanceThresholdSec}},PROC_PERFORMANCE_THRESHOLD_SEC=${{matrix.procPerformanceThresholdSec}}
56 changes: 56 additions & 0 deletions .github/workflows/web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Web

on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- 'binding/web/**'
- '!binding/web/README.md'
- 'lib/wasm/**'
- '.github/workflows/web.yml'
pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- 'binding/web/**'
- '!binding/web/README.md'
- 'lib/wasm/**'
- '.github/workflows/web.yml'

defaults:
run:
working-directory: binding/web

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3

- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

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

- name: Install dependencies
run: yarn install

- name: Copy libs
run: yarn copywasm

- name: Build
run: yarn build

- name: Prepare Test
run: yarn setup-test

- name: Test
run: yarn test --env ACCESS_KEY=${{secrets.PV_VALID_ACCESS_KEY}}
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions binding/web/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-transform-runtime"]
}
5 changes: 5 additions & 0 deletions binding/web/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
lib
rollup.config.js
.eslintrc.js
Loading

0 comments on commit c8d4a3c

Please sign in to comment.