Split online.cs and offline.csFile (#941)

Co-authored-by: 东风破 <birdfishs@163.com>
This commit is contained in:
东风破
2024-05-30 11:00:24 +08:00
committed by GitHub
parent e21caab759
commit 909148fe42
37 changed files with 1813 additions and 1440 deletions

View File

@@ -0,0 +1,46 @@
/// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx
{
public class SpokenLanguageIdentificationResult
{
public SpokenLanguageIdentificationResult(IntPtr handle)
{
Impl impl = (Impl)Marshal.PtrToStructure(handle, typeof(Impl));
// PtrToStringUTF8() requires .net standard 2.1
// _text = Marshal.PtrToStringUTF8(impl.Text);
int length = 0;
unsafe
{
byte* buffer = (byte*)impl.Lang;
while (*buffer != 0)
{
++buffer;
length += 1;
}
}
byte[] stringBuffer = new byte[length];
Marshal.Copy(impl.Lang, stringBuffer, 0, length);
_lang = Encoding.UTF8.GetString(stringBuffer);
}
[StructLayout(LayoutKind.Sequential)]
struct Impl
{
public IntPtr Lang;
}
private String _lang;
public String Lang => _lang;
}
}