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

v3.0 unity #693

Merged
merged 4 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
47 changes: 24 additions & 23 deletions .github/workflows/unity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,38 @@ jobs:

- name: Run tests
run: xvfb-run --auto-servernum --server-args='-screen 0 640x480x24'
/home/picovoice/Unity/Hub/Editor/2019.4.34f1/Editor/Unity -runTests -batchmode -projectPath . -testResults unityresults.xml -testPlatform StandaloneLinux64 -logFile -
/home/picovoice/Unity/Hub/Editor/2021.3.31f1/Editor/Unity -runTests -batchmode -projectPath . -testResults unityresults.xml -testPlatform StandaloneLinux64 -logFile -

- name: Check Results
run: sed -n 2p unityresults.xml | grep 'result="Passed"'

playtest-mac:
name: Run PlayTest unit tests on macOS
runs-on: pv-ios
# NOTE: fix later as mac runner halts unity test app in between runs. Running locally works fine as well as first try after restarting runner.
# playtest-mac:
# name: Run PlayTest unit tests on macOS
# runs-on: pv-ios

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
# steps:
# - uses: actions/checkout@v3
# with:
# submodules: 'recursive'

- name: Pre-build dependencies
run: |
./copy.sh
./copy_test_resources.sh
# - name: Pre-build dependencies
# run: |
# ./copy.sh
# ./copy_test_resources.sh

- name: Clean conflicting dylib
run: rm -rf Assets/Picovoice/Plugins/mac/arm64
# - name: Clean conflicting dylib
# run: rm -rf Assets/Picovoice/Plugins/mac/arm64

- name: Inject AppID
run: sed -i '.bak' 's:{TESTING_ACCESS_KEY_HERE}:${{secrets.PV_VALID_ACCESS_KEY}}:'
Assets/Picovoice/Tests/Integration.cs
# - name: Inject AppID
# run: sed -i '.bak' 's:{TESTING_ACCESS_KEY_HERE}:${{secrets.PV_VALID_ACCESS_KEY}}:'
# Assets/Picovoice/Tests/Integration.cs

- name: Run tests
run: /Applications/Unity/Hub/Editor/2019.4.34f1/Unity.app/Contents/MacOS/Unity -runTests -batchmode -projectPath . -testResults unityresults.xml -testPlatform StandaloneOSX -logFile -
# - name: Run tests
# run: /Applications/Unity/Hub/Editor/2021.3.31f1/Unity.app/Contents/MacOS/Unity -runTests -batchmode -projectPath . -testResults unityresults.xml -testPlatform StandaloneOSX -logFile -

- name: Check Results
run: sed -n 2p unityresults.xml | grep 'result="Passed"'
# - name: Check Results
# run: sed -n 2p unityresults.xml | grep 'result="Passed"'

playtest-windows:
name: Run PlayTest unit tests on Windows
Expand All @@ -102,7 +103,7 @@ jobs:

- name: Run tests
run: >
& "C:\Program Files\Unity\Hub\Editor\2019.4.34f1\Editor\Unity.exe" -runTests -batchmode -projectPath . -testResults unityresults.xml -testPlatform StandaloneWindows64 -logFile - | Out-Host
& "C:\Program Files\Unity\Hub\Editor\2021.3.31f1\Editor\Unity.exe" -runTests -batchmode -projectPath . -testResults unityresults.xml -testPlatform StandaloneWindows64 -logFile - | Out-Host
- name: Check Results
run: bash -c "sed -n 2p unityresults.xml | grep Passed"

Expand Down Expand Up @@ -131,7 +132,7 @@ jobs:
run: /Users/alirezakenarsari-anhari/Library/Android/sdk/emulator/emulator -avd Pixel_6_API_33 &

- name: Run tests
run: /Applications/Unity/Hub/Editor/2019.4.34f1/Unity.app/Contents/MacOS/Unity -runTests -batchmode -projectPath . -testResults unityresults.xml -testPlatform Android -logFile -
run: /Applications/Unity/Hub/Editor/2021.3.31f1/Unity.app/Contents/MacOS/Unity -runTests -batchmode -buildTarget Android -projectPath . -testResults unityresults.xml -testPlatform Android -logFile -

- name: Check Results
run: sed -n 2p unityresults.xml | grep 'result="Passed"'
65 changes: 35 additions & 30 deletions demo/unity/PicovoiceDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,40 @@ void Start()
_errorMessage = gameObject.transform.Find("ErrorMessage").GetComponent<Text>();
_locationStates = gameObject.GetComponentsInChildren<Image>();

