From 4dc18dd8ee943438b649861bb483ebcf140815ca Mon Sep 17 00:00:00 2001
From: Reuben Morais <reuben.morais@gmail.com>
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);
         }
 
+        /// <summary>
+        /// Return the sample rate expected by the model.
+        /// </summary>
+        /// <returns>Sample rate.</returns>
+        public unsafe int GetModelSampleRate()
+        {
+            return NativeImp.DS_GetModelSampleRate(_modelStatePP);
+        }
+
         /// <summary>
         /// Evaluate the result code and will raise an exception if necessary.
         /// </summary>
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);
 
+        /// <summary>
+        /// Return the sample rate expected by the model.
+        /// </summary>
+        /// <returns>Sample rate.</returns>
+        unsafe int GetModelSampleRate();
+
         /// <summary>
         /// Enable decoding using beam scoring with a KenLM language model.
         /// </summary>
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,