Split online.cs and offline.csFile (#941)
Co-authored-by: 东风破 <birdfishs@163.com>
This commit is contained in:
65
scripts/dotnet/OnlineStream.cs
Normal file
65
scripts/dotnet/OnlineStream.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
/// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang)
|
||||
/// Copyright (c) 2023 by manyeyes
|
||||
/// Copyright (c) 2024.5 by 东风破
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System;
|
||||
|
||||
namespace SherpaOnnx
|
||||
{
|
||||
|
||||
public class OnlineStream : IDisposable
|
||||
{
|
||||
public OnlineStream(IntPtr p)
|
||||
{
|
||||
_handle = new HandleRef(this, p);
|
||||
}
|
||||
|
||||
public void AcceptWaveform(int sampleRate, float[] samples)
|
||||
{
|
||||
AcceptWaveform(Handle, sampleRate, samples, samples.Length);
|
||||
}
|
||||
|
||||
public void InputFinished()
|
||||
{
|
||||
InputFinished(Handle);
|
||||
}
|
||||
|
||||
~OnlineStream()
|
||||
{
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Cleanup();
|
||||
// Prevent the object from being placed on the
|
||||
// finalization queue
|
||||
System.GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void Cleanup()
|
||||
{
|
||||
DestroyOnlineStream(Handle);
|
||||
|
||||
// Don't permit the handle to be used again.
|
||||
_handle = new HandleRef(this, IntPtr.Zero);
|
||||
}
|
||||
|
||||
private HandleRef _handle;
|
||||
public IntPtr Handle => _handle.Handle;
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern void DestroyOnlineStream(IntPtr handle);
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern void AcceptWaveform(IntPtr handle, int sampleRate, float[] samples, int n);
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern void InputFinished(IntPtr handle);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user