This repository has been archived on 2025-08-26. You can view files and clone it, but cannot push or open issues or pull requests.
Files
enginex-mr_series-sherpa-onnx/scripts/dotnet/SpeechSegment.cs

44 lines
1.0 KiB
C#
Raw Normal View History

/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang)
2024-05-30 18:29:38 +08:00
using System;
using System.Runtime.InteropServices;
2024-05-30 18:29:38 +08:00
namespace SherpaOnnx
{
public class SpeechSegment
{
public SpeechSegment(IntPtr handle)
{
2024-05-30 18:29:38 +08:00
Impl impl = (Impl)Marshal.PtrToStructure(handle, typeof(Impl));
_start = impl.Start;
unsafe
{
float* t = (float*)impl.Samples;
_samples = new float[impl.Count];
fixed (float* pTarget = _samples)
{
for (int i = 0; i < impl.Count; i++)
{
pTarget[i] = t[i];
}
}
}
}
2024-05-30 18:29:38 +08:00
public int _start;
public int Start => _start;
2024-05-30 18:29:38 +08:00
private float[] _samples;
public float[] Samples => _samples;
2024-05-30 18:29:38 +08:00
[StructLayout(LayoutKind.Sequential)]
struct Impl
{
public int Start;
public IntPtr Samples;
public int Count;
}
2024-05-30 18:29:38 +08:00
}
}