Skip to content

Commit

Permalink
v3.0 dotnet (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
laves authored Oct 20, 2023
1 parent a5b425a commit c682055
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 18 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/dotnet-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ jobs:
include:
- os: ubuntu-latest
platform: linux
nuget-path: ~/.nuget/NuGet/local-nuget
- os: windows-latest
platform: windows
nuget-path: ~/AppData/Roaming/NuGet/local-nuget
- os: macos-latest
platform: mac
nuget-path: ~/.nuget/NuGet/local-nuget

steps:
- uses: actions/checkout@v3
Expand All @@ -44,6 +47,34 @@ jobs:
with:
dotnet-version: 6.0.x

# *********** REMOVE AFTER RELEASE **********************
- name: mkdir NuGet directory
run: mkdir -p ${{ matrix.nuget-path }}

- name: Add local NuGet source
run: dotnet nuget add source local-nuget

- name: Pack Porcupine for local ref
run: dotnet pack -c Release
working-directory: resources/porcupine/binding/dotnet

- name: Copy Porcupine Nuget
run: cp ../../../resources/porcupine/binding/dotnet/Porcupine/bin/Release/*.nupkg ${{ matrix.nuget-path }}

- name: Pack Rhino for local ref
run: dotnet pack -c Release
working-directory: resources/rhino/binding/dotnet

- name: Copy Rhino Nuget
run: cp ../../../resources/rhino/binding/dotnet/Rhino/bin/Release/*.nupkg ${{ matrix.nuget-path }}

- name: Pack Picovoice for local ref
run: dotnet pack ../../../sdk/dotnet/Picovoice/Picovoice.csproj -c Release

- name: Copy Picovoice Nuget
run: cp ../../../sdk/dotnet/Picovoice/bin/Release/*.nupkg ${{ matrix.nuget-path }}
# ******************************************************

- name: Dotnet build micdemo
run: dotnet build -c MicDemo.Release -v n

Expand Down Expand Up @@ -84,6 +115,36 @@ jobs:
with:
submodules: recursive

# *********** REMOVE AFTER RELEASE **********************
- name: mkdir NuGet directory
run: rm -rf ~/.nuget/NuGet/local-nuget && mkdir -p ~/.nuget/NuGet/local-nuget
continue-on-error: true

- name: Add local NuGet source
run: dotnet nuget add source local-nuget
continue-on-error: true

- name: Pack Porcupine for local ref
run: dotnet pack -c Release
working-directory: resources/porcupine/binding/dotnet

- name: Copy Porcupine Nuget
run: cp ../../../resources/porcupine/binding/dotnet/Porcupine/bin/Release/*.nupkg ~/.nuget/NuGet/local-nuget

- name: Pack Rhino for local ref
run: dotnet pack -c Release
working-directory: resources/rhino/binding/dotnet

- name: Copy Rhino Nuget
run: cp ../../../resources/rhino/binding/dotnet/Rhino/bin/Release/*.nupkg ~/.nuget/NuGet/local-nuget

- name: Pack Picovoice for local ref
run: dotnet pack ../../../sdk/dotnet/Picovoice/Picovoice.csproj -c Release

- name: Copy Picovoice Nuget
run: cp ../../../sdk/dotnet/Picovoice/bin/Release/*.nupkg ~/.nuget/NuGet/local-nuget
# ******************************************************

- name: Dotnet build micdemo
run: dotnet build -c MicDemo.Release -v n

Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ jobs:
- dotnet-version: 6.0.x
binding-framework: net6.0
test-framework: net6.0
- os: ubuntu-latest
nuget-path: ~/.nuget/NuGet/local-nuget
- os: macos-latest
nuget-path: ~/.nuget/NuGet/local-nuget
- os: windows-latest
nuget-path: ~/AppData/Roaming/NuGet/local-nuget

steps:
- name: Checkout repository and submodules
Expand All @@ -65,6 +71,28 @@ jobs:
with:
dotnet-version: ${{ matrix.dotnet-version }}

# *********** REMOVE AFTER RELEASE **********************
- name: mkdir NuGet directory
run: mkdir -p ${{ matrix.nuget-path }}

- name: Add local NuGet source
run: dotnet nuget add source local-nuget

- name: Pack Porcupine for local ref
run: dotnet pack -c Release
working-directory: resources/porcupine/binding/dotnet

- name: Copy Porcupine Nuget
run: cp ../../resources/porcupine/binding/dotnet/Porcupine/bin/Release/*.nupkg ${{ matrix.nuget-path }}

- name: Pack Rhino for local ref
run: dotnet pack -c Release
working-directory: resources/rhino/binding/dotnet

- name: Copy Rhino Nuget
run: cp ../../resources/rhino/binding/dotnet/Rhino/bin/Release/*.nupkg ${{ matrix.nuget-path }}
# ******************************************************

- name: Build binding
run: dotnet build Picovoice/Picovoice.csproj --framework ${{ matrix.binding-framework }} -v n

Expand All @@ -86,6 +114,30 @@ jobs:
with:
submodules: recursive

# *********** REMOVE AFTER RELEASE **********************
- name: mkdir NuGet directory
run: rm -rf ~/.nuget/NuGet/local-nuget && mkdir -p ~/.nuget/NuGet/local-nuget
continue-on-error: true

- name: Add local NuGet source
run: dotnet nuget add source local-nuget
continue-on-error: true

- name: Pack Porcupine for local ref
run: dotnet pack -c Release
working-directory: resources/porcupine/binding/dotnet

- name: Copy Porcupine Nuget
run: cp ../../resources/porcupine/binding/dotnet/Porcupine/bin/Release/*.nupkg ~/.nuget/NuGet/local-nuget

- name: Pack Rhino for local ref
run: dotnet pack -c Release
working-directory: resources/rhino/binding/dotnet

- name: Copy Rhino Nuget
run: cp ../../resources/rhino/binding/dotnet/Rhino/bin/Release/*.nupkg ~/.nuget/NuGet/local-nuget
# ******************************************************

- name: Build binding
run: dotnet build Picovoice/Picovoice.csproj --framework net6.0 -v n

Expand Down
2 changes: 1 addition & 1 deletion demo/dotnet/PicovoiceDemo/PicovoiceDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@

<ItemGroup>
<PackageReference Include="PvRecorder" Version="1.2.4" />
<PackageReference Include="Picovoice" Version="2.2.2" />
<PackageReference Include="Picovoice" Version="3.0.0" />
</ItemGroup>
</Project>
55 changes: 42 additions & 13 deletions sdk/dotnet/Picovoice/Picovoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,21 +203,50 @@ public void Process(short[] pcm)
throw new PicovoiceInvalidStateException("Cannot process frame - resources have been released.");
}

if (!_isWakeWordDetected)
{
_isWakeWordDetected = _porcupine.Process(pcm) == 0;
if (_isWakeWordDetected)
_wakeWordCallback.Invoke();
}
else
try
{
bool isFinalized = _rhino.Process(pcm);
if (isFinalized)
if (!_isWakeWordDetected)
{
_isWakeWordDetected = false;
Inference inference = _rhino.GetInference();
_inferenceCallback.Invoke(inference);
_isWakeWordDetected = _porcupine.Process(pcm) == 0;
if (_isWakeWordDetected)
_wakeWordCallback.Invoke();
}
else
{
bool isFinalized = _rhino.Process(pcm);
if (isFinalized)
{
_isWakeWordDetected = false;
Inference inference = _rhino.GetInference();
_inferenceCallback.Invoke(inference);
}
}
}
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 Picovoice was stopped while processing a stream of audio.
/// </summary>
public void Reset()
{
if (_porcupine == null || _rhino == null)
{
throw new PicovoiceInvalidStateException("Cannot process frame - resources have been released.");
}

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

Expand All @@ -237,7 +266,7 @@ public void Process(short[] pcm)
/// Gets the version number of the Picovoice platform
/// </summary>
/// <returns>Version of Picovoice</returns>
public string Version => "2.1.0";
public string Version => "3.0.0";

/// <summary>
/// Get the version of the Porcupine library
Expand Down
6 changes: 3 additions & 3 deletions sdk/dotnet/Picovoice/Picovoice.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;netcoreapp3.0;netstandard2.0</TargetFrameworks>
<Version>2.2.2</Version>
<Version>3.0.0</Version>
<Authors>Picovoice</Authors>
<Company />
<Product>Picovoice End-to-End Platform</Product>
Expand Down Expand Up @@ -35,10 +35,10 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Porcupine" Version="2.2.3">
<PackageReference Include="Porcupine" Version="3.0.0">
<PrivateAssets>analyzers</PrivateAssets>
</PackageReference>
<PackageReference Include="Rhino" Version="2.2.3">
<PackageReference Include="Rhino" Version="3.0.0">
<PrivateAssets>analyzers</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
23 changes: 22 additions & 1 deletion sdk/dotnet/PicovoiceTest/MainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void TestClean()
_picovoice?.Dispose();
}

public void RunTestCase(string audioFileName, string expectedIntent, Dictionary<string, string> expectedSlots)
public void ProcessFileHelper(string audioFileName)
{
string testAudioPath = Path.Combine(ROOT_DIR, "resources/audio_samples/", audioFileName);

Expand All @@ -166,6 +166,11 @@ public void RunTestCase(string audioFileName, string expectedIntent, Dictionary<

_picovoice.Process(frame.ToArray());
}
}

public void RunTestCase(string audioFileName, string expectedIntent, Dictionary<string, string> expectedSlots)
{
ProcessFileHelper(audioFileName);

Assert.IsTrue(_isWakeWordDetected);
Assert.AreEqual(_inference.Intent, expectedIntent);
Expand All @@ -175,6 +180,22 @@ public void RunTestCase(string audioFileName, string expectedIntent, Dictionary<
expectedSlots[keyValuePair.Key] == keyValuePair.Value));
}

[TestMethod]
public void TestReset()
{
_picovoice = Picovoice.Create(
_accessKey,
GetKeywordPath("en", "picovoice"),
() => _picovoice.Reset(),
GetContextPath("en", "coffee_maker"),
_inferenceCallback);

_inference = null;
ProcessFileHelper("picovoice-coffee.wav");

Assert.IsNull(_inference);
}

[TestMethod]
[DynamicData(nameof(ParametersTestData))]
public void TestTwice(
Expand Down

0 comments on commit c682055

Please sign in to comment.