From 4dc18dd8ee943438b649861bb483ebcf140815ca Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Thu, 10 Oct 2019 22:04:44 +0200 Subject: [PATCH] Expose and use model sample rate in .NET --- native_client/dotnet/DeepSpeechClient/DeepSpeech.cs | 9 +++++++++ .../dotnet/DeepSpeechClient/Interfaces/IDeepSpeech.cs | 6 ++++++ native_client/dotnet/DeepSpeechClient/NativeImp.cs | 3 +++ 3 files changed, 18 insertions(+) diff --git a/native_client/dotnet/DeepSpeechClient/DeepSpeech.cs b/native_client/dotnet/DeepSpeechClient/DeepSpeech.cs index 25fcc109..9bbf5e3c 100644 --- a/native_client/dotnet/DeepSpeechClient/DeepSpeech.cs +++ b/native_client/dotnet/DeepSpeechClient/DeepSpeech.cs @@ -64,6 +64,15 @@ namespace DeepSpeechClient EvaluateResultCode(resultCode); } + /// + /// Return the sample rate expected by the model. + /// + /// Sample rate. + public unsafe int GetModelSampleRate() + { + return NativeImp.DS_GetModelSampleRate(_modelStatePP); + } + /// /// Evaluate the result code and will raise an exception if necessary. /// diff --git a/native_client/dotnet/DeepSpeechClient/Interfaces/IDeepSpeech.cs b/native_client/dotnet/DeepSpeechClient/Interfaces/IDeepSpeech.cs index 79af2964..f7bbee98 100644 --- a/native_client/dotnet/DeepSpeechClient/Interfaces/IDeepSpeech.cs +++ b/native_client/dotnet/DeepSpeechClient/Interfaces/IDeepSpeech.cs @@ -24,6 +24,12 @@ namespace DeepSpeechClient.Interfaces string aAlphabetConfigPath, uint aBeamWidth); + /// + /// Return the sample rate expected by the model. + /// + /// Sample rate. + unsafe int GetModelSampleRate(); + /// /// Enable decoding using beam scoring with a KenLM language model. /// diff --git a/native_client/dotnet/DeepSpeechClient/NativeImp.cs b/native_client/dotnet/DeepSpeechClient/NativeImp.cs index 74de9197..92cdb150 100644 --- a/native_client/dotnet/DeepSpeechClient/NativeImp.cs +++ b/native_client/dotnet/DeepSpeechClient/NativeImp.cs @@ -20,6 +20,9 @@ namespace DeepSpeechClient uint aBeamWidth, ref IntPtr** pint); + [DllImport("libdeepspeech.so", CallingConvention = CallingConvention.Cdecl)] + internal unsafe static extern int DS_GetModelSampleRate(IntPtr** aCtx); + [DllImport("libdeepspeech.so", CallingConvention = CallingConvention.Cdecl)] internal static unsafe extern ErrorCodes DS_EnableDecoderWithLM(IntPtr** aCtx, string aLMPath,