Move structs to IntPtr
This commit is contained in:
parent
9ac8cebb3b
commit
acabb26378
|
@ -1,10 +1,8 @@
|
|||
using DeepSpeechClient.Interfaces;
|
||||
using DeepSpeechClient.Structs;
|
||||
using DeepSpeechClient.Extensions;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using DeepSpeechClient.Enums;
|
||||
|
||||
namespace DeepSpeechClient
|
||||
|
@ -14,9 +12,8 @@ namespace DeepSpeechClient
|
|||
/// </summary>
|
||||
public class DeepSpeech : IDeepSpeech
|
||||
{
|
||||
private unsafe ModelState** _modelStatePP;
|
||||
private unsafe ModelState* _modelStateP;
|
||||
private unsafe StreamingState** _streamingStatePP;
|
||||
private unsafe IntPtr** _modelStatePP;
|
||||
private unsafe IntPtr** _streamingStatePP;
|
||||
|
||||
|
||||
|
||||
|
@ -65,7 +62,6 @@ namespace DeepSpeechClient
|
|||
aBeamWidth,
|
||||
ref _modelStatePP);
|
||||
EvaluateResultCode(resultCode);
|
||||
_modelStateP = *_modelStatePP;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -52,8 +52,6 @@
|
|||
<Compile Include="Models\MetadataItem.cs" />
|
||||
<Compile Include="NativeImp.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Structs\ModelState.cs" />
|
||||
<Compile Include="Structs\StreamingState.cs" />
|
||||
<Compile Include="Structs\Metadata.cs" />
|
||||
<Compile Include="Structs\MetadataItem.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using DeepSpeechClient.Enums;
|
||||
using DeepSpeechClient.Structs;
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
@ -19,10 +18,10 @@ namespace DeepSpeechClient
|
|||
internal unsafe static extern ErrorCodes DS_CreateModel(string aModelPath,
|
||||
string aAlphabetConfigPath,
|
||||
uint aBeamWidth,
|
||||
ref ModelState** pint);
|
||||
ref IntPtr** pint);
|
||||
|
||||
[DllImport("libdeepspeech.so", CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static unsafe extern ErrorCodes DS_EnableDecoderWithLM(ModelState** aCtx,
|
||||
internal static unsafe extern ErrorCodes DS_EnableDecoderWithLM(IntPtr** aCtx,
|
||||
string aLMPath,
|
||||
string aTriePath,
|
||||
float aLMAlpha,
|
||||
|
@ -30,26 +29,26 @@ namespace DeepSpeechClient
|
|||
|
||||
[DllImport("libdeepspeech.so", CallingConvention = CallingConvention.Cdecl,
|
||||
CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
internal static unsafe extern IntPtr DS_SpeechToText(ModelState** aCtx,
|
||||
internal static unsafe extern IntPtr DS_SpeechToText(IntPtr** aCtx,
|
||||
short[] aBuffer,
|
||||
uint aBufferSize,
|
||||
uint aSampleRate);
|
||||
|
||||
[DllImport("libdeepspeech.so", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
|
||||
internal static unsafe extern IntPtr DS_SpeechToTextWithMetadata(ModelState** aCtx,
|
||||
internal static unsafe extern IntPtr DS_SpeechToTextWithMetadata(IntPtr** aCtx,
|
||||
short[] aBuffer,
|
||||
uint aBufferSize,
|
||||
uint aSampleRate);
|
||||
|
||||
[DllImport("libdeepspeech.so", CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static unsafe extern void DS_FreeModel(ModelState** aCtx);
|
||||
internal static unsafe extern void DS_FreeModel(IntPtr** aCtx);
|
||||
|
||||
[DllImport("libdeepspeech.so", CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static unsafe extern ErrorCodes DS_CreateStream(ModelState** aCtx,
|
||||
uint aSampleRate, ref StreamingState** retval);
|
||||
internal static unsafe extern ErrorCodes DS_CreateStream(IntPtr** aCtx,
|
||||
uint aSampleRate, ref IntPtr** retval);
|
||||
|
||||
[DllImport("libdeepspeech.so", CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static unsafe extern void DS_FreeStream(ref StreamingState** aSctx);
|
||||
internal static unsafe extern void DS_FreeStream(ref IntPtr** aSctx);
|
||||
|
||||
[DllImport("libdeepspeech.so", CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static unsafe extern void DS_FreeMetadata(IntPtr metadata);
|
||||
|
@ -59,19 +58,19 @@ namespace DeepSpeechClient
|
|||
|
||||
[DllImport("libdeepspeech.so", CallingConvention = CallingConvention.Cdecl,
|
||||
CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
internal static unsafe extern void DS_FeedAudioContent(StreamingState** aSctx,
|
||||
internal static unsafe extern void DS_FeedAudioContent(IntPtr** aSctx,
|
||||
short[] aBuffer,
|
||||
uint aBufferSize);
|
||||
|
||||
[DllImport("libdeepspeech.so", CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static unsafe extern string DS_IntermediateDecode(StreamingState** aSctx);
|
||||
internal static unsafe extern string DS_IntermediateDecode(IntPtr** aSctx);
|
||||
|
||||
[DllImport("libdeepspeech.so", CallingConvention = CallingConvention.Cdecl,
|
||||
CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
internal static unsafe extern IntPtr DS_FinishStream( StreamingState** aSctx);
|
||||
internal static unsafe extern IntPtr DS_FinishStream(IntPtr** aSctx);
|
||||
|
||||
[DllImport("libdeepspeech.so", CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static unsafe extern IntPtr DS_FinishStreamWithMetadata(StreamingState** aSctx);
|
||||
internal static unsafe extern IntPtr DS_FinishStreamWithMetadata(IntPtr** aSctx);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using Alphabet = System.IntPtr;
|
||||
using Scorer = System.IntPtr;
|
||||
using Session = System.IntPtr;
|
||||
using MemmappedEnv = System.IntPtr;
|
||||
using GraphDef = System.IntPtr;
|
||||
|
||||
namespace DeepSpeechClient.Structs
|
||||
{
|
||||
//FIXME: ModelState is an opaque pointer to the API, why is this code reverse
|
||||
// engineering its contents?
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public unsafe struct ModelState
|
||||
{
|
||||
public MemmappedEnv mmap_env;
|
||||
public Session session;
|
||||
public GraphDef graph_def;
|
||||
public uint ncep;
|
||||
public uint ncontext;
|
||||
public Alphabet alphabet;
|
||||
public Scorer scorer;
|
||||
public uint beam_width;
|
||||
public uint n_steps;
|
||||
public uint mfcc_feats_per_timestep;
|
||||
public uint n_context;
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DeepSpeechClient.Structs
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
internal unsafe struct StreamingState
|
||||
{
|
||||
public float last_sample; // used for preemphasis
|
||||
public bool skip_next_mfcc;
|
||||
public ModelState* model;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue