Skip to content

Commit

Permalink
Web binding (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
albho authored Feb 21, 2024
1 parent 059cd4d commit 107d8b5
Show file tree
Hide file tree
Showing 37 changed files with 7,863 additions and 0 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/*
num_test_iterations: 10
proc_performance_threshold_sec: 10

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: 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=${{matrix.num_test_iterations}},PROC_PERFORMANCE_THRESHOLD_SEC=${{matrix.proc_performance_threshold_sec}}
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}}
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Orca is an on-device text-to-speech engine producing high-quality, realistic, sp
- Cross-Platform:
- Linux (x86_64), macOS (x86_64, arm64), Windows (x86_64)
- Raspberry Pi (5, 4, 3) and NVIDIA Jetson Nano
- Chrome, Safari, Firefox, and Edge

**Please note that Orca is currently in development. While we prioritize stability and compatibility, certain aspects of
Orca may undergo changes as we continually enhance and refine the engine to provide the best user experience possible.**
Expand All @@ -34,11 +35,13 @@ Orca may undergo changes as we continually enhance and refine the engine to prov
- [Python](#python-demos)
- [iOS](#ios-demo)
- [C](#c-demos)
- [Web](#web-demos)
- [Android](#android-demo)
- [SDKs](#sdks)
- [Python](#python)
- [iOS](#ios)
- [C](#c)
- [Web](#web)
- [Android](#android)
- [AccessKey](#accesskey)
- [Releases](#releases)
Expand Down Expand Up @@ -147,6 +150,24 @@ Run the demo:
./demo/c/build/orca_demo -l ${LIBRARY_PATH} -m ${MODEL_PATH} -a ${ACCESS_KEY} -t ${TEXT} -o ${OUTPUT_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.

### Android Demo

Using Android Studio, open [demo/android/OrcaDemo](./demo/android/OrcaDemo) as an Android project and then run the application.
Expand Down Expand Up @@ -257,6 +278,37 @@ pv_orca_synthesize_params_delete(synthesize_params);
pv_orca_delete(handle);
```
### Web
Install the web SDK using yarn:
```console
yarn add @picovoice/orca-web
```

or using npm:

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

Create an instance of the engine using `OrcaWorker` and synthesize speech:

```typescript
import { OrcaWorker } from "@picovoice/orca-web";
import orcaParams from "${PATH_TO_BASE64_ORCA_PARAMS}";

const orca = await OrcaWorker.create(
"${ACCESS_KEY}",
{ base64: orcaParams }
);

const speechPcm = await orca.synthesize("${TEXT}")
```

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

### Android

To include the Orca package in your Android project, ensure you have included `mavenCentral()` in your top-level `build.gradle` file and then add the following to your app's `build.gradle`:
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"]
}
Loading

0 comments on commit 107d8b5

Please sign in to comment.