Skip to content

Commit

Permalink
v2.0 dotnet (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
laves authored Nov 22, 2023
1 parent 7017473 commit ccf6883
Show file tree
Hide file tree
Showing 8 changed files with 627 additions and 201 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/dotnet-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ jobs:
- name: Package restore
run: dotnet restore

# *********** REMOVE AFTER RELEASE **********************
- name: Pack binding for local ref
run: dotnet pack -c Release
working-directory: binding/dotnet

- name: Add binding to demo
run: dotnet add package -s ../../../binding/dotnet/Leopard/bin/Release Leopard
# ******************************************************

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

Expand All @@ -60,6 +69,15 @@ jobs:
- name: Package restore
run: dotnet restore

# *********** REMOVE AFTER RELEASE **********************
- name: Pack binding for local ref
run: dotnet pack -c Release
working-directory: binding/dotnet

- name: Add binding to demo
run: dotnet add package -s ../../../binding/dotnet/Leopard/bin/Release Leopard
# ******************************************************

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

Expand Down
181 changes: 132 additions & 49 deletions binding/dotnet/Leopard/Leopard.cs

Large diffs are not rendered by default.

47 changes: 31 additions & 16 deletions binding/dotnet/Leopard/Leopard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

<PropertyGroup>
<TargetFrameworks>net6.0;netcoreapp3.0;netstandard2.0</TargetFrameworks>
<Version>1.2.1</Version>
<Version>2.0.0</Version>
<Authors>Picovoice</Authors>
<Company />
<Company/>
<Product>Leopard Speech-to-Text Engine</Product>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/Picovoice/leopard</PackageProjectUrl>
<RepositoryUrl>https://github.com/Picovoice/leopard.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>Speech-to-Text, Speech Recognition, Voice Recognition, ASR</PackageTags>
<PackageReleaseNotes>See https://github.com/Picovoice/leopard/ </PackageReleaseNotes>
<PackageReleaseNotes>See https://github.com/Picovoice/leopard/</PackageReleaseNotes>
<Copyright>Picovoice 2022-2023</Copyright>
<Description>
Leopard is an on-device speech-to-text engine. Leopard is:
Expand All @@ -24,6 +24,8 @@
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageIcon>pv_circle_512.png</PackageIcon>
</PropertyGroup>

<!--Target files-->
<ItemGroup>
<Content Include="Leopard.netstandard2.0.targets">
<PackagePath>
Expand All @@ -33,20 +35,15 @@
</Content>
<Content Include="Leopard.targets">
<PackagePath>
build/netcoreapp3.0;
build/net6.0;
</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\..\lib\common\leopard_params.pv">
<PackagePath>
build/netstandard2.0/lib/common/leopard_params.pv;
build/netcoreapp3.0/lib/common/leopard_params.pv;
build/net6.0/lib/common/leopard_params.pv;
build/netcoreapp3.0/Leopard.targets;
build/net6.0/Leopard.targets;
</PackagePath>
<Link>lib\common\leopard_params.pv</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<!--.NET Standard 2.0+ libs-->
<ItemGroup>
<Content Include="..\..\..\lib\windows\amd64\libpv_leopard.dll">
<PackagePath>
build/netstandard2.0/libpv_leopard.dll;
Expand Down Expand Up @@ -78,8 +75,10 @@
<Visible>false</Visible>
</Content>
</ItemGroup>

<!--.NET Core 3.0+ libs-->
<ItemGroup>
<Content Include="..\..\..\lib\raspberry-pi\**\*" Exclude="..\..\..\lib\raspberry-pi\arm11\*">
<Content Include="..\..\..\lib\raspberry-pi\**\*">
<PackagePath>
build/netcoreapp3.0/lib/raspberry-pi;
build/net6.0/lib/raspberry-pi;
Expand All @@ -98,6 +97,8 @@
<Visible>false</Visible>
</Content>
</ItemGroup>

<!--.NET Core 6.0+ libs-->
<ItemGroup>
<Content Include="..\..\..\lib\mac\arm64\libpv_leopard.dylib">
<PackagePath>
Expand All @@ -108,8 +109,22 @@
<Visible>false</Visible>
</Content>
</ItemGroup>

<!--Resources-->
<ItemGroup>
<Content Include="..\..\..\lib\common\leopard_params.pv">
<PackagePath>
build/netstandard2.0/lib/common/leopard_params.pv;
build/netcoreapp3.0/lib/common/leopard_params.pv;
build/net6.0/lib/common/leopard_params.pv;
</PackagePath>
<Link>lib\common\leopard_params.pv</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<Folder Include="Content\" />
<Folder Include="Content\"/>
</ItemGroup>
<ItemGroup>
<None Include="Content\pv_circle_512.png">
Expand Down
49 changes: 48 additions & 1 deletion binding/dotnet/Leopard/LeopardException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-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 All @@ -15,87 +15,134 @@ namespace Pv
{
public class LeopardException : Exception
{
private readonly string[] _messageStack;

public LeopardException() { }

public LeopardException(string message) : base(message) { }

public LeopardException(string message, string[] messageStack) : base(ModifyMessages(message, messageStack))
{
this._messageStack = messageStack;
}

public string[] MessageStack
{
get => _messageStack;
}

private static string ModifyMessages(string message, string[] messageStack)
{
string messageString = message;
if (messageStack.Length > 0)
{
messageString += ":";
for (int i = 0; i < messageStack.Length; i++)
{
messageString += $"\n [{i}] {messageStack[i]}";
}
}
return messageString;
}
}

public class LeopardMemoryException : LeopardException
{
public LeopardMemoryException() { }

public LeopardMemoryException(string message) : base(message) { }

public LeopardMemoryException(string message, string[] messageStack) : base(message, messageStack) { }
}

public class LeopardIOException : LeopardException
{
public LeopardIOException() { }

public LeopardIOException(string message) : base(message) { }

public LeopardIOException(string message, string[] messageStack) : base(message, messageStack) { }
}

public class LeopardInvalidArgumentException : LeopardException
{
public LeopardInvalidArgumentException() { }

public LeopardInvalidArgumentException(string message) : base(message) { }

public LeopardInvalidArgumentException(string message, string[] messageStack) : base(message, messageStack) { }
}

public class LeopardStopIterationException : LeopardException
{
public LeopardStopIterationException() { }

public LeopardStopIterationException(string message) : base(message) { }

public LeopardStopIterationException(string message, string[] messageStack) : base(message, messageStack) { }
}

public class LeopardKeyException : LeopardException
{
public LeopardKeyException() { }

public LeopardKeyException(string message) : base(message) { }

public LeopardKeyException(string message, string[] messageStack) : base(message, messageStack) { }
}

public class LeopardInvalidStateException : LeopardException
{
public LeopardInvalidStateException() { }

public LeopardInvalidStateException(string message) : base(message) { }

public LeopardInvalidStateException(string message, string[] messageStack) : base(message, messageStack) { }
}

public class LeopardRuntimeException : LeopardException
{
public LeopardRuntimeException() { }

public LeopardRuntimeException(string message) : base(message) { }

public LeopardRuntimeException(string message, string[] messageStack) : base(message, messageStack) { }
}

public class LeopardActivationException : LeopardException
{
public LeopardActivationException() { }

public LeopardActivationException(string message) : base(message) { }

public LeopardActivationException(string message, string[] messageStack) : base(message, messageStack) { }
}

public class LeopardActivationLimitException : LeopardException
{
public LeopardActivationLimitException() { }

public LeopardActivationLimitException(string message) : base(message) { }

public LeopardActivationLimitException(string message, string[] messageStack) : base(message, messageStack) { }
}

public class LeopardActivationThrottledException : LeopardException
{
public LeopardActivationThrottledException() { }

public LeopardActivationThrottledException(string message) : base(message) { }

public LeopardActivationThrottledException(string message, string[] messageStack) : base(message, messageStack) { }
}

public class LeopardActivationRefusedException : LeopardException
{
public LeopardActivationRefusedException() { }

public LeopardActivationRefusedException(string message) : base(message) { }

public LeopardActivationRefusedException(string message, string[] messageStack) : base(message, messageStack) { }
}

}
33 changes: 24 additions & 9 deletions binding/dotnet/Leopard/LeopardTranscript.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-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 All @@ -9,6 +9,8 @@ file accompanying this source.
specific language governing permissions and limitations under the License.
*/

using System;

namespace Pv
{
/// <summary>
Expand All @@ -19,18 +21,26 @@ public class LeopardWord
/// <summary>
/// Constructor.
/// </summary>
/// <param name="word"> Transcribed word. </param>
/// <param name="confidence"> Transcription confidence. It is a number within [0, 1].</param>
/// <param name="startSec"> Start of word in seconds. </param>
/// <param name="endSec"> End of word in seconds. </param>
///
public LeopardWord(string word, float confidence, float startSec, float endSec)
/// <param name="word">Transcribed word.</param>
/// <param name="confidence">Transcription confidence. It is a number within [0, 1].</param>
/// <param name="startSec">Start of word in seconds.</param>
/// <param name="endSec">End of word in seconds.</param>
/// <param name="speakerTag">
/// The speaker tag is `-1` if diarization is not enabled during initialization; otherwise,
/// it's a non-negative integer identifying unique speakers, with `0` reserved for unknown speakers.
/// </param>
public LeopardWord(
string word,
float confidence,
float startSec,
float endSec,
Int32 speakerTag)
{
Word = word;
Confidence = confidence;

StartSec = startSec;
EndSec = endSec;
SpeakerTag = speakerTag;
}

/// <summary>
Expand All @@ -52,6 +62,11 @@ public LeopardWord(string word, float confidence, float startSec, float endSec)
/// Getter for endSec.
/// </summary>
public float EndSec { get; }

/// <summary>
/// Getter for speakerTag.
/// </summary>
public Int32 SpeakerTag { get; }
}

/// <summary>
Expand All @@ -63,7 +78,7 @@ public class LeopardTranscript
/// Constructor.
/// </summary>
/// <param name="transcriptString">
/// transcript String transcript returned from Leopard.
/// Transcript returned from Leopard.
/// </param>
/// <param name="wordArray">
/// Transcribed words and their associated metadata.
Expand Down
Loading

0 comments on commit ccf6883

Please sign in to comment.