Add API to get version information (#2309)
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#include "sherpa-onnx/csrc/speaker-embedding-manager.h"
|
||||
#include "sherpa-onnx/csrc/spoken-language-identification.h"
|
||||
#include "sherpa-onnx/csrc/text-utils.h"
|
||||
#include "sherpa-onnx/csrc/version.h"
|
||||
#include "sherpa-onnx/csrc/voice-activity-detector.h"
|
||||
#include "sherpa-onnx/csrc/wave-reader.h"
|
||||
#include "sherpa-onnx/csrc/wave-writer.h"
|
||||
@@ -44,6 +45,10 @@
|
||||
#include "sherpa-onnx/csrc/offline-speaker-diarization.h"
|
||||
#endif
|
||||
|
||||
const char *SherpaOnnxGetVersionStr() { return sherpa_onnx::GetVersionStr(); }
|
||||
const char *SherpaOnnxGetGitSha1() { return sherpa_onnx::GetGitSha1(); }
|
||||
const char *SherpaOnnxGetGitDate() { return sherpa_onnx::GetGitDate(); }
|
||||
|
||||
struct SherpaOnnxOnlineRecognizer {
|
||||
std::unique_ptr<sherpa_onnx::OnlineRecognizer> impl;
|
||||
};
|
||||
@@ -1369,9 +1374,8 @@ int64_t SherpaOnnxWaveFileSize(int32_t n_samples) {
|
||||
return sherpa_onnx::WaveFileSize(n_samples);
|
||||
}
|
||||
|
||||
SHERPA_ONNX_API void SherpaOnnxWriteWaveToBuffer(const float *samples,
|
||||
int32_t n, int32_t sample_rate,
|
||||
char *buffer) {
|
||||
void SherpaOnnxWriteWaveToBuffer(const float *samples, int32_t n,
|
||||
int32_t sample_rate, char *buffer) {
|
||||
sherpa_onnx::WriteWave(buffer, sample_rate, samples, n);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,30 @@ extern "C" {
|
||||
#define SHERPA_ONNX_API SHERPA_ONNX_IMPORT
|
||||
#endif
|
||||
|
||||
// Please don't free the returned pointer.
|
||||
// Please don't modify the memory pointed by the returned pointer.
|
||||
//
|
||||
// The memory pointed by the returned pointer is statically allocated.
|
||||
//
|
||||
// Example return value: "1.12.1"
|
||||
SHERPA_ONNX_API const char *SherpaOnnxGetVersionStr();
|
||||
|
||||
// Please don't free the returned pointer.
|
||||
// Please don't modify the memory pointed by the returned pointer.
|
||||
//
|
||||
// The memory pointed by the returned pointer is statically allocated.
|
||||
//
|
||||
// Example return value: "6982b86c"
|
||||
SHERPA_ONNX_API const char *SherpaOnnxGetGitSha1();
|
||||
|
||||
// Please don't free the returned pointer.
|
||||
// Please don't modify the memory pointed by the returned pointer.
|
||||
//
|
||||
// The memory pointed by the returned pointer is statically allocated.
|
||||
//
|
||||
// Example return value: "Fri Jun 20 11:22:52 2025"
|
||||
SHERPA_ONNX_API const char *SherpaOnnxGetGitDate();
|
||||
|
||||
/// Please refer to
|
||||
/// https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
|
||||
/// to download pre-trained models. That is, you can find encoder-xxx.onnx
|
||||
|
||||
@@ -717,4 +717,10 @@ int32_t LinearResampler::GetOutputSamplingRate() const {
|
||||
return SherpaOnnxLinearResamplerResampleGetOutputSampleRate(p_);
|
||||
}
|
||||
|
||||
std::string GetVersionStr() { return SherpaOnnxGetVersionStr(); }
|
||||
|
||||
std::string GetGitSha1() { return SherpaOnnxGetGitSha1(); }
|
||||
|
||||
std::string GetGitDate() { return SherpaOnnxGetGitDate(); }
|
||||
|
||||
} // namespace sherpa_onnx::cxx
|
||||
|
||||
@@ -615,6 +615,10 @@ class SHERPA_ONNX_API LinearResampler
|
||||
explicit LinearResampler(const SherpaOnnxLinearResampler *p);
|
||||
};
|
||||
|
||||
std::string GetVersionStr();
|
||||
std::string GetGitSha1();
|
||||
std::string GetGitDate();
|
||||
|
||||
} // namespace sherpa_onnx::cxx
|
||||
|
||||
#endif // SHERPA_ONNX_C_API_CXX_API_H_
|
||||
|
||||
@@ -129,6 +129,7 @@ set(sources
|
||||
utils.cc
|
||||
vad-model-config.cc
|
||||
vad-model.cc
|
||||
version.cc
|
||||
voice-activity-detector.cc
|
||||
wave-reader.cc
|
||||
wave-writer.cc
|
||||
@@ -337,6 +338,7 @@ if(SHERPA_ONNX_ENABLE_BINARY)
|
||||
add_executable(sherpa-onnx-offline-punctuation sherpa-onnx-offline-punctuation.cc)
|
||||
add_executable(sherpa-onnx-offline-source-separation sherpa-onnx-offline-source-separation.cc)
|
||||
add_executable(sherpa-onnx-online-punctuation sherpa-onnx-online-punctuation.cc)
|
||||
add_executable(sherpa-onnx-version sherpa-onnx-version.cc version.cc)
|
||||
add_executable(sherpa-onnx-vad sherpa-onnx-vad.cc)
|
||||
|
||||
if(SHERPA_ONNX_ENABLE_TTS)
|
||||
@@ -396,6 +398,7 @@ if(SHERPA_ONNX_ENABLE_BINARY)
|
||||
install(
|
||||
TARGETS
|
||||
${main_exes}
|
||||
sherpa-onnx-version
|
||||
DESTINATION
|
||||
bin
|
||||
)
|
||||
|
||||
17
sherpa-onnx/csrc/sherpa-onnx-version.cc
Normal file
17
sherpa-onnx/csrc/sherpa-onnx-version.cc
Normal file
@@ -0,0 +1,17 @@
|
||||
// sherpa-onnx/csrc/sherpa-onnx-version.cc
|
||||
//
|
||||
// Copyright (c) 2025 Xiaomi Corporation
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "sherpa-onnx/csrc/version.h"
|
||||
|
||||
int32_t main() {
|
||||
printf("sherpa-onnx version : %s\n", sherpa_onnx::GetVersionStr());
|
||||
printf("sherpa-onnx Git SHA1: %s\n", sherpa_onnx::GetGitSha1());
|
||||
printf("sherpa-onnx Git date: %s\n", sherpa_onnx::GetGitDate());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -312,7 +312,8 @@ static std::vector<std::string> MergeCharactersIntoWords(
|
||||
while (i < n) {
|
||||
const auto &w = words[i];
|
||||
if (w.size() >= 3 || (w.size() == 2 && !IsSpecial(w)) ||
|
||||
(w.size() == 1 && (IsPunct(w[0]) || std::isspace(static_cast<uint8_t>(w[0]))))) {
|
||||
(w.size() == 1 &&
|
||||
(IsPunct(w[0]) || std::isspace(static_cast<uint8_t>(w[0]))))) {
|
||||
if (prev != -1) {
|
||||
std::string t;
|
||||
for (; prev < i; ++prev) {
|
||||
|
||||
24
sherpa-onnx/csrc/version.cc
Normal file
24
sherpa-onnx/csrc/version.cc
Normal file
@@ -0,0 +1,24 @@
|
||||
// sherpa-onnx/csrc/version.h
|
||||
//
|
||||
// Copyright 2025 Xiaomi Corporation
|
||||
|
||||
#include "sherpa-onnx/csrc/version.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
const char *GetGitDate() {
|
||||
static const char *date = "Fri Jun 20 11:22:52 2025";
|
||||
return date;
|
||||
}
|
||||
|
||||
const char *GetGitSha1() {
|
||||
static const char *sha1 = "6982b86c";
|
||||
return sha1;
|
||||
}
|
||||
|
||||
const char *GetVersionStr() {
|
||||
static const char *version = "1.12.1";
|
||||
return version;
|
||||
}
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
29
sherpa-onnx/csrc/version.h
Normal file
29
sherpa-onnx/csrc/version.h
Normal file
@@ -0,0 +1,29 @@
|
||||
// sherpa-onnx/csrc/version.h
|
||||
//
|
||||
// Copyright 2025 Xiaomi Corporation
|
||||
#ifndef SHERPA_ONNX_CSRC_VERSION_H_
|
||||
#define SHERPA_ONNX_CSRC_VERSION_H_
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
// Please don't free the returned pointer.
|
||||
// Please don't modify the memory pointed by the returned pointer.
|
||||
//
|
||||
// The memory pointed by the returned pointer is statically allocated.
|
||||
const char *GetVersionStr();
|
||||
|
||||
// Please don't free the returned pointer.
|
||||
// Please don't modify the memory pointed by the returned pointer.
|
||||
//
|
||||
// The memory pointed by the returned pointer is statically allocated.
|
||||
const char *GetGitSha1();
|
||||
|
||||
// Please don't free the returned pointer.
|
||||
// Please don't modify the memory pointed by the returned pointer.
|
||||
//
|
||||
// The memory pointed by the returned pointer is statically allocated.
|
||||
const char *GetGitDate();
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
|
||||
#endif // SHERPA_ONNX_CSRC_VERSION_H_
|
||||
@@ -8,6 +8,7 @@ package_dir := com/k2fsa/sherpa/onnx
|
||||
|
||||
java_files := LibraryLoader.java
|
||||
|
||||
java_files += VersionInfo.java
|
||||
java_files += WaveReader.java
|
||||
java_files += WaveWriter.java
|
||||
java_files += EndpointRule.java
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.k2fsa.sherpa.onnx;
|
||||
|
||||
public class VersionInfo {
|
||||
|
||||
public static String getVersion() {
|
||||
LibraryLoader.maybeLoad();
|
||||
return getVersionStr2();
|
||||
}
|
||||
|
||||
public static String getGitSha1() {
|
||||
LibraryLoader.maybeLoad();
|
||||
return getGitSha12();
|
||||
}
|
||||
|
||||
public static String getGitDate() {
|
||||
LibraryLoader.maybeLoad();
|
||||
return getGitDate2();
|
||||
}
|
||||
|
||||
private static native String getVersionStr2();
|
||||
private static native String getGitSha12();
|
||||
private static native String getGitDate2();
|
||||
}
|
||||
@@ -24,6 +24,7 @@ set(sources
|
||||
speaker-embedding-extractor.cc
|
||||
speaker-embedding-manager.cc
|
||||
spoken-language-identification.cc
|
||||
version.cc
|
||||
voice-activity-detector.cc
|
||||
wave-reader.cc
|
||||
wave-writer.cc
|
||||
|
||||
49
sherpa-onnx/jni/version.cc
Normal file
49
sherpa-onnx/jni/version.cc
Normal file
@@ -0,0 +1,49 @@
|
||||
// sherpa-onnx/jni/version.cc
|
||||
//
|
||||
// Copyright (c) 2025 Xiaomi Corporation
|
||||
#include "sherpa-onnx/csrc/version.h"
|
||||
|
||||
#include "sherpa-onnx/jni/common.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
SHERPA_ONNX_EXTERN_C
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_k2fsa_sherpa_onnx_VersionInfo_00024Companion_getVersionStr2(
|
||||
JNIEnv *env, jclass /*cls*/) {
|
||||
return env->NewStringUTF(GetVersionStr());
|
||||
}
|
||||
|
||||
SHERPA_ONNX_EXTERN_C
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_k2fsa_sherpa_onnx_VersionInfo_00024Companion_getGitSha12(
|
||||
JNIEnv *env, jclass /*cls*/) {
|
||||
return env->NewStringUTF(GetGitSha1());
|
||||
}
|
||||
|
||||
SHERPA_ONNX_EXTERN_C
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_k2fsa_sherpa_onnx_VersionInfo_00024Companion_getGitDate2(
|
||||
JNIEnv *env, jclass /*cls*/) {
|
||||
return env->NewStringUTF(GetGitDate());
|
||||
}
|
||||
|
||||
SHERPA_ONNX_EXTERN_C
|
||||
JNIEXPORT jstring JNICALL Java_com_k2fsa_sherpa_onnx_VersionInfo_getVersionStr2(
|
||||
JNIEnv *env, jclass /*cls*/) {
|
||||
return env->NewStringUTF(GetVersionStr());
|
||||
}
|
||||
|
||||
SHERPA_ONNX_EXTERN_C
|
||||
JNIEXPORT jstring JNICALL Java_com_k2fsa_sherpa_onnx_VersionInfo_getGitSha12(
|
||||
JNIEnv *env, jclass /*cls*/) {
|
||||
return env->NewStringUTF(GetGitSha1());
|
||||
}
|
||||
|
||||
SHERPA_ONNX_EXTERN_C
|
||||
JNIEXPORT jstring JNICALL Java_com_k2fsa_sherpa_onnx_VersionInfo_getGitDate2(
|
||||
JNIEnv *env, jclass /*cls*/) {
|
||||
return env->NewStringUTF(GetGitDate());
|
||||
}
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
22
sherpa-onnx/kotlin-api/VersionInfo.kt
Normal file
22
sherpa-onnx/kotlin-api/VersionInfo.kt
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.k2fsa.sherpa.onnx
|
||||
|
||||
class VersionInfo {
|
||||
companion object {
|
||||
init {
|
||||
System.loadLibrary("sherpa-onnx-jni")
|
||||
}
|
||||
|
||||
val version: String
|
||||
get() = getVersionStr2()
|
||||
|
||||
val gitSha1: String
|
||||
get() = getGitSha12()
|
||||
|
||||
val gitDate: String
|
||||
get() = getGitDate2()
|
||||
|
||||
external fun getVersionStr2(): String
|
||||
external fun getGitSha12(): String
|
||||
external fun getGitDate2(): String
|
||||
}
|
||||
}
|
||||
@@ -578,6 +578,10 @@ type
|
||||
function SherpaOnnxWriteWave(Filename: AnsiString;
|
||||
Samples: array of Single; SampleRate: Integer): Boolean;
|
||||
|
||||
function SherpaOnnxGetVersionStr(): AnsiString;
|
||||
function SherpaOnnxGetGitSha1(): AnsiString;
|
||||
function SherpaOnnxGetGitDate(): AnsiString;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
@@ -951,6 +955,30 @@ function SherpaOnnxCreateLinearResampler(SampleRateInHz: cint32;
|
||||
NumZeros: cint32): Pointer; cdecl;
|
||||
external SherpaOnnxLibName;
|
||||
|
||||
function SherpaOnnxGetVersionStrWrapper(): PAnsiChar; cdecl;
|
||||
external SherpaOnnxLibName name 'SherpaOnnxGetVersionStr';
|
||||
|
||||
function SherpaOnnxGetGitSha1Wrapper(): PAnsiChar; cdecl;
|
||||
external SherpaOnnxLibName name 'SherpaOnnxGetGitSha1';
|
||||
|
||||
function SherpaOnnxGetGitDateWrapper(): PAnsiChar; cdecl;
|
||||
external SherpaOnnxLibName name 'SherpaOnnxGetGitDate';
|
||||
|
||||
function SherpaOnnxGetVersionStr(): AnsiString;
|
||||
begin
|
||||
Result := SherpaOnnxGetVersionStrWrapper();
|
||||
end;
|
||||
|
||||
function SherpaOnnxGetGitSha1(): AnsiString;
|
||||
begin
|
||||
Result := SherpaOnnxGetGitSha1Wrapper();
|
||||
end;
|
||||
|
||||
function SherpaOnnxGetGitDate(): AnsiString;
|
||||
begin
|
||||
Result := SherpaOnnxGetGitDateWrapper();
|
||||
end;
|
||||
|
||||
procedure SherpaOnnxDestroyLinearResampler(P: Pointer); cdecl;
|
||||
external SherpaOnnxLibName;
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ set(srcs
|
||||
tensorrt-config.cc
|
||||
vad-model-config.cc
|
||||
vad-model.cc
|
||||
version.cc
|
||||
voice-activity-detector.cc
|
||||
wave-writer.cc
|
||||
)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "sherpa-onnx/csrc/offline-source-separation.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include "sherpa-onnx/python/csrc/offline-source-separation-model-config.h"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// sherpa-onnx/python/csrc/offline-source-separation-config.h
|
||||
// sherpa-onnx/python/csrc/offline-source-separation.h
|
||||
//
|
||||
// Copyright (c) 2025 Xiaomi Corporation
|
||||
|
||||
#ifndef SHERPA_ONNX_PYTHON_CSRC_OFFLINE_SOURCE_SEPARATION_CONFIG_H_
|
||||
#define SHERPA_ONNX_PYTHON_CSRC_OFFLINE_SOURCE_SEPARATION_CONFIG_H_
|
||||
#ifndef SHERPA_ONNX_PYTHON_CSRC_OFFLINE_SOURCE_SEPARATION_H_
|
||||
#define SHERPA_ONNX_PYTHON_CSRC_OFFLINE_SOURCE_SEPARATION_H_
|
||||
|
||||
#include "sherpa-onnx/python/csrc/sherpa-onnx.h"
|
||||
|
||||
@@ -13,4 +13,4 @@ void PybindOfflineSourceSeparation(py::module *m);
|
||||
|
||||
}
|
||||
|
||||
#endif // SHERPA_ONNX_PYTHON_CSRC_OFFLINE_SOURCE_SEPARATION_CONFIG_H_
|
||||
#endif // SHERPA_ONNX_PYTHON_CSRC_OFFLINE_SOURCE_SEPARATION_H_
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "sherpa-onnx/python/csrc/spoken-language-identification.h"
|
||||
#include "sherpa-onnx/python/csrc/vad-model-config.h"
|
||||
#include "sherpa-onnx/python/csrc/vad-model.h"
|
||||
#include "sherpa-onnx/python/csrc/version.h"
|
||||
#include "sherpa-onnx/python/csrc/voice-activity-detector.h"
|
||||
#include "sherpa-onnx/python/csrc/wave-writer.h"
|
||||
|
||||
@@ -112,6 +113,7 @@ PYBIND11_MODULE(_sherpa_onnx, m) {
|
||||
PybindAlsa(&m);
|
||||
PybindOfflineSpeechDenoiser(&m);
|
||||
PybindOfflineSourceSeparation(&m);
|
||||
PybindVersion(&m);
|
||||
}
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
|
||||
21
sherpa-onnx/python/csrc/version.cc
Normal file
21
sherpa-onnx/python/csrc/version.cc
Normal file
@@ -0,0 +1,21 @@
|
||||
// sherpa-onnx/python/csrc/version.cc
|
||||
//
|
||||
// Copyright (c) 2025 Xiaomi Corporation
|
||||
|
||||
#include "sherpa-onnx/python/csrc/version.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "sherpa-onnx/csrc/version.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
void PybindVersion(py::module *m) {
|
||||
m->attr("version") = std::string(GetVersionStr());
|
||||
|
||||
m->attr("git_sha1") = std::string(GetGitSha1());
|
||||
|
||||
m->attr("git_date") = std::string(GetGitDate());
|
||||
}
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
16
sherpa-onnx/python/csrc/version.h
Normal file
16
sherpa-onnx/python/csrc/version.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// sherpa-onnx/python/csrc/version.h
|
||||
//
|
||||
// Copyright (c) 2025 Xiaomi Corporation
|
||||
|
||||
#ifndef SHERPA_ONNX_PYTHON_CSRC_VERSION_H_
|
||||
#define SHERPA_ONNX_PYTHON_CSRC_VERSION_H_
|
||||
|
||||
#include "sherpa-onnx/python/csrc/sherpa-onnx.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
void PybindVersion(py::module *m);
|
||||
|
||||
}
|
||||
|
||||
#endif // SHERPA_ONNX_PYTHON_CSRC_VERSION_H_
|
||||
@@ -49,6 +49,9 @@ from _sherpa_onnx import (
|
||||
VadModel,
|
||||
VadModelConfig,
|
||||
VoiceActivityDetector,
|
||||
git_date,
|
||||
git_sha1,
|
||||
version,
|
||||
write_wave,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user