Skip to content

Commit

Permalink
wasm detach fix (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksyeo1010 authored Jul 20, 2023
1 parent d3fca81 commit 7a7e694
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 94 deletions.
2 changes: 1 addition & 1 deletion binding/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@angular/cli": "~13.3.9",
"@angular/compiler-cli": "~13.3.0",
"@picovoice/rhino-web": "~2.2.0",
"@picovoice/web-voice-processor": "~4.0.6",
"@picovoice/web-voice-processor": "~4.0.8",
"@types/node": "^12.11.1",
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.27.1",
Expand Down
6 changes: 3 additions & 3 deletions binding/angular/projects/rhino-angular/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@picovoice/rhino-angular",
"description": "Angular service for Rhino Web SDK",
"version": "2.2.0",
"version": "2.2.1",
"peerDependencies": {
"@angular/common": ">=13.0.0",
"@angular/core": ">=13.0.0",
"@picovoice/web-voice-processor": "~4.0.6"
"@picovoice/web-voice-processor": "~4.0.8"
},
"keywords": [
"rhino",
Expand All @@ -22,7 +22,7 @@
"author": "Picovoice Inc",
"license": "Apache-2.0",
"dependencies": {
"@picovoice/rhino-web": "=2.2.0",
"@picovoice/rhino-web": "=2.2.1",
"tslib": "^2.3.0"
}
}
10 changes: 6 additions & 4 deletions binding/angular/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1676,10 +1676,12 @@
dependencies:
commander "^9.2.0"

"@picovoice/web-voice-processor@~4.0.6":
version "4.0.6"
resolved "https://registry.yarnpkg.com/@picovoice/web-voice-processor/-/web-voice-processor-4.0.6.tgz#4769283b82f64d3625794f7290d47c6d477a3f41"
integrity sha512-Ykfy6hrWFpOklfeN7rSJb5CGim8wDu7J+l8imRYyQxWHWVV1Wu5S8FW69zkJmwiDG2Wx+M2+h0SCMS+hNM5qow==
"@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"
integrity sha512-/OSHn8YKniMo0jP5EwGimLOxvLQl/Yx4Hs+LydNmoSu4hfBrDdzhhfhB79118uDiK4aUUKx2A/RAD9TG0mQ/ng==
dependencies:
"@picovoice/web-utils" "=1.3.1"

"@rollup/plugin-json@^4.1.0":
version "4.1.0"
Expand Down
6 changes: 3 additions & 3 deletions binding/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@picovoice/rhino-react",
"version": "2.2.0",
"version": "2.2.1",
"description": "React component for Rhino Web SDK",
"entry": "src/index.ts",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -39,7 +39,7 @@
"@babel/plugin-transform-runtime": "^7.21.0",
"@babel/preset-env": "^7.20.2",
"@babel/runtime": "^7.21.0",
"@picovoice/web-voice-processor": "~4.0.6",
"@picovoice/web-voice-processor": "~4.0.8",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
Expand Down Expand Up @@ -68,7 +68,7 @@
"vite": "^3.2.5"
},
"peerDependencies": {
"@picovoice/web-voice-processor": "~4.0.6",
"@picovoice/web-voice-processor": "~4.0.8",
"react": ">=17",
"react-dom": ">=17"
},
Expand Down
10 changes: 6 additions & 4 deletions binding/react/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1252,10 +1252,12 @@
dependencies:
commander "^9.2.0"

"@picovoice/web-voice-processor@~4.0.6":
version "4.0.6"
resolved "https://registry.yarnpkg.com/@picovoice/web-voice-processor/-/web-voice-processor-4.0.6.tgz#4769283b82f64d3625794f7290d47c6d477a3f41"
integrity sha512-Ykfy6hrWFpOklfeN7rSJb5CGim8wDu7J+l8imRYyQxWHWVV1Wu5S8FW69zkJmwiDG2Wx+M2+h0SCMS+hNM5qow==
"@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"
integrity sha512-/OSHn8YKniMo0jP5EwGimLOxvLQl/Yx4Hs+LydNmoSu4hfBrDdzhhfhB79118uDiK4aUUKx2A/RAD9TG0mQ/ng==
dependencies:
"@picovoice/web-utils" "=1.3.1"