_picovoiceManager = PicovoiceManager.Create(ACCESS_KEY, _keywordPath, OnWakeWordDetected, _contextPath, OnInferenceResult, processErrorCallback: ErrorCallback);
try
{
_picovoiceManager = PicovoiceManager.Create(
ACCESS_KEY,
_keywordPath,
OnWakeWordDetected,
_contextPath,
OnInferenceResult,
processErrorCallback: ErrorCallback);
}
catch (PicovoiceInvalidArgumentException ex)
{
SetError(ex.Message);
}
catch (PicovoiceActivationException)
{
SetError("AccessKey activation error");
}
catch (PicovoiceActivationLimitException)
{
SetError("AccessKey reached its device limit");
}
catch (PicovoiceActivationRefusedException)
{
SetError("AccessKey refused");
}
catch (PicovoiceActivationThrottledException)
{
SetError("AccessKey has been throttled");
}
catch (PicovoiceException ex)
{
SetError("PicovoiceManager was unable to start: " + ex.Message);
}
}


Expand Down Expand Up @@ -162,39 +195,11 @@ void Update()
{
if (_picovoiceManager.IsAudioDeviceAvailable())
{
try
{
_picovoiceManager.Start();
}
catch (PicovoiceInvalidArgumentException ex)
{
SetError($"{ex.Message}\nMake sure your access key '{ACCESS_KEY}' is a valid access key.");
}
catch (PicovoiceActivationException)
{
SetError("AccessKey activation error");
}
catch (PicovoiceActivationLimitException)
{
SetError("AccessKey reached its device limit");
}
catch (PicovoiceActivationRefusedException)
{
SetError("AccessKey refused");
}
catch (PicovoiceActivationThrottledException)
{
SetError("AccessKey has been throttled");
}
catch (PicovoiceException ex)
{
SetError("PicovoiceManager was unable to start: " + ex.Message);
}
_picovoiceManager.Start();
}
else
SetError("No audio recording device available!");
}

}

void OnApplicationQuit()
Expand Down
2 changes: 2 additions & 0 deletions sdk/unity/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ Assets/Picovoice/Rhino*.cs

Assets/StreamingAssets/test/
Assets/InitTestScene*
.vscode
UserSettings
57 changes: 43 additions & 14 deletions sdk/unity/Assets/Picovoice/Picovoice.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2021 Picovoice Inc.
// Copyright 2021-2023 Picovoice Inc.
//
// You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
// file accompanying this source.
Expand Down Expand Up @@ -39,7 +39,7 @@ public class Picovoice : IDisposable
/// Gets the version number of the Picovoice platform
/// </summary>
/// <returns>Version of Picovoice</returns>
public string Version => "2.0.0";
public string Version => "3.0.0";

/// <summary>
/// Get the version of the Porcupine library
Expand Down Expand Up @@ -192,24 +192,53 @@ public void Process(short[] pcm)
throw new PicovoiceInvalidStateException("Cannot process frame - resources have been released.");
}

if (!_isWakeWordDetected)
try
{
int keywordIndex = _porcupine.Process(pcm);
if (keywordIndex >= 0)
if (!_isWakeWordDetected)
{
_isWakeWordDetected = true;
_wakeWordCallback.Invoke();
int keywordIndex = _porcupine.Process(pcm);
if (keywordIndex >= 0)
{
_isWakeWordDetected = true;
_wakeWordCallback.Invoke();
}
}
}
else
{
bool isFinalized = _rhino.Process(pcm);
if (isFinalized)
else
{
_isWakeWordDetected = false;
_inferenceCallback.Invoke(_rhino.GetInference());
bool isFinalized = _rhino.Process(pcm);
if (isFinalized)
{
_isWakeWordDetected = false;
_inferenceCallback.Invoke(_rhino.GetInference());
}
}
}
catch (Exception ex)
{
throw MapToPicovoiceException(ex);
}
}

/// <summary>
/// Resets the internal state of Picovoice. It should be called before processing a new stream of audio
/// or when process was stopped while processing a stream of audio.
/// </summary>
public void Reset()
{
if (_porcupine == null || _rhino == null)
{
throw new PicovoiceInvalidStateException("Cannot reset - resources have been released.");
}

try
{
_isWakeWordDetected = false;
_rhino.Reset();
}
catch (Exception ex)
{
throw MapToPicovoiceException(ex);
}
}

/// <summary>
Expand Down
Loading