Add API to get version information (#2309)
This commit is contained in:
120
scripts/dotnet/VersionInfo.cs
Normal file
120
scripts/dotnet/VersionInfo.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
/// Copyright (c) 2025 Xiaomi Corporation (authors: Fangjun Kuang)
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace SherpaOnnx
|
||||
{
|
||||
public class VersionInfo
|
||||
{
|
||||
public static String Version
|
||||
{
|
||||
get
|
||||
{
|
||||
IntPtr p = SherpaOnnxGetVersionStr();
|
||||
|
||||
string s = "";
|
||||
int length = 0;
|
||||
|
||||
unsafe
|
||||
{
|
||||
byte* b = (byte*)p;
|
||||
if (b != null)
|
||||
{
|
||||
while (*b != 0)
|
||||
{
|
||||
++b;
|
||||
length += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
byte[] stringBuffer = new byte[length];
|
||||
Marshal.Copy(p, stringBuffer, 0, length);
|
||||
s = Encoding.UTF8.GetString(stringBuffer);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
public static String GitSha1
|
||||
{
|
||||
get
|
||||
{
|
||||
IntPtr p = SherpaOnnxGetGitSha1();
|
||||
|
||||
string s = "";
|
||||
int length = 0;
|
||||
|
||||
unsafe
|
||||
{
|
||||
byte* b = (byte*)p;
|
||||
if (b != null)
|
||||
{
|
||||
while (*b != 0)
|
||||
{
|
||||
++b;
|
||||
length += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
byte[] stringBuffer = new byte[length];
|
||||
Marshal.Copy(p, stringBuffer, 0, length);
|
||||
s = Encoding.UTF8.GetString(stringBuffer);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
public static String GitDate
|
||||
{
|
||||
get
|
||||
{
|
||||
IntPtr p = SherpaOnnxGetGitDate();
|
||||
|
||||
string s = "";
|
||||
int length = 0;
|
||||
|
||||
unsafe
|
||||
{
|
||||
byte* b = (byte*)p;
|
||||
if (b != null)
|
||||
{
|
||||
while (*b != 0)
|
||||
{
|
||||
++b;
|
||||
length += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
byte[] stringBuffer = new byte[length];
|
||||
Marshal.Copy(p, stringBuffer, 0, length);
|
||||
s = Encoding.UTF8.GetString(stringBuffer);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern IntPtr SherpaOnnxGetVersionStr();
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern IntPtr SherpaOnnxGetGitSha1();
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern IntPtr SherpaOnnxGetGitDate();
|
||||
}
|
||||
}
|
||||
@@ -2027,3 +2027,15 @@ func (audio *DenoisedAudio) Save(filename string) bool {
|
||||
func (sd *OfflineSpeechDenoiser) SampleRate() int {
|
||||
return int(C.SherpaOnnxOfflineSpeechDenoiserGetSampleRate(sd.impl))
|
||||
}
|
||||
|
||||
func GetVersion() string {
|
||||
return C.GoString(C.SherpaOnnxGetVersionStr())
|
||||
}
|
||||
|
||||
func GetGitSha1() string {
|
||||
return C.GoString(C.SherpaOnnxGetGitSha1())
|
||||
}
|
||||
|
||||
func GetGitDate() string {
|
||||
return C.GoString(C.SherpaOnnxGetGitDate())
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ set(srcs
|
||||
src/spoken-language-identification.cc
|
||||
src/streaming-asr.cc
|
||||
src/vad.cc
|
||||
src/version.cc
|
||||
src/wave-reader.cc
|
||||
src/wave-writer.cc
|
||||
)
|
||||
|
||||
@@ -26,12 +26,14 @@ for (const p of possible_paths) {
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
let addon_path = `${process.env.PWD}/node_modules/sherpa-onnx-${platform_arch}`;
|
||||
let addon_path =
|
||||
`${process.env.PWD}/node_modules/sherpa-onnx-${platform_arch}`;
|
||||
const pnpmIndex = __dirname.indexOf(`node_modules${path.sep}.pnpm`);
|
||||
if (pnpmIndex !== -1) {
|
||||
const parts = __dirname.slice(pnpmIndex).split(path.sep);
|
||||
parts.pop();
|
||||
addon_path = `${process.env.PWD}/${parts.join('/')}/sherpa-onnx-${platform_arch}`;
|
||||
addon_path =
|
||||
`${process.env.PWD}/${parts.join('/')}/sherpa-onnx-${platform_arch}`;
|
||||
}
|
||||
|
||||
let msg = `Could not find sherpa-onnx-node. Tried\n\n ${
|
||||
|
||||
@@ -28,4 +28,7 @@ module.exports = {
|
||||
KeywordSpotter: kws.KeywordSpotter,
|
||||
OfflineSpeakerDiarization: sd.OfflineSpeakerDiarization,
|
||||
OfflineSpeechDenoiser: speech_denoiser.OfflineSpeechDenoiser,
|
||||
version: addon.version,
|
||||
gitSha1: addon.gitSha1,
|
||||
gitDate: addon.gitDate,
|
||||
}
|
||||
|
||||
1
scripts/node-addon-api/src/version.cc
Symbolic link
1
scripts/node-addon-api/src/version.cc
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/version.cc
|
||||
@@ -60,6 +60,21 @@ function createOfflineSpeechDenoiser(config) {
|
||||
wasmModule, config);
|
||||
}
|
||||
|
||||
function getVersion() {
|
||||
const v = wasmModule._SherpaOnnxGetVersionStr();
|
||||
return wasmModule.UTF8ToString(v);
|
||||
}
|
||||
|
||||
function getGitSha1() {
|
||||
const v = wasmModule._SherpaOnnxGetGitSha1();
|
||||
return wasmModule.UTF8ToString(v);
|
||||
}
|
||||
|
||||
function getGitDate() {
|
||||
const v = wasmModule._SherpaOnnxGetGitDate();
|
||||
return wasmModule.UTF8ToString(v);
|
||||
}
|
||||
|
||||
// Note: online means streaming and offline means non-streaming here.
|
||||
// Both of them don't require internet connection.
|
||||
module.exports = {
|
||||
@@ -74,4 +89,7 @@ module.exports = {
|
||||
createVad,
|
||||
createOfflineSpeakerDiarization,
|
||||
createOfflineSpeechDenoiser,
|
||||
version: getVersion(),
|
||||
gitSha1: getGitSha1(),
|
||||
gitDate: getGitDate(),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user