"@rollup/plugin-babel@^6.0.3":
version "6.0.3"
Expand Down
6 changes: 3 additions & 3 deletions binding/vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@picovoice/rhino-vue",
"version": "2.2.0",
"version": "2.2.1",
"description": "Vue binding for Rhino Web SDK",
"author": "Picovoice Inc",
"license": "Apache-2.0",
Expand All @@ -25,7 +25,7 @@
"@babel/plugin-transform-runtime": "^7.21.0",
"@babel/preset-env": "^7.20.2",
"@babel/runtime": "^7.21.0",
"@picovoice/web-voice-processor": "~4.0.6",
"@picovoice/web-voice-processor": "~4.0.8",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
Expand All @@ -52,7 +52,7 @@
"vue": "^3.2.47"
},
"peerDependencies": {
"@picovoice/web-voice-processor": "~4.0.6",
"@picovoice/web-voice-processor": "~4.0.8",
"vue": "^2.6.11 || ^3.0.0"
},
"dependencies": {
Expand Down
10 changes: 6 additions & 4 deletions binding/vue/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1245,10 +1245,12 @@
dependencies:
commander "^9.2.0"

"@picovoice/web-voice-processor@~4.0.6":
version "4.0.6"
resolved "https://registry.yarnpkg.com/@picovoice/web-voice-processor/-/web-voice-processor-4.0.6.tgz#4769283b82f64d3625794f7290d47c6d477a3f41"
integrity sha512-Ykfy6hrWFpOklfeN7rSJb5CGim8wDu7J+l8imRYyQxWHWVV1Wu5S8FW69zkJmwiDG2Wx+M2+h0SCMS+hNM5qow==
"@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"
integrity sha512-/OSHn8YKniMo0jP5EwGimLOxvLQl/Yx4Hs+LydNmoSu4hfBrDdzhhfhB79118uDiK4aUUKx2A/RAD9TG0mQ/ng==
dependencies:
"@picovoice/web-utils" "=1.3.1"

"@rollup/plugin-babel@^6.0.3":
version "6.0.3"
Expand Down
2 changes: 1 addition & 1 deletion binding/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Rhino Speech-to-Intent engine for web browsers (via WebAssembly)",
"author": "Picovoice Inc",
"license": "Apache-2.0",
"version": "2.2.0",
"version": "2.2.1",
"keywords": [
"rhino",
"web",
Expand Down
60 changes: 34 additions & 26 deletions binding/web/src/rhino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ export class Rhino {

private _wasmMemory: WebAssembly.Memory | undefined;
private readonly _pvFree: pv_free_type;
private readonly _memoryBuffer: Int16Array;
private readonly _memoryBufferUint8: Uint8Array;
private readonly _memoryBufferView: DataView;
private readonly _processMutex: Mutex;

private readonly _contextAddress: number;
Expand Down Expand Up @@ -184,9 +181,6 @@ export class Rhino {
this._slotsAddressAddressAddress = handleWasm.slotsAddressAddressAddress;
this._valuesAddressAddressAddress = handleWasm.valuesAddressAddressAddress;

this._memoryBuffer = new Int16Array(handleWasm.memory.buffer);
this._memoryBufferUint8 = new Uint8Array(handleWasm.memory.buffer);
this._memoryBufferView = new DataView(handleWasm.memory.buffer);
this._processMutex = new Mutex();

this._inferenceCallback = inferenceCallback;
Expand Down Expand Up @@ -351,8 +345,9 @@ export class Rhino {
if (this._wasmMemory === undefined) {
throw new Error('Attempted to call Rhino process after release.');
}
const memoryBuffer = new Int16Array(this._wasmMemory.buffer);

this._memoryBuffer.set(
memoryBuffer.set(
pcm,
this._inputBufferAddress / Int16Array.BYTES_PER_ELEMENT
);
Expand All @@ -362,16 +357,20 @@ export class Rhino {
this._inputBufferAddress,
this._isFinalizedAddress
);

let memoryBufferUint8 = new Uint8Array(this._wasmMemory.buffer);
const memoryBufferView = new DataView(this._wasmMemory.buffer);

if (status !== PV_STATUS_SUCCESS) {
throw new Error(
`'pv_rhino_process' failed with status ${arrayBufferToStringAtIndex(
this._memoryBufferUint8,
memoryBufferUint8,
await this._pvStatusToString(status)
)}`
);
}

const isFinalized = this._memoryBufferView.getUint8(
const isFinalized = memoryBufferView.getUint8(
this._isFinalizedAddress
);

Expand All @@ -383,13 +382,13 @@ export class Rhino {
if (status !== PV_STATUS_SUCCESS) {
throw new Error(
`'pv_rhino_is_understood' failed with status ${arrayBufferToStringAtIndex(
this._memoryBufferUint8,
memoryBufferUint8,
await this._pvStatusToString(status)
)}`
);
}

const isUnderstood = this._memoryBufferView.getUint8(
const isUnderstood = memoryBufferView.getUint8(
this._isUnderstoodAddress
);

Expand All @@ -410,22 +409,22 @@ export class Rhino {
if (status !== PV_STATUS_SUCCESS) {
throw new Error(
`'pv_rhino_get_intent' failed with status ${arrayBufferToStringAtIndex(
this._memoryBufferUint8,
memoryBufferUint8,
await this._pvStatusToString(status)
)}`
);
}

const intentAddress = this._memoryBufferView.getInt32(
const intentAddress = memoryBufferView.getInt32(
this._intentAddressAddress,
true
);
intent = arrayBufferToStringAtIndex(
this._memoryBufferUint8,
memoryBufferUint8,
intentAddress
);

const numSlots = this._memoryBufferView.getInt32(
const numSlots = memoryBufferView.getInt32(
this._numSlotsAddress,
true
);
Expand All @@ -445,12 +444,12 @@ export class Rhino {
slots[slot] = value;
}

const slotsAddressAddress = this._memoryBufferView.getInt32(
const slotsAddressAddress = memoryBufferView.getInt32(
this._slotsAddressAddressAddress,
true
);

const valuesAddressAddress = this._memoryBufferView.getInt32(
const valuesAddressAddress = memoryBufferView.getInt32(
this._valuesAddressAddressAddress,
true
);
Expand All @@ -461,9 +460,10 @@ export class Rhino {
valuesAddressAddress
);
if (status !== PV_STATUS_SUCCESS) {
memoryBufferUint8 = new Uint8Array(this._wasmMemory.buffer);
throw new Error(
`'pv_rhino_free_slots_values' failed with status ${arrayBufferToStringAtIndex(
this._memoryBufferUint8,
memoryBufferUint8,
await this._pvStatusToString(status)
)}`
);
Expand All @@ -472,9 +472,10 @@ export class Rhino {

status = await this._pvRhinoReset(this._objectAddress);
if (status !== PV_STATUS_SUCCESS) {
memoryBufferUint8 = new Uint8Array(this._wasmMemory.buffer);
throw new Error(
`'pv_rhino_process' failed with status ${arrayBufferToStringAtIndex(
this._memoryBufferUint8,
memoryBufferUint8,
await this._pvStatusToString(status)
)}`
);
Expand Down Expand Up @@ -507,31 +508,37 @@ export class Rhino {
}

private _getSlot(index: number): string {
const slotsAddressAddress = this._memoryBufferView.getInt32(
const memoryBufferUint8 = new Uint8Array(this._wasmMemory.buffer);
const memoryBufferView = new DataView(this._wasmMemory.buffer);

const slotsAddressAddress = memoryBufferView.getInt32(
this._slotsAddressAddressAddress,
true
);

const slotAddress = this._memoryBufferView.getInt32(
const slotAddress = memoryBufferView.getInt32(
slotsAddressAddress + index * Int32Array.BYTES_PER_ELEMENT,
true
);

return arrayBufferToStringAtIndex(this._memoryBufferUint8, slotAddress);
return arrayBufferToStringAtIndex(memoryBufferUint8, slotAddress);
}

private _getSlotValue(index: number): string {
const valuesAddressAddress = this._memoryBufferView.getInt32(
const memoryBufferUint8 = new Uint8Array(this._wasmMemory.buffer);
const memoryBufferView = new DataView(this._wasmMemory.buffer);

const valuesAddressAddress = memoryBufferView.getInt32(
this._valuesAddressAddressAddress,
true
);

const valueAddress = this._memoryBufferView.getInt32(
const valueAddress = memoryBufferView.getInt32(
valuesAddressAddress + index * Int32Array.BYTES_PER_ELEMENT,
true
);

return arrayBufferToStringAtIndex(this._memoryBufferUint8, valueAddress);
return arrayBufferToStringAtIndex(memoryBufferUint8, valueAddress);
}

/**
Expand All @@ -540,9 +547,10 @@ export class Rhino {
public async reset(): Promise<void> {
const status = await this._pvRhinoReset(this._objectAddress);
if (status !== PV_STATUS_SUCCESS) {
const memoryBufferUint8 = new Uint8Array(this._wasmMemory.buffer);
throw new Error(
`'pv_rhino_process' failed with status ${arrayBufferToStringAtIndex(
this._memoryBufferUint8,
memoryBufferUint8,
await this._pvStatusToString(status)
)}`
);
Expand Down
4 changes: 2 additions & 2 deletions demo/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"@angular/platform-browser": "^15.0.3",
"@angular/platform-browser-dynamic": "^15.0.3",
"@angular/router": "^15.0.3",
"@picovoice/rhino-angular": "~2.2.0",
"@picovoice/web-voice-processor": "~4.0.6",
"@picovoice/rhino-angular": "~2.2.1",
"@picovoice/web-voice-processor": "~4.0.8",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
Expand Down
28 changes: 15 additions & 13 deletions demo/angular/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1534,18 +1534,18 @@
read-package-json-fast "^3.0.0"
which "^3.0.0"

"@picovoice/rhino-angular@~2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@picovoice/rhino-angular/-/rhino-angular-2.2.0.tgz#c073e481c775cda4170ba23204c9949dea231951"
integrity sha512-LL7VhnV5uNPAdEaQPxQVRTabN38tIMiplnb26x254qKd+4Tkc+sj7w8DqyregOCCoFTWM0+Z21ktcg8ZxLNwwQ==
"@picovoice/rhino-angular@~2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@picovoice/rhino-angular/-/rhino-angular-2.2.1.tgz#067b24d16f4798febe4d55a2d3bc7bac62ab8b2f"
integrity sha512-XCj2Pu8egElhY7JlJO9K2DWJ7BdUP/e9DQxGXcCayj9AYWPdzXWHtesLcz42Wy7kl9lMyRHejvrxHEGfDPK5+Q==
dependencies:
"@picovoice/rhino-web" "=2.2.0"
"@picovoice/rhino-web" "=2.2.1"
tslib "^2.3.0"

"@picovoice/rhino-web@=2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@picovoice/rhino-web/-/rhino-web-2.2.0.tgz#fb221654e3c0977b8b1b417f42bf0eb510cf6750"
integrity sha512-2ckCNq9ayVQ6GKEZ0OFXy7NIdEIOiyXsGQPjDfHRDKhMf7EATnR4AgVIEXLwKCSg8WfFCZkXOw33E3V47QEUAA==
"@picovoice/rhino-web@=2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@picovoice/rhino-web/-/rhino-web-2.2.1.tgz#68ece011d99ecd638e8935147c8e443c294becf5"
integrity sha512-kwNNvuUt+6x/kfLplLeCV1J2RbTZEkKwe5WoyY6yZbtJB1Tb/+HcWlNaeSU1kLTegxZ6UL+ETT/gay4psDKLmQ==
dependencies:
"@picovoice/web-utils" "=1.3.1"

Expand All @@ -1556,10 +1556,12 @@
dependencies:
commander "^9.2.0"

"@picovoice/web-voice-processor@~4.0.6":
version "4.0.6"
resolved "https://registry.yarnpkg.com/@picovoice/web-voice-processor/-/web-voice-processor-4.0.6.tgz#4769283b82f64d3625794f7290d47c6d477a3f41"
integrity sha512-Ykfy6hrWFpOklfeN7rSJb5CGim8wDu7J+l8imRYyQxWHWVV1Wu5S8FW69zkJmwiDG2Wx+M2+h0SCMS+hNM5qow==
"@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"
integrity sha512-/OSHn8YKniMo0jP5EwGimLOxvLQl/Yx4Hs+LydNmoSu4hfBrDdzhhfhB79118uDiK4aUUKx2A/RAD9TG0mQ/ng==
dependencies:
"@picovoice/web-utils" "=1.3.1"

"@schematics/[email protected]":
version "15.1.3"
Expand Down
Loading

0 comments on commit 7a7e694

Please sign in to comment.