Skip to content

Commit

Permalink
check err status for rust (#1164)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksyeo1010 authored Nov 16, 2023
1 parent 18c6dfc commit 5aa6aea
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
paths:
- '.github/workflows/rust.yml'
- 'binding/rust/**'
- 'binding/rust/**/*.rs'
- '!binding/rust/README.md'
- 'lib/beaglebone/**'
- 'lib/common/**'
Expand All @@ -28,6 +29,7 @@ on:
paths:
- '.github/workflows/rust.yml'
- 'binding/rust/**'
- 'binding/rust/**/*.rs'
- '!binding/rust/README.md'
- 'lib/beaglebone/**'
- 'lib/common/**'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ For more information about Go demos go to [demo/go](demo/go).

### Unity Demos

To run the Porcupine Unity demo, import the [Porcupine Unity package](binding/unity/porcupine-2.1.3.unitypackage) into your project, open the PorcupineDemo scene and hit play. To run on other platforms or in the player, go to _File > Build Settings_, choose your platform and hit the `Build and Run` button.
To run the Porcupine Unity demo, import the [Porcupine Unity package](binding/unity/porcupine-3.0.0.unitypackage) into your project, open the PorcupineDemo scene and hit play. To run on other platforms or in the player, go to _File > Build Settings_, choose your platform and hit the `Build and Run` button.

To browse the demo source go to [demo/unity](demo/unity).

Expand Down Expand Up @@ -778,7 +778,7 @@ porcupine.Delete()

### Unity

Import the [Porcupine Unity Package](binding/unity/porcupine-2.1.3.unitypackage) into your Unity project.
Import the [Porcupine Unity Package](binding/unity/porcupine-3.0.0.unitypackage) into your Unity project.

The SDK provides two APIs:

Expand Down
11 changes: 9 additions & 2 deletions binding/rust/src/porcupine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ type PvSampleRateFn = unsafe extern "C" fn() -> i32;
type PvPorcupineFrameLengthFn = unsafe extern "C" fn() -> i32;
type PvPorcupineVersionFn = unsafe extern "C" fn() -> *mut c_char;
type PvGetErrorStackFn =
unsafe extern "C" fn(message_stack: *mut *mut *mut c_char, message_stack_depth: *mut i32);
unsafe extern "C" fn(message_stack: *mut *mut *mut c_char, message_stack_depth: *mut i32) -> PvStatus;
type PvFreeErrorStackFn = unsafe extern "C" fn(message_stack: *mut *mut c_char);
type PvSetSdkFn = unsafe extern "C" fn(sdk: *const c_char);

Expand Down Expand Up @@ -350,11 +350,18 @@ fn check_fn_call_status(
let mut message_stack_ptr_ptr = addr_of_mut!(message_stack_ptr);

let mut message_stack_depth: i32 = 0;
(vtable.pv_get_error_stack)(
let err_status = (vtable.pv_get_error_stack)(
addr_of_mut!(message_stack_ptr_ptr),
addr_of_mut!(message_stack_depth),
);

if err_status != PvStatus::SUCCESS {
return Err(PorcupineError::new(
PorcupineErrorStatus::LibraryError(err_status),
"Unable to get Porcupine error state",
));
};

let mut message_stack = Vec::new();
for i in 0..message_stack_depth as usize {
let message = CStr::from_ptr(*message_stack_ptr_ptr.add(i));
Expand Down
8 changes: 3 additions & 5 deletions binding/unity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@ To learn more about Porcupine, see the [product](https://picovoice.ai/products/p

## Compatibility

[Porcupine unity package](porcupine-2.2.2.unitypackage) is for running Porcupine on **Unity 2017.4+** on the following platforms:
[Porcupine unity package](porcupine-3.0.0.unitypackage) is for running Porcupine on **Unity 2017.4+** on the following platforms:

- Android 5.0+ (API 21+) (ARM only)
- iOS 11.0+
- iOS 13.0+
- Windows (x86_64)
- macOS (x86_64)
- Linux (x86_64)

For running Porcupine on **macOS M1 (arm64)**, use the [Apple Silicon](porcupine-2.2.2-Apple-silicon.unitypackage) version on **Unity 2021.2+**.

## Installation

The easiest way to install the Porcupine Unity SDK is to import [porcupine-2.2.2.unitypackage](porcupine-2.2.2.unitypackage) into your Unity projects by either dropping it into the Unity editor or going to _Assets>Import Package>Custom Package..._
The easiest way to install the Porcupine Unity SDK is to import [porcupine-3.0.0.unitypackage](porcupine-3.0.0.unitypackage) into your Unity projects by either dropping it into the Unity editor or going to _Assets>Import Package>Custom Package..._

**NOTE:** On macOS, the Porcupine library may get flagged as having come from an unverified source if you've downloaded the `.unitypackage` directly from GitHub. This should only come up when running your project in the Editor. To disable this warning, go to Security & Preferences and choose to allow pv_porcupine.dylib to run.

Expand Down
6 changes: 3 additions & 3 deletions demo/unity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
The Porcupine demo for Unity is a multi-platform demo that runs on:

- Desktop Standalone (Windows, macOS and Linux x86_64)
- iOS 9.0+
- Android 4.1+
- iOS 13.0+
- Android 5.0+

Additionally, you will need a version of Unity that is 2017.4 or higher.

## Usage
The easiest way to run the demo is to simply import the [Porcupine Unity package](../../binding/unity/porcupine-2.1.3.unitypackage) into your project, open the PorcupineDemo scene and hit play. To run on other platforms or in the player, go to _File > Build Settings_, choose your platform and hit the `Build and Run` button.
The easiest way to run the demo is to simply import the [Porcupine Unity package](../../binding/unity/porcupine-3.0.0.unitypackage) into your project, open the PorcupineDemo scene and hit play. To run on other platforms or in the player, go to _File > Build Settings_, choose your platform and hit the `Build and Run` button.

Once the demo launches, press the `Start Listening` button and try out any of the listed wake words.

Expand Down

0 comments on commit 5aa6aea

Please sign in to comment.