Skip to content

Commit

Permalink
update uvp (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksyeo1010 authored Aug 9, 2023
1 parent bcb6d2d commit fcc3091
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 37 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[submodule "binding/unity/Assets/Rhino/VoiceProcessor"]
path = binding/unity/Assets/Rhino/VoiceProcessor
[submodule "binding/unity/VoiceProcessor"]
path = binding/unity/VoiceProcessor
url = ../unity-voice-processor.git
[submodule "demo/c/dr_libs"]
path = demo/c/dr_libs
url = ../../mackron/dr_libs.git
[submodule "demo/c/pvrecorder"]
path = demo/c/pvrecorder
url = ../pvrecorder.git
url = ../pvrecorder.git
39 changes: 18 additions & 21 deletions binding/unity/Assets/Rhino/RhinoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace Pv.Unity

public class RhinoManager
{
private VoiceProcessor _voiceProcessor;
private Rhino _rhino;
private Action<Inference> _inferenceCallback;
private Action<RhinoException> _processErrorCallback;
Expand Down Expand Up @@ -69,26 +68,29 @@ private RhinoManager(Rhino rhino, Action<Inference> inferenceCallback, Action<Rh
_inferenceCallback = inferenceCallback;
_processErrorCallback = processErrorCallback;

_voiceProcessor = VoiceProcessor.Instance;
_voiceProcessor.OnFrameCaptured += OnFrameCaptured;
VoiceProcessor.Instance.AddFrameListener(OnFrameCaptured);
}

/// <summary>
/// Action to catch audio frames as voice processor produces them
/// </summary>
/// <param name="pcm">Frame of pcm audio</param>
private void OnFrameCaptured(short[] pcm)
/// <param name="frame">Frame of audio</param>
private void OnFrameCaptured(short[] frame)
{
try
{
bool _isFinalized = _rhino.Process(pcm);
bool _isFinalized = _rhino.Process(frame);
if (_isFinalized)
{
Inference inference = _rhino.GetInference();
if (_inferenceCallback != null)
_inferenceCallback.Invoke(inference);

_voiceProcessor.StopRecording();
VoiceProcessor.Instance.RemoveFrameListener(OnFrameCaptured);
if (VoiceProcessor.Instance.NumFrameListeners == 0)
{
VoiceProcessor.Instance.StopRecording();
}
}
}
catch (RhinoException ex)
Expand All @@ -104,48 +106,43 @@ private void OnFrameCaptured(short[] pcm)
/// Checks to see whether RhinoManager is capturing audio or not
/// </summary>
/// <returns>whether RhinoManager is capturing audio or not</returns>
public bool IsRecording => _voiceProcessor.IsRecording;
public bool IsRecording => VoiceProcessor.Instance.IsRecording;

/// <summary>
/// Checks to see whether there are any audio capture devices available
/// </summary>
/// <returns>whether there are any audio capture devices available</returns>
public bool IsAudioDeviceAvailable()
{
_voiceProcessor.UpdateDevices();
return _voiceProcessor.CurrentDeviceIndex >= 0;
VoiceProcessor.Instance.UpdateDevices();
return VoiceProcessor.Instance.CurrentDeviceIndex >= 0;
}

/// <summary>
/// Starts audio capture and intent inference
/// </summary>
public void Process()
{
if (_rhino == null || _voiceProcessor == null)
if (_rhino == null)
{
throw new RhinoInvalidStateException("Cannot start RhinoManager - resources have already been released");
}
_voiceProcessor.StartRecording(_rhino.SampleRate, _rhino.FrameLength);
VoiceProcessor.Instance.StartRecording(_rhino.FrameLength, _rhino.SampleRate);
}

/// <summary>
/// Free resources that were allocated to Rhino and the voice processor
/// </summary>
public void Delete()
{
if (_voiceProcessor != null)
if (_rhino != null)
{
if (_voiceProcessor.IsRecording)
VoiceProcessor.Instance.RemoveFrameListener(OnFrameCaptured);
if (VoiceProcessor.Instance.NumFrameListeners == 0)
{
_voiceProcessor.StopRecording();
VoiceProcessor.Instance.StopRecording();
}

_voiceProcessor.OnFrameCaptured -= OnFrameCaptured;
_voiceProcessor = null;
}

if (_rhino != null)
{
_rhino.Dispose();
_rhino = null;
}
Expand Down
1 change: 0 additions & 1 deletion binding/unity/Assets/Rhino/VoiceProcessor
Submodule VoiceProcessor deleted from c7ece4
2 changes: 1 addition & 1 deletion binding/unity/Assets/Rhino/VoiceProcessor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions binding/unity/Assets/StreamingAssets/test.meta

This file was deleted.

6 changes: 3 additions & 3 deletions binding/unity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ Rhino is:

## Compatibility

[Rhino unity package](./rhino-2.2.1.unitypackage) is for running Rhino on **Unity 2017.4+** on the following platforms:
[Rhino unity package](./rhino-2.2.2.unitypackage) is for running Rhino on **Unity 2017.4+** on the following platforms:

- Android 4.4+ (API 19+) (ARM only)
- iOS 9.0+
- Windows (x86_64)
- macOS (x86_64)
- Linux (x86_64)

For running Rhino on **macOS m1 (arm64)**, use the [Apple silicon](./rhino-2.2.1-Apple-silicon.unitypackage) version on **Unity 2021.2+**.
For running Rhino on **macOS m1 (arm64)**, use the [Apple silicon](./rhino-2.2.2-Apple-silicon.unitypackage) version on **Unity 2021.2+**.

## Installation

The easiest way to install the Rhino Unity SDK is to import the [Rhino Unity Package](./rhino-2.2.1.unitypackage) into your Unity project by either dropping it into the Unity editor or going to _Assets>Import Package>Custom Package..._
The easiest way to install the Rhino Unity SDK is to import the [Rhino Unity Package](./rhino-2.2.2.unitypackage) into your Unity project by either dropping it into the Unity editor or going to _Assets>Import Package>Custom Package..._

**NOTE:** On macOS, the Rhino 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_rhino.dylib to run.

Expand Down
1 change: 1 addition & 0 deletions binding/unity/VoiceProcessor
Submodule VoiceProcessor added at c7e647
7 changes: 7 additions & 0 deletions binding/unity/copy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ cp ../../lib/windows/amd64/libpv_rhino.dll ./Assets/Rhino/Plugins/windows/amd64/
echo "Copying Rhino common lib..."
cp ../../lib/common/rhino_params.pv ./Assets/StreamingAssets/rhino_params.pv

echo "Copying Voice Processor files..."
if [ ! -d "./Assets/Rhino/VoiceProcessor" ]
then
mkdir -p ./Assets/Rhino/VoiceProcessor
fi
cp -rp VoiceProcessor/Assets/UnityVoiceProcessor/*.cs ./Assets/Rhino/VoiceProcessor

echo "Copying demo files..."
if [ ! -d "./Assets/Rhino/Demo" ]
then
Expand Down
Binary file removed binding/unity/rhino-2.2.1-Apple-silicon.unitypackage
Binary file not shown.
Binary file removed binding/unity/rhino-2.2.1.unitypackage
Binary file not shown.
Binary file not shown.
Binary file added binding/unity/rhino-2.2.2.unitypackage
Binary file not shown.

0 comments on commit fcc3091

Please sign in to comment.