react-native-sherpa-onnx 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +232 -236
- package/SherpaOnnx.podspec +68 -64
- package/android/build.gradle +182 -192
- package/android/codegen.gradle +57 -0
- package/android/prebuilt-download.gradle +428 -0
- package/android/prebuilt-versions.gradle +43 -0
- package/android/proguard-rules.pro +10 -0
- package/android/src/main/assets/testModels/add_mul_add.onnx +28 -0
- package/android/src/main/assets/testModels/nnapi_internal_uint8_support.onnx +0 -0
- package/android/src/main/assets/testModels/qnn_multi_ctx_embed.onnx +0 -0
- package/android/src/main/cpp/CMakeLists.txt +166 -129
- package/android/src/main/cpp/CMakePresets.json +54 -0
- package/android/src/main/cpp/crypto/sha256.cpp +174 -0
- package/android/src/main/cpp/crypto/sha256.h +16 -0
- package/android/src/main/cpp/jni/archive/sherpa-onnx-archive-helper.cpp +404 -0
- package/android/src/main/cpp/jni/archive/sherpa-onnx-archive-helper.h +56 -0
- package/android/src/main/cpp/jni/archive/sherpa-onnx-archive-jni.cpp +181 -0
- package/android/src/main/cpp/jni/audio/sherpa-onnx-audio-convert-jni.cpp +888 -0
- package/{ios → android/src/main/cpp/jni/model_detect}/sherpa-onnx-common.h +18 -18
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-detect-jni-common.cpp +86 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-detect-jni-common.h +20 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-helper.cpp +423 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-helper.h +55 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-stt.cpp +399 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-tts.cpp +238 -0
- package/{ios → android/src/main/cpp/jni/model_detect}/sherpa-onnx-model-detect.h +122 -89
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-stt-wrapper.cpp +99 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-stt-wrapper.h +16 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-tts-wrapper.cpp +78 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-tts-wrapper.h +16 -0
- package/android/src/main/cpp/jni/module/sherpa-onnx-module-jni.cpp +190 -0
- package/android/src/main/cpp/jni/tts/sherpa-onnx-tts-zipvoice-jni.cpp +301 -0
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxArchiveHelper.kt +94 -0
- package/android/src/main/java/com/sherpaonnx/{SherpaOnnxCoreHelper.kt → SherpaOnnxAssetHelper.kt} +350 -236
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxModule.kt +791 -483
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxSttHelper.kt +699 -109
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxTtsHelper.kt +1123 -668
- package/android/src/main/java/com/sherpaonnx/ZipvoiceTtsWrapper.kt +187 -0
- package/ios/SherpaOnnx+Assets.h +11 -0
- package/ios/SherpaOnnx+Assets.mm +325 -0
- package/ios/SherpaOnnx+STT.mm +455 -118
- package/ios/SherpaOnnx+TTS.mm +1101 -712
- package/ios/SherpaOnnx.h +17 -6
- package/ios/SherpaOnnx.mm +206 -311
- package/ios/SherpaOnnx.xcconfig +19 -19
- package/ios/SherpaOnnxCoreMLHelper.swift +24 -0
- package/ios/archive/sherpa-onnx-archive-helper.h +21 -0
- package/ios/archive/sherpa-onnx-archive-helper.mm +296 -0
- package/ios/libarchive_darwin_config.h +153 -0
- package/{android/src/main/cpp/jni → ios/model_detect}/sherpa-onnx-common.h +18 -18
- package/ios/model_detect/sherpa-onnx-model-detect-helper.h +49 -0
- package/ios/model_detect/sherpa-onnx-model-detect-helper.mm +210 -0
- package/ios/model_detect/sherpa-onnx-model-detect-stt.mm +344 -0
- package/ios/model_detect/sherpa-onnx-model-detect-tts.mm +201 -0
- package/{android/src/main/cpp/jni → ios/model_detect}/sherpa-onnx-model-detect.h +117 -89
- package/ios/scripts/patch-libarchive-includes.sh +61 -0
- package/ios/scripts/setup-ios-libarchive.sh +98 -0
- package/ios/stt/sherpa-onnx-stt-wrapper.h +129 -0
- package/ios/stt/sherpa-onnx-stt-wrapper.mm +523 -0
- package/ios/{sherpa-onnx-tts-wrapper.h → tts/sherpa-onnx-tts-wrapper.h} +90 -85
- package/ios/{sherpa-onnx-tts-wrapper.mm → tts/sherpa-onnx-tts-wrapper.mm} +376 -345
- package/lib/module/NativeSherpaOnnx.js +3 -0
- package/lib/module/NativeSherpaOnnx.js.map +1 -1
- package/lib/module/audio/index.js +22 -0
- package/lib/module/audio/index.js.map +1 -0
- package/lib/module/diarization/index.js +1 -1
- package/lib/module/diarization/index.js.map +1 -1
- package/lib/module/download/ModelDownloadManager.js +918 -0
- package/lib/module/download/ModelDownloadManager.js.map +1 -0
- package/lib/module/download/extractTarBz2.js +53 -0
- package/lib/module/download/extractTarBz2.js.map +1 -0
- package/lib/module/download/index.js +6 -0
- package/lib/module/download/index.js.map +1 -0
- package/lib/module/download/validation.js +178 -0
- package/lib/module/download/validation.js.map +1 -0
- package/lib/module/enhancement/index.js +1 -1
- package/lib/module/enhancement/index.js.map +1 -1
- package/lib/module/index.js +41 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/separation/index.js +1 -1
- package/lib/module/separation/index.js.map +1 -1
- package/lib/module/stt/index.js +127 -60
- package/lib/module/stt/index.js.map +1 -1
- package/lib/module/stt/sttModelLanguages.js +512 -0
- package/lib/module/stt/sttModelLanguages.js.map +1 -0
- package/lib/module/stt/types.js +53 -1
- package/lib/module/stt/types.js.map +1 -1
- package/lib/module/tts/index.js +216 -289
- package/lib/module/tts/index.js.map +1 -1
- package/lib/module/tts/types.js +86 -1
- package/lib/module/tts/types.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils.js +86 -73
- package/lib/module/utils.js.map +1 -1
- package/lib/module/vad/index.js +1 -1
- package/lib/module/vad/index.js.map +1 -1
- package/lib/typescript/src/NativeSherpaOnnx.d.ts +192 -38
- package/lib/typescript/src/NativeSherpaOnnx.d.ts.map +1 -1
- package/lib/typescript/src/audio/index.d.ts +13 -0
- package/lib/typescript/src/audio/index.d.ts.map +1 -0
- package/lib/typescript/src/diarization/index.d.ts +3 -2
- package/lib/typescript/src/diarization/index.d.ts.map +1 -1
- package/lib/typescript/src/download/ModelDownloadManager.d.ts +108 -0
- package/lib/typescript/src/download/ModelDownloadManager.d.ts.map +1 -0
- package/lib/typescript/src/download/extractTarBz2.d.ts +14 -0
- package/lib/typescript/src/download/extractTarBz2.d.ts.map +1 -0
- package/lib/typescript/src/download/index.d.ts +7 -0
- package/lib/typescript/src/download/index.d.ts.map +1 -0
- package/lib/typescript/src/download/validation.d.ts +57 -0
- package/lib/typescript/src/download/validation.d.ts.map +1 -0
- package/lib/typescript/src/enhancement/index.d.ts +3 -2
- package/lib/typescript/src/enhancement/index.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +26 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/separation/index.d.ts +3 -2
- package/lib/typescript/src/separation/index.d.ts.map +1 -1
- package/lib/typescript/src/stt/index.d.ts +31 -43
- package/lib/typescript/src/stt/index.d.ts.map +1 -1
- package/lib/typescript/src/stt/sttModelLanguages.d.ts +52 -0
- package/lib/typescript/src/stt/sttModelLanguages.d.ts.map +1 -0
- package/lib/typescript/src/stt/types.d.ts +196 -9
- package/lib/typescript/src/stt/types.d.ts.map +1 -1
- package/lib/typescript/src/tts/index.d.ts +25 -211
- package/lib/typescript/src/tts/index.d.ts.map +1 -1
- package/lib/typescript/src/tts/types.d.ts +148 -25
- package/lib/typescript/src/tts/types.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +0 -32
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +28 -13
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/lib/typescript/src/vad/index.d.ts +3 -2
- package/lib/typescript/src/vad/index.d.ts.map +1 -1
- package/package.json +250 -222
- package/scripts/check-qnn-support.sh +78 -0
- package/scripts/setup-ios-framework.sh +379 -282
- package/src/NativeSherpaOnnx.ts +474 -251
- package/src/audio/index.ts +32 -0
- package/src/diarization/index.ts +4 -2
- package/src/download/ModelDownloadManager.ts +1325 -0
- package/src/download/extractTarBz2.ts +78 -0
- package/src/download/index.ts +43 -0
- package/src/download/validation.ts +279 -0
- package/src/enhancement/index.ts +4 -2
- package/src/index.tsx +78 -27
- package/src/separation/index.ts +4 -2
- package/src/stt/index.ts +249 -89
- package/src/stt/sttModelLanguages.ts +237 -0
- package/src/stt/types.ts +263 -9
- package/src/tts/index.ts +470 -458
- package/src/tts/types.ts +373 -218
- package/src/types.ts +0 -44
- package/src/utils.ts +145 -131
- package/src/vad/index.ts +4 -2
- package/third_party/ffmpeg_prebuilt/ANDROID_RELEASE_TAG +1 -0
- package/third_party/libarchive_prebuilt/ANDROID_RELEASE_TAG +1 -0
- package/third_party/libarchive_prebuilt/IOS_RELEASE_TAG +1 -0
- package/third_party/sherpa-onnx-prebuilt/ANDROID_RELEASE_TAG +1 -0
- package/third_party/sherpa-onnx-prebuilt/IOS_RELEASE_TAG +1 -0
- package/android/src/main/cpp/include/sherpa-onnx/c-api/c-api.h +0 -1918
- package/android/src/main/cpp/include/sherpa-onnx/c-api/cxx-api.h +0 -841
- package/android/src/main/cpp/jni/sherpa-onnx-model-detect.cpp +0 -541
- package/android/src/main/cpp/jni/sherpa-onnx-stt-jni.cpp +0 -336
- package/android/src/main/cpp/jni/sherpa-onnx-stt-wrapper.cpp +0 -222
- package/android/src/main/cpp/jni/sherpa-onnx-stt-wrapper.h +0 -68
- package/android/src/main/cpp/jni/sherpa-onnx-tts-jni.cpp +0 -823
- package/android/src/main/cpp/jni/sherpa-onnx-tts-wrapper.cpp +0 -387
- package/android/src/main/cpp/jni/sherpa-onnx-tts-wrapper.h +0 -147
- package/ios/Frameworks/sherpa_onnx.xcframework.zip +0 -0
- package/ios/include/sherpa-onnx/c-api/c-api.h +0 -1918
- package/ios/include/sherpa-onnx/c-api/cxx-api.h +0 -841
- package/ios/sherpa-onnx-model-detect.mm +0 -441
- package/ios/sherpa-onnx-stt-wrapper.h +0 -48
- package/ios/sherpa-onnx-stt-wrapper.mm +0 -201
- package/scripts/copy-headers.js +0 -184
- package/scripts/setup-assets.js +0 -323
|
@@ -1,1918 +0,0 @@
|
|
|
1
|
-
// sherpa-onnx/c-api/c-api.h
|
|
2
|
-
//
|
|
3
|
-
// Copyright (c) 2023 Xiaomi Corporation
|
|
4
|
-
|
|
5
|
-
// C API for sherpa-onnx
|
|
6
|
-
//
|
|
7
|
-
// Please refer to
|
|
8
|
-
// https://github.com/k2-fsa/sherpa-onnx/blob/master/c-api-examples/decode-file-c-api.c
|
|
9
|
-
// for usages.
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
#ifndef SHERPA_ONNX_C_API_C_API_H_
|
|
13
|
-
#define SHERPA_ONNX_C_API_C_API_H_
|
|
14
|
-
|
|
15
|
-
#include <stdint.h>
|
|
16
|
-
|
|
17
|
-
#ifdef __cplusplus
|
|
18
|
-
extern "C" {
|
|
19
|
-
#endif
|
|
20
|
-
|
|
21
|
-
// See https://github.com/pytorch/pytorch/blob/main/c10/macros/Export.h
|
|
22
|
-
// We will set SHERPA_ONNX_BUILD_SHARED_LIBS and SHERPA_ONNX_BUILD_MAIN_LIB in
|
|
23
|
-
// CMakeLists.txt
|
|
24
|
-
|
|
25
|
-
#if defined(__GNUC__)
|
|
26
|
-
#pragma GCC diagnostic push
|
|
27
|
-
#pragma GCC diagnostic ignored "-Wattributes"
|
|
28
|
-
#endif
|
|
29
|
-
|
|
30
|
-
#if defined(_WIN32)
|
|
31
|
-
#if defined(SHERPA_ONNX_BUILD_SHARED_LIBS)
|
|
32
|
-
#define SHERPA_ONNX_EXPORT __declspec(dllexport)
|
|
33
|
-
#define SHERPA_ONNX_IMPORT __declspec(dllimport)
|
|
34
|
-
#else
|
|
35
|
-
#define SHERPA_ONNX_EXPORT
|
|
36
|
-
#define SHERPA_ONNX_IMPORT
|
|
37
|
-
#endif
|
|
38
|
-
#else // WIN32
|
|
39
|
-
#define SHERPA_ONNX_EXPORT __attribute__((visibility("default")))
|
|
40
|
-
|
|
41
|
-
#define SHERPA_ONNX_IMPORT SHERPA_ONNX_EXPORT
|
|
42
|
-
#endif // WIN32
|
|
43
|
-
|
|
44
|
-
#if defined(SHERPA_ONNX_BUILD_MAIN_LIB)
|
|
45
|
-
#define SHERPA_ONNX_API SHERPA_ONNX_EXPORT
|
|
46
|
-
#else
|
|
47
|
-
#define SHERPA_ONNX_API SHERPA_ONNX_IMPORT
|
|
48
|
-
#endif
|
|
49
|
-
|
|
50
|
-
// Please don't free the returned pointer.
|
|
51
|
-
// Please don't modify the memory pointed by the returned pointer.
|
|
52
|
-
//
|
|
53
|
-
// The memory pointed by the returned pointer is statically allocated.
|
|
54
|
-
//
|
|
55
|
-
// Example return value: "1.12.1"
|
|
56
|
-
SHERPA_ONNX_API const char *SherpaOnnxGetVersionStr();
|
|
57
|
-
|
|
58
|
-
// Please don't free the returned pointer.
|
|
59
|
-
// Please don't modify the memory pointed by the returned pointer.
|
|
60
|
-
//
|
|
61
|
-
// The memory pointed by the returned pointer is statically allocated.
|
|
62
|
-
//
|
|
63
|
-
// Example return value: "6982b86c"
|
|
64
|
-
SHERPA_ONNX_API const char *SherpaOnnxGetGitSha1();
|
|
65
|
-
|
|
66
|
-
// Please don't free the returned pointer.
|
|
67
|
-
// Please don't modify the memory pointed by the returned pointer.
|
|
68
|
-
//
|
|
69
|
-
// The memory pointed by the returned pointer is statically allocated.
|
|
70
|
-
//
|
|
71
|
-
// Example return value: "Fri Jun 20 11:22:52 2025"
|
|
72
|
-
SHERPA_ONNX_API const char *SherpaOnnxGetGitDate();
|
|
73
|
-
|
|
74
|
-
// return 1 if the given file exists; return 0 otherwise
|
|
75
|
-
SHERPA_ONNX_API int32_t SherpaOnnxFileExists(const char *filename);
|
|
76
|
-
|
|
77
|
-
/// Please refer to
|
|
78
|
-
/// https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
|
|
79
|
-
/// to download pre-trained models. That is, you can find encoder-xxx.onnx
|
|
80
|
-
/// decoder-xxx.onnx, joiner-xxx.onnx, and tokens.txt for this struct
|
|
81
|
-
/// from there.
|
|
82
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOnlineTransducerModelConfig {
|
|
83
|
-
const char *encoder;
|
|
84
|
-
const char *decoder;
|
|
85
|
-
const char *joiner;
|
|
86
|
-
} SherpaOnnxOnlineTransducerModelConfig;
|
|
87
|
-
|
|
88
|
-
// please visit
|
|
89
|
-
// https://k2-fsa.github.io/sherpa/onnx/pretrained_models/online-paraformer/index.html
|
|
90
|
-
// to download pre-trained streaming paraformer models
|
|
91
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOnlineParaformerModelConfig {
|
|
92
|
-
const char *encoder;
|
|
93
|
-
const char *decoder;
|
|
94
|
-
} SherpaOnnxOnlineParaformerModelConfig;
|
|
95
|
-
|
|
96
|
-
// Please visit
|
|
97
|
-
// https://k2-fsa.github.io/sherpa/onnx/pretrained_models/online-ctc/zipformer-ctc-models.html#
|
|
98
|
-
// to download pre-trained streaming zipformer2 ctc models
|
|
99
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOnlineZipformer2CtcModelConfig {
|
|
100
|
-
const char *model;
|
|
101
|
-
} SherpaOnnxOnlineZipformer2CtcModelConfig;
|
|
102
|
-
|
|
103
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOnlineNemoCtcModelConfig {
|
|
104
|
-
const char *model;
|
|
105
|
-
} SherpaOnnxOnlineNemoCtcModelConfig;
|
|
106
|
-
|
|
107
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOnlineToneCtcModelConfig {
|
|
108
|
-
const char *model;
|
|
109
|
-
} SherpaOnnxOnlineToneCtcModelConfig;
|
|
110
|
-
|
|
111
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOnlineModelConfig {
|
|
112
|
-
SherpaOnnxOnlineTransducerModelConfig transducer;
|
|
113
|
-
SherpaOnnxOnlineParaformerModelConfig paraformer;
|
|
114
|
-
SherpaOnnxOnlineZipformer2CtcModelConfig zipformer2_ctc;
|
|
115
|
-
const char *tokens;
|
|
116
|
-
int32_t num_threads;
|
|
117
|
-
const char *provider;
|
|
118
|
-
int32_t debug; // true to print debug information of the model
|
|
119
|
-
const char *model_type;
|
|
120
|
-
// Valid values:
|
|
121
|
-
// - cjkchar
|
|
122
|
-
// - bpe
|
|
123
|
-
// - cjkchar+bpe
|
|
124
|
-
const char *modeling_unit;
|
|
125
|
-
const char *bpe_vocab;
|
|
126
|
-
/// if non-null, loading the tokens from the buffer instead of from the
|
|
127
|
-
/// "tokens" file
|
|
128
|
-
const char *tokens_buf;
|
|
129
|
-
/// byte size excluding the trailing '\0'
|
|
130
|
-
int32_t tokens_buf_size;
|
|
131
|
-
SherpaOnnxOnlineNemoCtcModelConfig nemo_ctc;
|
|
132
|
-
SherpaOnnxOnlineToneCtcModelConfig t_one_ctc;
|
|
133
|
-
} SherpaOnnxOnlineModelConfig;
|
|
134
|
-
|
|
135
|
-
/// It expects 16 kHz 16-bit single channel wave format.
|
|
136
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxFeatureConfig {
|
|
137
|
-
/// Sample rate of the input data. MUST match the one expected
|
|
138
|
-
/// by the model. For instance, it should be 16000 for models provided
|
|
139
|
-
/// by us.
|
|
140
|
-
int32_t sample_rate;
|
|
141
|
-
|
|
142
|
-
/// Feature dimension of the model.
|
|
143
|
-
/// For instance, it should be 80 for models provided by us.
|
|
144
|
-
int32_t feature_dim;
|
|
145
|
-
} SherpaOnnxFeatureConfig;
|
|
146
|
-
|
|
147
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOnlineCtcFstDecoderConfig {
|
|
148
|
-
const char *graph;
|
|
149
|
-
int32_t max_active;
|
|
150
|
-
} SherpaOnnxOnlineCtcFstDecoderConfig;
|
|
151
|
-
|
|
152
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxHomophoneReplacerConfig {
|
|
153
|
-
const char *dict_dir; // unused
|
|
154
|
-
const char *lexicon;
|
|
155
|
-
const char *rule_fsts;
|
|
156
|
-
} SherpaOnnxHomophoneReplacerConfig;
|
|
157
|
-
|
|
158
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOnlineRecognizerConfig {
|
|
159
|
-
SherpaOnnxFeatureConfig feat_config;
|
|
160
|
-
SherpaOnnxOnlineModelConfig model_config;
|
|
161
|
-
|
|
162
|
-
/// Possible values are: greedy_search, modified_beam_search
|
|
163
|
-
const char *decoding_method;
|
|
164
|
-
|
|
165
|
-
/// Used only when decoding_method is modified_beam_search
|
|
166
|
-
/// Example value: 4
|
|
167
|
-
int32_t max_active_paths;
|
|
168
|
-
|
|
169
|
-
/// 0 to disable endpoint detection.
|
|
170
|
-
/// A non-zero value to enable endpoint detection.
|
|
171
|
-
int32_t enable_endpoint;
|
|
172
|
-
|
|
173
|
-
/// An endpoint is detected if trailing silence in seconds is larger than
|
|
174
|
-
/// this value even if nothing has been decoded.
|
|
175
|
-
/// Used only when enable_endpoint is not 0.
|
|
176
|
-
float rule1_min_trailing_silence;
|
|
177
|
-
|
|
178
|
-
/// An endpoint is detected if trailing silence in seconds is larger than
|
|
179
|
-
/// this value after something that is not blank has been decoded.
|
|
180
|
-
/// Used only when enable_endpoint is not 0.
|
|
181
|
-
float rule2_min_trailing_silence;
|
|
182
|
-
|
|
183
|
-
/// An endpoint is detected if the utterance in seconds is larger than
|
|
184
|
-
/// this value.
|
|
185
|
-
/// Used only when enable_endpoint is not 0.
|
|
186
|
-
float rule3_min_utterance_length;
|
|
187
|
-
|
|
188
|
-
/// Path to the hotwords.
|
|
189
|
-
const char *hotwords_file;
|
|
190
|
-
|
|
191
|
-
/// Bonus score for each token in hotwords.
|
|
192
|
-
float hotwords_score;
|
|
193
|
-
|
|
194
|
-
SherpaOnnxOnlineCtcFstDecoderConfig ctc_fst_decoder_config;
|
|
195
|
-
const char *rule_fsts;
|
|
196
|
-
const char *rule_fars;
|
|
197
|
-
float blank_penalty;
|
|
198
|
-
|
|
199
|
-
/// if non-nullptr, loading the hotwords from the buffered string directly in
|
|
200
|
-
const char *hotwords_buf;
|
|
201
|
-
/// byte size excluding the tailing '\0'
|
|
202
|
-
int32_t hotwords_buf_size;
|
|
203
|
-
SherpaOnnxHomophoneReplacerConfig hr;
|
|
204
|
-
} SherpaOnnxOnlineRecognizerConfig;
|
|
205
|
-
|
|
206
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOnlineRecognizerResult {
|
|
207
|
-
// Recognized text
|
|
208
|
-
const char *text;
|
|
209
|
-
|
|
210
|
-
// Pointer to continuous memory which holds string based tokens
|
|
211
|
-
// which are separated by \0
|
|
212
|
-
const char *tokens;
|
|
213
|
-
|
|
214
|
-
// a pointer array containing the address of the first item in tokens
|
|
215
|
-
const char *const *tokens_arr;
|
|
216
|
-
|
|
217
|
-
// Pointer to continuous memory which holds timestamps
|
|
218
|
-
//
|
|
219
|
-
// Caution: If timestamp information is not available, this pointer is NULL.
|
|
220
|
-
// Please check whether it is NULL before you access it; otherwise, you would
|
|
221
|
-
// get segmentation fault.
|
|
222
|
-
float *timestamps;
|
|
223
|
-
|
|
224
|
-
// The number of tokens/timestamps in above pointer
|
|
225
|
-
int32_t count;
|
|
226
|
-
|
|
227
|
-
/** Return a json string.
|
|
228
|
-
*
|
|
229
|
-
* The returned string contains:
|
|
230
|
-
* {
|
|
231
|
-
* "text": "The recognition result",
|
|
232
|
-
* "tokens": [x, x, x],
|
|
233
|
-
* "timestamps": [x, x, x],
|
|
234
|
-
* "segment": x,
|
|
235
|
-
* "start_time": x,
|
|
236
|
-
* "is_final": true|false
|
|
237
|
-
* }
|
|
238
|
-
*/
|
|
239
|
-
const char *json;
|
|
240
|
-
} SherpaOnnxOnlineRecognizerResult;
|
|
241
|
-
|
|
242
|
-
/// Note: OnlineRecognizer here means StreamingRecognizer.
|
|
243
|
-
/// It does not need to access the Internet during recognition.
|
|
244
|
-
/// Everything is run locally.
|
|
245
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOnlineRecognizer
|
|
246
|
-
SherpaOnnxOnlineRecognizer;
|
|
247
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOnlineStream SherpaOnnxOnlineStream;
|
|
248
|
-
|
|
249
|
-
/// @param config Config for the recognizer.
|
|
250
|
-
/// @return Return a pointer to the recognizer. The user has to invoke
|
|
251
|
-
// SherpaOnnxDestroyOnlineRecognizer() to free it to avoid memory leak.
|
|
252
|
-
SHERPA_ONNX_API const SherpaOnnxOnlineRecognizer *
|
|
253
|
-
SherpaOnnxCreateOnlineRecognizer(
|
|
254
|
-
const SherpaOnnxOnlineRecognizerConfig *config);
|
|
255
|
-
|
|
256
|
-
/// Free a pointer returned by SherpaOnnxCreateOnlineRecognizer()
|
|
257
|
-
///
|
|
258
|
-
/// @param p A pointer returned by SherpaOnnxCreateOnlineRecognizer()
|
|
259
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyOnlineRecognizer(
|
|
260
|
-
const SherpaOnnxOnlineRecognizer *recognizer);
|
|
261
|
-
|
|
262
|
-
/// Create an online stream for accepting wave samples.
|
|
263
|
-
///
|
|
264
|
-
/// @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer()
|
|
265
|
-
/// @return Return a pointer to an OnlineStream. The user has to invoke
|
|
266
|
-
/// SherpaOnnxDestroyOnlineStream() to free it to avoid memory leak.
|
|
267
|
-
SHERPA_ONNX_API const SherpaOnnxOnlineStream *SherpaOnnxCreateOnlineStream(
|
|
268
|
-
const SherpaOnnxOnlineRecognizer *recognizer);
|
|
269
|
-
|
|
270
|
-
/// Create an online stream for accepting wave samples with the specified hot
|
|
271
|
-
/// words.
|
|
272
|
-
///
|
|
273
|
-
/// @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer()
|
|
274
|
-
/// @return Return a pointer to an OnlineStream. The user has to invoke
|
|
275
|
-
/// SherpaOnnxDestroyOnlineStream() to free it to avoid memory leak.
|
|
276
|
-
SHERPA_ONNX_API const SherpaOnnxOnlineStream *
|
|
277
|
-
SherpaOnnxCreateOnlineStreamWithHotwords(
|
|
278
|
-
const SherpaOnnxOnlineRecognizer *recognizer, const char *hotwords);
|
|
279
|
-
|
|
280
|
-
/// Destroy an online stream.
|
|
281
|
-
///
|
|
282
|
-
/// @param stream A pointer returned by SherpaOnnxCreateOnlineStream()
|
|
283
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyOnlineStream(
|
|
284
|
-
const SherpaOnnxOnlineStream *stream);
|
|
285
|
-
|
|
286
|
-
/// Accept input audio samples and compute the features.
|
|
287
|
-
/// The user has to invoke SherpaOnnxDecodeOnlineStream() to run the neural
|
|
288
|
-
/// network and decoding.
|
|
289
|
-
///
|
|
290
|
-
/// @param stream A pointer returned by SherpaOnnxCreateOnlineStream().
|
|
291
|
-
/// @param sample_rate Sample rate of the input samples. If it is different
|
|
292
|
-
/// from config.feat_config.sample_rate, we will do
|
|
293
|
-
/// resampling inside sherpa-onnx.
|
|
294
|
-
/// @param samples A pointer to a 1-D array containing audio samples.
|
|
295
|
-
/// The range of samples has to be normalized to [-1, 1].
|
|
296
|
-
/// @param n Number of elements in the samples array.
|
|
297
|
-
SHERPA_ONNX_API void SherpaOnnxOnlineStreamAcceptWaveform(
|
|
298
|
-
const SherpaOnnxOnlineStream *stream, int32_t sample_rate,
|
|
299
|
-
const float *samples, int32_t n);
|
|
300
|
-
|
|
301
|
-
/// Return 1 if there are enough number of feature frames for decoding.
|
|
302
|
-
/// Return 0 otherwise.
|
|
303
|
-
///
|
|
304
|
-
/// @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer
|
|
305
|
-
/// @param stream A pointer returned by SherpaOnnxCreateOnlineStream
|
|
306
|
-
SHERPA_ONNX_API int32_t
|
|
307
|
-
SherpaOnnxIsOnlineStreamReady(const SherpaOnnxOnlineRecognizer *recognizer,
|
|
308
|
-
const SherpaOnnxOnlineStream *stream);
|
|
309
|
-
|
|
310
|
-
/// Call this function to run the neural network model and decoding.
|
|
311
|
-
//
|
|
312
|
-
/// Precondition for this function: SherpaOnnxIsOnlineStreamReady() MUST
|
|
313
|
-
/// return 1.
|
|
314
|
-
///
|
|
315
|
-
/// Usage example:
|
|
316
|
-
///
|
|
317
|
-
/// while (SherpaOnnxIsOnlineStreamReady(recognizer, stream)) {
|
|
318
|
-
/// SherpaOnnxDecodeOnlineStream(recognizer, stream);
|
|
319
|
-
/// }
|
|
320
|
-
///
|
|
321
|
-
SHERPA_ONNX_API void SherpaOnnxDecodeOnlineStream(
|
|
322
|
-
const SherpaOnnxOnlineRecognizer *recognizer,
|
|
323
|
-
const SherpaOnnxOnlineStream *stream);
|
|
324
|
-
|
|
325
|
-
/// This function is similar to SherpaOnnxDecodeOnlineStream(). It decodes
|
|
326
|
-
/// multiple OnlineStream in parallel.
|
|
327
|
-
///
|
|
328
|
-
/// Caution: The caller has to ensure each OnlineStream is ready, i.e.,
|
|
329
|
-
/// SherpaOnnxIsOnlineStreamReady() for that stream should return 1.
|
|
330
|
-
///
|
|
331
|
-
/// @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer()
|
|
332
|
-
/// @param streams A pointer array containing pointers returned by
|
|
333
|
-
/// SherpaOnnxCreateOnlineRecognizer()
|
|
334
|
-
/// @param n Number of elements in the given streams array.
|
|
335
|
-
SHERPA_ONNX_API void SherpaOnnxDecodeMultipleOnlineStreams(
|
|
336
|
-
const SherpaOnnxOnlineRecognizer *recognizer,
|
|
337
|
-
const SherpaOnnxOnlineStream **streams, int32_t n);
|
|
338
|
-
|
|
339
|
-
/// Get the decoding results so far for an OnlineStream.
|
|
340
|
-
///
|
|
341
|
-
/// @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer().
|
|
342
|
-
/// @param stream A pointer returned by SherpaOnnxCreateOnlineStream().
|
|
343
|
-
/// @return A pointer containing the result. The user has to invoke
|
|
344
|
-
/// SherpaOnnxDestroyOnlineRecognizerResult() to free the returned
|
|
345
|
-
/// pointer to avoid memory leak.
|
|
346
|
-
SHERPA_ONNX_API const SherpaOnnxOnlineRecognizerResult *
|
|
347
|
-
SherpaOnnxGetOnlineStreamResult(const SherpaOnnxOnlineRecognizer *recognizer,
|
|
348
|
-
const SherpaOnnxOnlineStream *stream);
|
|
349
|
-
|
|
350
|
-
/// Destroy the pointer returned by SherpaOnnxGetOnlineStreamResult().
|
|
351
|
-
///
|
|
352
|
-
/// @param r A pointer returned by SherpaOnnxGetOnlineStreamResult()
|
|
353
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyOnlineRecognizerResult(
|
|
354
|
-
const SherpaOnnxOnlineRecognizerResult *r);
|
|
355
|
-
|
|
356
|
-
/// Return the result as a json string.
|
|
357
|
-
/// The user has to invoke
|
|
358
|
-
/// SherpaOnnxDestroyOnlineStreamResultJson()
|
|
359
|
-
/// to free the returned pointer to avoid memory leak
|
|
360
|
-
SHERPA_ONNX_API const char *SherpaOnnxGetOnlineStreamResultAsJson(
|
|
361
|
-
const SherpaOnnxOnlineRecognizer *recognizer,
|
|
362
|
-
const SherpaOnnxOnlineStream *stream);
|
|
363
|
-
|
|
364
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyOnlineStreamResultJson(const char *s);
|
|
365
|
-
|
|
366
|
-
/// SherpaOnnxOnlineStreamReset an OnlineStream , which clears the neural
|
|
367
|
-
/// network model state and the state for decoding.
|
|
368
|
-
///
|
|
369
|
-
/// @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer().
|
|
370
|
-
/// @param stream A pointer returned by SherpaOnnxCreateOnlineStream
|
|
371
|
-
SHERPA_ONNX_API void SherpaOnnxOnlineStreamReset(
|
|
372
|
-
const SherpaOnnxOnlineRecognizer *recognizer,
|
|
373
|
-
const SherpaOnnxOnlineStream *stream);
|
|
374
|
-
|
|
375
|
-
/// Signal that no more audio samples would be available.
|
|
376
|
-
/// After this call, you cannot call SherpaOnnxOnlineStreamAcceptWaveform() any
|
|
377
|
-
/// more.
|
|
378
|
-
///
|
|
379
|
-
/// @param stream A pointer returned by SherpaOnnxCreateOnlineStream()
|
|
380
|
-
SHERPA_ONNX_API void SherpaOnnxOnlineStreamInputFinished(
|
|
381
|
-
const SherpaOnnxOnlineStream *stream);
|
|
382
|
-
|
|
383
|
-
/// Return 1 if an endpoint has been detected.
|
|
384
|
-
///
|
|
385
|
-
/// @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer()
|
|
386
|
-
/// @param stream A pointer returned by SherpaOnnxCreateOnlineStream()
|
|
387
|
-
/// @return Return 1 if an endpoint is detected. Return 0 otherwise.
|
|
388
|
-
SHERPA_ONNX_API int32_t
|
|
389
|
-
SherpaOnnxOnlineStreamIsEndpoint(const SherpaOnnxOnlineRecognizer *recognizer,
|
|
390
|
-
const SherpaOnnxOnlineStream *stream);
|
|
391
|
-
|
|
392
|
-
// for displaying results on Linux/macOS.
|
|
393
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxDisplay SherpaOnnxDisplay;
|
|
394
|
-
|
|
395
|
-
/// Create a display object. Must be freed using SherpaOnnxDestroyDisplay to
|
|
396
|
-
/// avoid memory leak.
|
|
397
|
-
SHERPA_ONNX_API const SherpaOnnxDisplay *SherpaOnnxCreateDisplay(
|
|
398
|
-
int32_t max_word_per_line);
|
|
399
|
-
|
|
400
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyDisplay(const SherpaOnnxDisplay *display);
|
|
401
|
-
|
|
402
|
-
/// Print the result.
|
|
403
|
-
SHERPA_ONNX_API void SherpaOnnxPrint(const SherpaOnnxDisplay *display,
|
|
404
|
-
int32_t idx, const char *s);
|
|
405
|
-
// ============================================================
|
|
406
|
-
// For offline ASR (i.e., non-streaming ASR)
|
|
407
|
-
// ============================================================
|
|
408
|
-
|
|
409
|
-
/// Please refer to
|
|
410
|
-
/// https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
|
|
411
|
-
/// to download pre-trained models. That is, you can find encoder-xxx.onnx
|
|
412
|
-
/// decoder-xxx.onnx, and joiner-xxx.onnx for this struct
|
|
413
|
-
/// from there.
|
|
414
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTransducerModelConfig {
|
|
415
|
-
const char *encoder;
|
|
416
|
-
const char *decoder;
|
|
417
|
-
const char *joiner;
|
|
418
|
-
} SherpaOnnxOfflineTransducerModelConfig;
|
|
419
|
-
|
|
420
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineParaformerModelConfig {
|
|
421
|
-
const char *model;
|
|
422
|
-
} SherpaOnnxOfflineParaformerModelConfig;
|
|
423
|
-
|
|
424
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineNemoEncDecCtcModelConfig {
|
|
425
|
-
const char *model;
|
|
426
|
-
} SherpaOnnxOfflineNemoEncDecCtcModelConfig;
|
|
427
|
-
|
|
428
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineWhisperModelConfig {
|
|
429
|
-
const char *encoder;
|
|
430
|
-
const char *decoder;
|
|
431
|
-
const char *language;
|
|
432
|
-
const char *task;
|
|
433
|
-
int32_t tail_paddings;
|
|
434
|
-
} SherpaOnnxOfflineWhisperModelConfig;
|
|
435
|
-
|
|
436
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineCanaryModelConfig {
|
|
437
|
-
const char *encoder;
|
|
438
|
-
const char *decoder;
|
|
439
|
-
const char *src_lang;
|
|
440
|
-
const char *tgt_lang;
|
|
441
|
-
int32_t use_pnc;
|
|
442
|
-
} SherpaOnnxOfflineCanaryModelConfig;
|
|
443
|
-
|
|
444
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineFireRedAsrModelConfig {
|
|
445
|
-
const char *encoder;
|
|
446
|
-
const char *decoder;
|
|
447
|
-
} SherpaOnnxOfflineFireRedAsrModelConfig;
|
|
448
|
-
|
|
449
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineMoonshineModelConfig {
|
|
450
|
-
const char *preprocessor;
|
|
451
|
-
const char *encoder;
|
|
452
|
-
const char *uncached_decoder;
|
|
453
|
-
const char *cached_decoder;
|
|
454
|
-
} SherpaOnnxOfflineMoonshineModelConfig;
|
|
455
|
-
|
|
456
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTdnnModelConfig {
|
|
457
|
-
const char *model;
|
|
458
|
-
} SherpaOnnxOfflineTdnnModelConfig;
|
|
459
|
-
|
|
460
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineLMConfig {
|
|
461
|
-
const char *model;
|
|
462
|
-
float scale;
|
|
463
|
-
} SherpaOnnxOfflineLMConfig;
|
|
464
|
-
|
|
465
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineSenseVoiceModelConfig {
|
|
466
|
-
const char *model;
|
|
467
|
-
const char *language;
|
|
468
|
-
int32_t use_itn;
|
|
469
|
-
} SherpaOnnxOfflineSenseVoiceModelConfig;
|
|
470
|
-
|
|
471
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineDolphinModelConfig {
|
|
472
|
-
const char *model;
|
|
473
|
-
} SherpaOnnxOfflineDolphinModelConfig;
|
|
474
|
-
|
|
475
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineZipformerCtcModelConfig {
|
|
476
|
-
const char *model;
|
|
477
|
-
} SherpaOnnxOfflineZipformerCtcModelConfig;
|
|
478
|
-
|
|
479
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineWenetCtcModelConfig {
|
|
480
|
-
const char *model;
|
|
481
|
-
} SherpaOnnxOfflineWenetCtcModelConfig;
|
|
482
|
-
|
|
483
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineOmnilingualAsrCtcModelConfig {
|
|
484
|
-
const char *model;
|
|
485
|
-
} SherpaOnnxOfflineOmnilingualAsrCtcModelConfig;
|
|
486
|
-
|
|
487
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineFunASRNanoModelConfig {
|
|
488
|
-
const char *encoder_adaptor;
|
|
489
|
-
const char *llm;
|
|
490
|
-
const char *embedding;
|
|
491
|
-
const char *tokenizer;
|
|
492
|
-
const char *system_prompt;
|
|
493
|
-
const char *user_prompt;
|
|
494
|
-
int32_t max_new_tokens;
|
|
495
|
-
float temperature;
|
|
496
|
-
float top_p;
|
|
497
|
-
int32_t seed;
|
|
498
|
-
} SherpaOnnxOfflineFunASRNanoModelConfig;
|
|
499
|
-
|
|
500
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineMedAsrCtcModelConfig {
|
|
501
|
-
const char *model;
|
|
502
|
-
} SherpaOnnxOfflineMedAsrCtcModelConfig;
|
|
503
|
-
|
|
504
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineModelConfig {
|
|
505
|
-
SherpaOnnxOfflineTransducerModelConfig transducer;
|
|
506
|
-
SherpaOnnxOfflineParaformerModelConfig paraformer;
|
|
507
|
-
SherpaOnnxOfflineNemoEncDecCtcModelConfig nemo_ctc;
|
|
508
|
-
SherpaOnnxOfflineWhisperModelConfig whisper;
|
|
509
|
-
SherpaOnnxOfflineTdnnModelConfig tdnn;
|
|
510
|
-
|
|
511
|
-
const char *tokens;
|
|
512
|
-
int32_t num_threads;
|
|
513
|
-
int32_t debug;
|
|
514
|
-
const char *provider;
|
|
515
|
-
const char *model_type;
|
|
516
|
-
// Valid values:
|
|
517
|
-
// - cjkchar
|
|
518
|
-
// - bpe
|
|
519
|
-
// - cjkchar+bpe
|
|
520
|
-
const char *modeling_unit;
|
|
521
|
-
const char *bpe_vocab;
|
|
522
|
-
const char *telespeech_ctc;
|
|
523
|
-
SherpaOnnxOfflineSenseVoiceModelConfig sense_voice;
|
|
524
|
-
SherpaOnnxOfflineMoonshineModelConfig moonshine;
|
|
525
|
-
SherpaOnnxOfflineFireRedAsrModelConfig fire_red_asr;
|
|
526
|
-
SherpaOnnxOfflineDolphinModelConfig dolphin;
|
|
527
|
-
SherpaOnnxOfflineZipformerCtcModelConfig zipformer_ctc;
|
|
528
|
-
SherpaOnnxOfflineCanaryModelConfig canary;
|
|
529
|
-
SherpaOnnxOfflineWenetCtcModelConfig wenet_ctc;
|
|
530
|
-
SherpaOnnxOfflineOmnilingualAsrCtcModelConfig omnilingual;
|
|
531
|
-
SherpaOnnxOfflineMedAsrCtcModelConfig medasr;
|
|
532
|
-
SherpaOnnxOfflineFunASRNanoModelConfig funasr_nano;
|
|
533
|
-
} SherpaOnnxOfflineModelConfig;
|
|
534
|
-
|
|
535
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineRecognizerConfig {
|
|
536
|
-
SherpaOnnxFeatureConfig feat_config;
|
|
537
|
-
SherpaOnnxOfflineModelConfig model_config;
|
|
538
|
-
SherpaOnnxOfflineLMConfig lm_config;
|
|
539
|
-
|
|
540
|
-
const char *decoding_method;
|
|
541
|
-
int32_t max_active_paths;
|
|
542
|
-
|
|
543
|
-
/// Path to the hotwords.
|
|
544
|
-
const char *hotwords_file;
|
|
545
|
-
|
|
546
|
-
/// Bonus score for each token in hotwords.
|
|
547
|
-
float hotwords_score;
|
|
548
|
-
const char *rule_fsts;
|
|
549
|
-
const char *rule_fars;
|
|
550
|
-
float blank_penalty;
|
|
551
|
-
|
|
552
|
-
SherpaOnnxHomophoneReplacerConfig hr;
|
|
553
|
-
} SherpaOnnxOfflineRecognizerConfig;
|
|
554
|
-
|
|
555
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineRecognizer
|
|
556
|
-
SherpaOnnxOfflineRecognizer;
|
|
557
|
-
|
|
558
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineStream SherpaOnnxOfflineStream;
|
|
559
|
-
|
|
560
|
-
/// @param config Config for the recognizer.
|
|
561
|
-
/// @return Return a pointer to the recognizer. The user has to invoke
|
|
562
|
-
// SherpaOnnxDestroyOfflineRecognizer() to free it to avoid memory
|
|
563
|
-
// leak.
|
|
564
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineRecognizer *
|
|
565
|
-
SherpaOnnxCreateOfflineRecognizer(
|
|
566
|
-
const SherpaOnnxOfflineRecognizerConfig *config);
|
|
567
|
-
|
|
568
|
-
/// @param config Config for the recognizer.
|
|
569
|
-
SHERPA_ONNX_API void SherpaOnnxOfflineRecognizerSetConfig(
|
|
570
|
-
const SherpaOnnxOfflineRecognizer *recognizer,
|
|
571
|
-
const SherpaOnnxOfflineRecognizerConfig *config);
|
|
572
|
-
|
|
573
|
-
/// Free a pointer returned by SherpaOnnxCreateOfflineRecognizer()
|
|
574
|
-
///
|
|
575
|
-
/// @param p A pointer returned by SherpaOnnxCreateOfflineRecognizer()
|
|
576
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyOfflineRecognizer(
|
|
577
|
-
const SherpaOnnxOfflineRecognizer *recognizer);
|
|
578
|
-
|
|
579
|
-
/// Create an offline stream for accepting wave samples.
|
|
580
|
-
///
|
|
581
|
-
/// @param recognizer A pointer returned by SherpaOnnxCreateOfflineRecognizer()
|
|
582
|
-
/// @return Return a pointer to an OfflineStream. The user has to invoke
|
|
583
|
-
/// SherpaOnnxDestroyOfflineStream() to free it to avoid memory leak.
|
|
584
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineStream *SherpaOnnxCreateOfflineStream(
|
|
585
|
-
const SherpaOnnxOfflineRecognizer *recognizer);
|
|
586
|
-
|
|
587
|
-
/// Create an offline stream for accepting wave samples with the specified hot
|
|
588
|
-
/// words.
|
|
589
|
-
///
|
|
590
|
-
/// @param recognizer A pointer returned by SherpaOnnxCreateOfflineRecognizer()
|
|
591
|
-
/// @return Return a pointer to an OfflineStream. The user has to invoke
|
|
592
|
-
/// SherpaOnnxDestroyOfflineStream() to free it to avoid memory leak.
|
|
593
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineStream *
|
|
594
|
-
SherpaOnnxCreateOfflineStreamWithHotwords(
|
|
595
|
-
const SherpaOnnxOfflineRecognizer *recognizer, const char *hotwords);
|
|
596
|
-
|
|
597
|
-
/// Destroy an offline stream.
|
|
598
|
-
///
|
|
599
|
-
/// @param stream A pointer returned by SherpaOnnxCreateOfflineStream()
|
|
600
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyOfflineStream(
|
|
601
|
-
const SherpaOnnxOfflineStream *stream);
|
|
602
|
-
|
|
603
|
-
/// Accept input audio samples and compute the features.
|
|
604
|
-
/// The user has to invoke SherpaOnnxDecodeOfflineStream() to run the neural
|
|
605
|
-
/// network and decoding.
|
|
606
|
-
///
|
|
607
|
-
/// @param stream A pointer returned by SherpaOnnxCreateOfflineStream().
|
|
608
|
-
/// @param sample_rate Sample rate of the input samples. If it is different
|
|
609
|
-
/// from config.feat_config.sample_rate, we will do
|
|
610
|
-
/// resampling inside sherpa-onnx.
|
|
611
|
-
/// @param samples A pointer to a 1-D array containing audio samples.
|
|
612
|
-
/// The range of samples has to be normalized to [-1, 1].
|
|
613
|
-
/// @param n Number of elements in the samples array.
|
|
614
|
-
///
|
|
615
|
-
/// @caution: For each offline stream, please invoke this function only once!
|
|
616
|
-
SHERPA_ONNX_API void SherpaOnnxAcceptWaveformOffline(
|
|
617
|
-
const SherpaOnnxOfflineStream *stream, int32_t sample_rate,
|
|
618
|
-
const float *samples, int32_t n);
|
|
619
|
-
/// Decode an offline stream.
|
|
620
|
-
///
|
|
621
|
-
/// We assume you have invoked SherpaOnnxAcceptWaveformOffline() for the given
|
|
622
|
-
/// stream before calling this function.
|
|
623
|
-
///
|
|
624
|
-
/// @param recognizer A pointer returned by SherpaOnnxCreateOfflineRecognizer().
|
|
625
|
-
/// @param stream A pointer returned by SherpaOnnxCreateOfflineStream()
|
|
626
|
-
SHERPA_ONNX_API void SherpaOnnxDecodeOfflineStream(
|
|
627
|
-
const SherpaOnnxOfflineRecognizer *recognizer,
|
|
628
|
-
const SherpaOnnxOfflineStream *stream);
|
|
629
|
-
|
|
630
|
-
/// Decode a list offline streams in parallel.
|
|
631
|
-
///
|
|
632
|
-
/// We assume you have invoked SherpaOnnxAcceptWaveformOffline() for each stream
|
|
633
|
-
/// before calling this function.
|
|
634
|
-
///
|
|
635
|
-
/// @param recognizer A pointer returned by SherpaOnnxCreateOfflineRecognizer().
|
|
636
|
-
/// @param streams A pointer pointer array containing pointers returned
|
|
637
|
-
/// by SherpaOnnxCreateOfflineStream().
|
|
638
|
-
/// @param n Number of entries in the given streams.
|
|
639
|
-
SHERPA_ONNX_API void SherpaOnnxDecodeMultipleOfflineStreams(
|
|
640
|
-
const SherpaOnnxOfflineRecognizer *recognizer,
|
|
641
|
-
const SherpaOnnxOfflineStream **streams, int32_t n);
|
|
642
|
-
|
|
643
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineRecognizerResult {
|
|
644
|
-
const char *text;
|
|
645
|
-
|
|
646
|
-
// Pointer to continuous memory which holds timestamps
|
|
647
|
-
//
|
|
648
|
-
// It is NULL if the model does not support timestamps
|
|
649
|
-
float *timestamps;
|
|
650
|
-
|
|
651
|
-
// number of entries in timestamps
|
|
652
|
-
int32_t count;
|
|
653
|
-
|
|
654
|
-
// Pointer to continuous memory which holds string based tokens
|
|
655
|
-
// which are separated by \0
|
|
656
|
-
const char *tokens;
|
|
657
|
-
|
|
658
|
-
// a pointer array containing the address of the first item in tokens
|
|
659
|
-
const char *const *tokens_arr;
|
|
660
|
-
|
|
661
|
-
/** Return a json string.
|
|
662
|
-
*
|
|
663
|
-
* The returned string contains:
|
|
664
|
-
* {
|
|
665
|
-
* "text": "The recognition result",
|
|
666
|
-
* "tokens": [x, x, x],
|
|
667
|
-
* "timestamps": [x, x, x],
|
|
668
|
-
* "durations": [x, x, x],
|
|
669
|
-
* "segment": x,
|
|
670
|
-
* "start_time": x,
|
|
671
|
-
* "is_final": true|false
|
|
672
|
-
* }
|
|
673
|
-
*/
|
|
674
|
-
const char *json;
|
|
675
|
-
|
|
676
|
-
// return recognized language
|
|
677
|
-
const char *lang;
|
|
678
|
-
|
|
679
|
-
// return emotion.
|
|
680
|
-
const char *emotion;
|
|
681
|
-
|
|
682
|
-
// return event.
|
|
683
|
-
const char *event;
|
|
684
|
-
|
|
685
|
-
// Pointer to continuous memory which holds durations (in seconds) for each
|
|
686
|
-
// token It is NULL if the model does not support durations
|
|
687
|
-
float *durations;
|
|
688
|
-
|
|
689
|
-
// Pointer to continuous memory which holds log probabilities (confidence)
|
|
690
|
-
// for each token. It is NULL if the model does not support probabilities.
|
|
691
|
-
// ys_log_probs[i] is the log probability for token i.
|
|
692
|
-
float *ys_log_probs;
|
|
693
|
-
} SherpaOnnxOfflineRecognizerResult;
|
|
694
|
-
|
|
695
|
-
/// Get the result of the offline stream.
|
|
696
|
-
///
|
|
697
|
-
/// We assume you have called SherpaOnnxDecodeOfflineStream() or
|
|
698
|
-
/// SherpaOnnxDecodeMultipleOfflineStreams() with the given stream before
|
|
699
|
-
/// calling this function.
|
|
700
|
-
///
|
|
701
|
-
/// @param stream A pointer returned by SherpaOnnxCreateOfflineStream().
|
|
702
|
-
/// @return Return a pointer to the result. The user has to invoke
|
|
703
|
-
/// SherpaOnnxDestroyOnlineRecognizerResult() to free the returned
|
|
704
|
-
/// pointer to avoid memory leak.
|
|
705
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineRecognizerResult *
|
|
706
|
-
SherpaOnnxGetOfflineStreamResult(const SherpaOnnxOfflineStream *stream);
|
|
707
|
-
|
|
708
|
-
/// Destroy the pointer returned by SherpaOnnxGetOfflineStreamResult().
|
|
709
|
-
///
|
|
710
|
-
/// @param r A pointer returned by SherpaOnnxGetOfflineStreamResult()
|
|
711
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyOfflineRecognizerResult(
|
|
712
|
-
const SherpaOnnxOfflineRecognizerResult *r);
|
|
713
|
-
|
|
714
|
-
/// Return the result as a json string.
|
|
715
|
-
/// The user has to use SherpaOnnxDestroyOfflineStreamResultJson()
|
|
716
|
-
/// to free the returned pointer to avoid memory leak
|
|
717
|
-
SHERPA_ONNX_API const char *SherpaOnnxGetOfflineStreamResultAsJson(
|
|
718
|
-
const SherpaOnnxOfflineStream *stream);
|
|
719
|
-
|
|
720
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyOfflineStreamResultJson(const char *s);
|
|
721
|
-
|
|
722
|
-
// ============================================================
|
|
723
|
-
// For Keyword Spotter
|
|
724
|
-
// ============================================================
|
|
725
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxKeywordResult {
|
|
726
|
-
/// The triggered keyword.
|
|
727
|
-
/// For English, it consists of space separated words.
|
|
728
|
-
/// For Chinese, it consists of Chinese words without spaces.
|
|
729
|
-
/// Example 1: "hello world"
|
|
730
|
-
/// Example 2: "你好世界"
|
|
731
|
-
const char *keyword;
|
|
732
|
-
|
|
733
|
-
/// Decoded results at the token level.
|
|
734
|
-
/// For instance, for BPE-based models it consists of a list of BPE tokens.
|
|
735
|
-
const char *tokens;
|
|
736
|
-
|
|
737
|
-
const char *const *tokens_arr;
|
|
738
|
-
|
|
739
|
-
int32_t count;
|
|
740
|
-
|
|
741
|
-
/// timestamps.size() == tokens.size()
|
|
742
|
-
/// timestamps[i] records the time in seconds when tokens[i] is decoded.
|
|
743
|
-
float *timestamps;
|
|
744
|
-
|
|
745
|
-
/// Starting time of this segment.
|
|
746
|
-
/// When an endpoint is detected, it will change
|
|
747
|
-
float start_time;
|
|
748
|
-
|
|
749
|
-
/** Return a json string.
|
|
750
|
-
*
|
|
751
|
-
* The returned string contains:
|
|
752
|
-
* {
|
|
753
|
-
* "keyword": "The triggered keyword",
|
|
754
|
-
* "tokens": [x, x, x],
|
|
755
|
-
* "timestamps": [x, x, x],
|
|
756
|
-
* "start_time": x,
|
|
757
|
-
* }
|
|
758
|
-
*/
|
|
759
|
-
const char *json;
|
|
760
|
-
} SherpaOnnxKeywordResult;
|
|
761
|
-
|
|
762
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxKeywordSpotterConfig {
|
|
763
|
-
SherpaOnnxFeatureConfig feat_config;
|
|
764
|
-
SherpaOnnxOnlineModelConfig model_config;
|
|
765
|
-
int32_t max_active_paths;
|
|
766
|
-
int32_t num_trailing_blanks;
|
|
767
|
-
float keywords_score;
|
|
768
|
-
float keywords_threshold;
|
|
769
|
-
const char *keywords_file;
|
|
770
|
-
/// if non-null, loading the keywords from the buffer instead of from the
|
|
771
|
-
/// keywords_file
|
|
772
|
-
const char *keywords_buf;
|
|
773
|
-
/// byte size excluding the trailing '\0'
|
|
774
|
-
int32_t keywords_buf_size;
|
|
775
|
-
} SherpaOnnxKeywordSpotterConfig;
|
|
776
|
-
|
|
777
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxKeywordSpotter
|
|
778
|
-
SherpaOnnxKeywordSpotter;
|
|
779
|
-
|
|
780
|
-
/// @param config Config for the keyword spotter.
|
|
781
|
-
/// @return Return a pointer to the spotter. The user has to invoke
|
|
782
|
-
/// SherpaOnnxDestroyKeywordSpotter() to free it to avoid memory leak.
|
|
783
|
-
SHERPA_ONNX_API const SherpaOnnxKeywordSpotter *SherpaOnnxCreateKeywordSpotter(
|
|
784
|
-
const SherpaOnnxKeywordSpotterConfig *config);
|
|
785
|
-
|
|
786
|
-
/// Free a pointer returned by SherpaOnnxCreateKeywordSpotter()
|
|
787
|
-
///
|
|
788
|
-
/// @param p A pointer returned by SherpaOnnxCreateKeywordSpotter()
|
|
789
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyKeywordSpotter(
|
|
790
|
-
const SherpaOnnxKeywordSpotter *spotter);
|
|
791
|
-
|
|
792
|
-
/// Create an online stream for accepting wave samples.
|
|
793
|
-
///
|
|
794
|
-
/// @param spotter A pointer returned by SherpaOnnxCreateKeywordSpotter()
|
|
795
|
-
/// @return Return a pointer to an OnlineStream. The user has to invoke
|
|
796
|
-
/// SherpaOnnxDestroyOnlineStream() to free it to avoid memory leak.
|
|
797
|
-
SHERPA_ONNX_API const SherpaOnnxOnlineStream *SherpaOnnxCreateKeywordStream(
|
|
798
|
-
const SherpaOnnxKeywordSpotter *spotter);
|
|
799
|
-
|
|
800
|
-
/// Create an online stream for accepting wave samples with the specified hot
|
|
801
|
-
/// words.
|
|
802
|
-
///
|
|
803
|
-
/// @param spotter A pointer returned by SherpaOnnxCreateKeywordSpotter()
|
|
804
|
-
/// @param keywords A pointer points to the keywords that you set
|
|
805
|
-
/// @return Return a pointer to an OnlineStream. The user has to invoke
|
|
806
|
-
/// SherpaOnnxDestroyOnlineStream() to free it to avoid memory leak.
|
|
807
|
-
SHERPA_ONNX_API const SherpaOnnxOnlineStream *
|
|
808
|
-
SherpaOnnxCreateKeywordStreamWithKeywords(
|
|
809
|
-
const SherpaOnnxKeywordSpotter *spotter, const char *keywords);
|
|
810
|
-
|
|
811
|
-
/// Return 1 if there are enough number of feature frames for decoding.
|
|
812
|
-
/// Return 0 otherwise.
|
|
813
|
-
///
|
|
814
|
-
/// @param spotter A pointer returned by SherpaOnnxCreateKeywordSpotter
|
|
815
|
-
/// @param stream A pointer returned by SherpaOnnxCreateKeywordStream
|
|
816
|
-
SHERPA_ONNX_API int32_t
|
|
817
|
-
SherpaOnnxIsKeywordStreamReady(const SherpaOnnxKeywordSpotter *spotter,
|
|
818
|
-
const SherpaOnnxOnlineStream *stream);
|
|
819
|
-
|
|
820
|
-
/// Call this function to run the neural network model and decoding.
|
|
821
|
-
//
|
|
822
|
-
/// Precondition for this function: SherpaOnnxIsKeywordStreamReady() MUST
|
|
823
|
-
/// return 1.
|
|
824
|
-
SHERPA_ONNX_API void SherpaOnnxDecodeKeywordStream(
|
|
825
|
-
const SherpaOnnxKeywordSpotter *spotter,
|
|
826
|
-
const SherpaOnnxOnlineStream *stream);
|
|
827
|
-
|
|
828
|
-
/// Please call it right after a keyword is detected
|
|
829
|
-
SHERPA_ONNX_API void SherpaOnnxResetKeywordStream(
|
|
830
|
-
const SherpaOnnxKeywordSpotter *spotter,
|
|
831
|
-
const SherpaOnnxOnlineStream *stream);
|
|
832
|
-
|
|
833
|
-
/// This function is similar to SherpaOnnxDecodeKeywordStream(). It decodes
|
|
834
|
-
/// multiple OnlineStream in parallel.
|
|
835
|
-
///
|
|
836
|
-
/// Caution: The caller has to ensure each OnlineStream is ready, i.e.,
|
|
837
|
-
/// SherpaOnnxIsKeywordStreamReady() for that stream should return 1.
|
|
838
|
-
///
|
|
839
|
-
/// @param spotter A pointer returned by SherpaOnnxCreateKeywordSpotter()
|
|
840
|
-
/// @param streams A pointer array containing pointers returned by
|
|
841
|
-
/// SherpaOnnxCreateKeywordStream()
|
|
842
|
-
/// @param n Number of elements in the given streams array.
|
|
843
|
-
SHERPA_ONNX_API void SherpaOnnxDecodeMultipleKeywordStreams(
|
|
844
|
-
const SherpaOnnxKeywordSpotter *spotter,
|
|
845
|
-
const SherpaOnnxOnlineStream **streams, int32_t n);
|
|
846
|
-
|
|
847
|
-
/// Get the decoding results so far for an OnlineStream.
|
|
848
|
-
///
|
|
849
|
-
/// @param spotter A pointer returned by SherpaOnnxCreateKeywordSpotter().
|
|
850
|
-
/// @param stream A pointer returned by SherpaOnnxCreateKeywordStream().
|
|
851
|
-
/// @return A pointer containing the result. The user has to invoke
|
|
852
|
-
/// SherpaOnnxDestroyKeywordResult() to free the returned pointer to
|
|
853
|
-
/// avoid memory leak.
|
|
854
|
-
SHERPA_ONNX_API const SherpaOnnxKeywordResult *SherpaOnnxGetKeywordResult(
|
|
855
|
-
const SherpaOnnxKeywordSpotter *spotter,
|
|
856
|
-
const SherpaOnnxOnlineStream *stream);
|
|
857
|
-
|
|
858
|
-
/// Destroy the pointer returned by SherpaOnnxGetKeywordResult().
|
|
859
|
-
///
|
|
860
|
-
/// @param r A pointer returned by SherpaOnnxGetKeywordResult()
|
|
861
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyKeywordResult(
|
|
862
|
-
const SherpaOnnxKeywordResult *r);
|
|
863
|
-
|
|
864
|
-
// the user has to call SherpaOnnxFreeKeywordResultJson() to free the returned
|
|
865
|
-
// pointer to avoid memory leak
|
|
866
|
-
SHERPA_ONNX_API const char *SherpaOnnxGetKeywordResultAsJson(
|
|
867
|
-
const SherpaOnnxKeywordSpotter *spotter,
|
|
868
|
-
const SherpaOnnxOnlineStream *stream);
|
|
869
|
-
|
|
870
|
-
SHERPA_ONNX_API void SherpaOnnxFreeKeywordResultJson(const char *s);
|
|
871
|
-
|
|
872
|
-
// ============================================================
|
|
873
|
-
// For VAD
|
|
874
|
-
// ============================================================
|
|
875
|
-
|
|
876
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxSileroVadModelConfig {
|
|
877
|
-
// Path to the silero VAD model
|
|
878
|
-
const char *model;
|
|
879
|
-
|
|
880
|
-
// threshold to classify a segment as speech
|
|
881
|
-
//
|
|
882
|
-
// If the predicted probability of a segment is larger than this
|
|
883
|
-
// value, then it is classified as speech.
|
|
884
|
-
float threshold;
|
|
885
|
-
|
|
886
|
-
// in seconds
|
|
887
|
-
float min_silence_duration;
|
|
888
|
-
|
|
889
|
-
// in seconds
|
|
890
|
-
float min_speech_duration;
|
|
891
|
-
|
|
892
|
-
int32_t window_size;
|
|
893
|
-
|
|
894
|
-
// If a speech segment is longer than this value, then we increase
|
|
895
|
-
// the threshold to 0.9. After finishing detecting the segment,
|
|
896
|
-
// the threshold value is reset to its original value.
|
|
897
|
-
float max_speech_duration;
|
|
898
|
-
} SherpaOnnxSileroVadModelConfig;
|
|
899
|
-
|
|
900
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxTenVadModelConfig {
|
|
901
|
-
// Path to the ten-vad model
|
|
902
|
-
const char *model;
|
|
903
|
-
|
|
904
|
-
// threshold to classify a segment as speech
|
|
905
|
-
//
|
|
906
|
-
// If the predicted probability of a segment is larger than this
|
|
907
|
-
// value, then it is classified as speech.
|
|
908
|
-
float threshold;
|
|
909
|
-
|
|
910
|
-
// in seconds
|
|
911
|
-
float min_silence_duration;
|
|
912
|
-
|
|
913
|
-
// in seconds
|
|
914
|
-
float min_speech_duration;
|
|
915
|
-
|
|
916
|
-
int32_t window_size;
|
|
917
|
-
|
|
918
|
-
// If a speech segment is longer than this value, then we increase
|
|
919
|
-
// the threshold to 0.9. After finishing detecting the segment,
|
|
920
|
-
// the threshold value is reset to its original value.
|
|
921
|
-
float max_speech_duration;
|
|
922
|
-
} SherpaOnnxTenVadModelConfig;
|
|
923
|
-
|
|
924
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxVadModelConfig {
|
|
925
|
-
SherpaOnnxSileroVadModelConfig silero_vad;
|
|
926
|
-
|
|
927
|
-
int32_t sample_rate;
|
|
928
|
-
int32_t num_threads;
|
|
929
|
-
const char *provider;
|
|
930
|
-
int32_t debug;
|
|
931
|
-
SherpaOnnxTenVadModelConfig ten_vad;
|
|
932
|
-
} SherpaOnnxVadModelConfig;
|
|
933
|
-
|
|
934
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxCircularBuffer
|
|
935
|
-
SherpaOnnxCircularBuffer;
|
|
936
|
-
|
|
937
|
-
// Return an instance of circular buffer. The user has to use
|
|
938
|
-
// SherpaOnnxDestroyCircularBuffer() to free the returned pointer to avoid
|
|
939
|
-
// memory leak.
|
|
940
|
-
SHERPA_ONNX_API const SherpaOnnxCircularBuffer *SherpaOnnxCreateCircularBuffer(
|
|
941
|
-
int32_t capacity);
|
|
942
|
-
|
|
943
|
-
// Free the pointer returned by SherpaOnnxCreateCircularBuffer()
|
|
944
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyCircularBuffer(
|
|
945
|
-
const SherpaOnnxCircularBuffer *buffer);
|
|
946
|
-
|
|
947
|
-
SHERPA_ONNX_API void SherpaOnnxCircularBufferPush(
|
|
948
|
-
const SherpaOnnxCircularBuffer *buffer, const float *p, int32_t n);
|
|
949
|
-
|
|
950
|
-
// Return n samples starting at the given index.
|
|
951
|
-
//
|
|
952
|
-
// Return a pointer to an array containing n samples starting at start_index.
|
|
953
|
-
// The user has to use SherpaOnnxCircularBufferFree() to free the returned
|
|
954
|
-
// pointer to avoid memory leak.
|
|
955
|
-
SHERPA_ONNX_API const float *SherpaOnnxCircularBufferGet(
|
|
956
|
-
const SherpaOnnxCircularBuffer *buffer, int32_t start_index, int32_t n);
|
|
957
|
-
|
|
958
|
-
// Free the pointer returned by SherpaOnnxCircularBufferGet().
|
|
959
|
-
SHERPA_ONNX_API void SherpaOnnxCircularBufferFree(const float *p);
|
|
960
|
-
|
|
961
|
-
// Remove n elements from the buffer
|
|
962
|
-
SHERPA_ONNX_API void SherpaOnnxCircularBufferPop(
|
|
963
|
-
const SherpaOnnxCircularBuffer *buffer, int32_t n);
|
|
964
|
-
|
|
965
|
-
// Return number of elements in the buffer.
|
|
966
|
-
SHERPA_ONNX_API int32_t
|
|
967
|
-
SherpaOnnxCircularBufferSize(const SherpaOnnxCircularBuffer *buffer);
|
|
968
|
-
|
|
969
|
-
// Return the head of the buffer. It's always non-decreasing until you
|
|
970
|
-
// invoke SherpaOnnxCircularBufferReset() which resets head to 0.
|
|
971
|
-
SHERPA_ONNX_API int32_t
|
|
972
|
-
SherpaOnnxCircularBufferHead(const SherpaOnnxCircularBuffer *buffer);
|
|
973
|
-
|
|
974
|
-
// Clear all elements in the buffer
|
|
975
|
-
SHERPA_ONNX_API void SherpaOnnxCircularBufferReset(
|
|
976
|
-
const SherpaOnnxCircularBuffer *buffer);
|
|
977
|
-
|
|
978
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxSpeechSegment {
|
|
979
|
-
// The start index in samples of this segment
|
|
980
|
-
int32_t start;
|
|
981
|
-
|
|
982
|
-
// pointer to the array containing the samples
|
|
983
|
-
float *samples;
|
|
984
|
-
|
|
985
|
-
// number of samples in this segment
|
|
986
|
-
int32_t n;
|
|
987
|
-
} SherpaOnnxSpeechSegment;
|
|
988
|
-
|
|
989
|
-
typedef struct SherpaOnnxVoiceActivityDetector SherpaOnnxVoiceActivityDetector;
|
|
990
|
-
|
|
991
|
-
// Return an instance of VoiceActivityDetector.
|
|
992
|
-
// The user has to use SherpaOnnxDestroyVoiceActivityDetector() to free
|
|
993
|
-
// the returned pointer to avoid memory leak.
|
|
994
|
-
SHERPA_ONNX_API const SherpaOnnxVoiceActivityDetector *
|
|
995
|
-
SherpaOnnxCreateVoiceActivityDetector(const SherpaOnnxVadModelConfig *config,
|
|
996
|
-
float buffer_size_in_seconds);
|
|
997
|
-
|
|
998
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyVoiceActivityDetector(
|
|
999
|
-
const SherpaOnnxVoiceActivityDetector *p);
|
|
1000
|
-
|
|
1001
|
-
SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorAcceptWaveform(
|
|
1002
|
-
const SherpaOnnxVoiceActivityDetector *p, const float *samples, int32_t n);
|
|
1003
|
-
|
|
1004
|
-
// Return 1 if there are no speech segments available.
|
|
1005
|
-
// Return 0 if there are speech segments.
|
|
1006
|
-
SHERPA_ONNX_API int32_t
|
|
1007
|
-
SherpaOnnxVoiceActivityDetectorEmpty(const SherpaOnnxVoiceActivityDetector *p);
|
|
1008
|
-
|
|
1009
|
-
// Return 1 if there is voice detected.
|
|
1010
|
-
// Return 0 if voice is silent.
|
|
1011
|
-
SHERPA_ONNX_API int32_t SherpaOnnxVoiceActivityDetectorDetected(
|
|
1012
|
-
const SherpaOnnxVoiceActivityDetector *p);
|
|
1013
|
-
|
|
1014
|
-
// Return the first speech segment.
|
|
1015
|
-
// It throws if SherpaOnnxVoiceActivityDetectorEmpty() returns 1.
|
|
1016
|
-
SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorPop(
|
|
1017
|
-
const SherpaOnnxVoiceActivityDetector *p);
|
|
1018
|
-
|
|
1019
|
-
// Clear current speech segments.
|
|
1020
|
-
SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorClear(
|
|
1021
|
-
const SherpaOnnxVoiceActivityDetector *p);
|
|
1022
|
-
|
|
1023
|
-
// Return the first speech segment.
|
|
1024
|
-
// The user has to use SherpaOnnxDestroySpeechSegment() to free the returned
|
|
1025
|
-
// pointer to avoid memory leak.
|
|
1026
|
-
SHERPA_ONNX_API const SherpaOnnxSpeechSegment *
|
|
1027
|
-
SherpaOnnxVoiceActivityDetectorFront(const SherpaOnnxVoiceActivityDetector *p);
|
|
1028
|
-
|
|
1029
|
-
// Free the pointer returned SherpaOnnxVoiceActivityDetectorFront().
|
|
1030
|
-
SHERPA_ONNX_API void SherpaOnnxDestroySpeechSegment(
|
|
1031
|
-
const SherpaOnnxSpeechSegment *p);
|
|
1032
|
-
|
|
1033
|
-
// Re-initialize the voice activity detector.
|
|
1034
|
-
SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorReset(
|
|
1035
|
-
const SherpaOnnxVoiceActivityDetector *p);
|
|
1036
|
-
|
|
1037
|
-
SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorFlush(
|
|
1038
|
-
const SherpaOnnxVoiceActivityDetector *p);
|
|
1039
|
-
|
|
1040
|
-
// ============================================================
|
|
1041
|
-
// For offline Text-to-Speech (i.e., non-streaming TTS)
|
|
1042
|
-
// ============================================================
|
|
1043
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTtsVitsModelConfig {
|
|
1044
|
-
const char *model;
|
|
1045
|
-
const char *lexicon;
|
|
1046
|
-
const char *tokens;
|
|
1047
|
-
const char *data_dir;
|
|
1048
|
-
|
|
1049
|
-
float noise_scale;
|
|
1050
|
-
float noise_scale_w;
|
|
1051
|
-
float length_scale; // < 1, faster in speech speed; > 1, slower in speed
|
|
1052
|
-
const char *dict_dir; // unused
|
|
1053
|
-
} SherpaOnnxOfflineTtsVitsModelConfig;
|
|
1054
|
-
|
|
1055
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTtsMatchaModelConfig {
|
|
1056
|
-
const char *acoustic_model;
|
|
1057
|
-
const char *vocoder;
|
|
1058
|
-
const char *lexicon;
|
|
1059
|
-
const char *tokens;
|
|
1060
|
-
const char *data_dir;
|
|
1061
|
-
|
|
1062
|
-
float noise_scale;
|
|
1063
|
-
float length_scale; // < 1, faster in speech speed; > 1, slower in speed
|
|
1064
|
-
const char *dict_dir; // unused
|
|
1065
|
-
} SherpaOnnxOfflineTtsMatchaModelConfig;
|
|
1066
|
-
|
|
1067
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTtsKokoroModelConfig {
|
|
1068
|
-
const char *model;
|
|
1069
|
-
const char *voices;
|
|
1070
|
-
const char *tokens;
|
|
1071
|
-
const char *data_dir;
|
|
1072
|
-
|
|
1073
|
-
float length_scale; // < 1, faster in speech speed; > 1, slower in speed
|
|
1074
|
-
const char *dict_dir; // unused
|
|
1075
|
-
const char *lexicon;
|
|
1076
|
-
const char *lang;
|
|
1077
|
-
} SherpaOnnxOfflineTtsKokoroModelConfig;
|
|
1078
|
-
|
|
1079
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTtsKittenModelConfig {
|
|
1080
|
-
const char *model;
|
|
1081
|
-
const char *voices;
|
|
1082
|
-
const char *tokens;
|
|
1083
|
-
const char *data_dir;
|
|
1084
|
-
|
|
1085
|
-
float length_scale; // < 1, faster in speech speed; > 1, slower in speed
|
|
1086
|
-
} SherpaOnnxOfflineTtsKittenModelConfig;
|
|
1087
|
-
|
|
1088
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTtsZipvoiceModelConfig {
|
|
1089
|
-
const char *tokens;
|
|
1090
|
-
const char *encoder;
|
|
1091
|
-
const char *decoder;
|
|
1092
|
-
const char *vocoder;
|
|
1093
|
-
const char *data_dir;
|
|
1094
|
-
const char *lexicon;
|
|
1095
|
-
float feat_scale;
|
|
1096
|
-
float t_shift;
|
|
1097
|
-
float target_rms;
|
|
1098
|
-
float guidance_scale;
|
|
1099
|
-
} SherpaOnnxOfflineTtsZipvoiceModelConfig;
|
|
1100
|
-
|
|
1101
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTtsModelConfig {
|
|
1102
|
-
SherpaOnnxOfflineTtsVitsModelConfig vits;
|
|
1103
|
-
int32_t num_threads;
|
|
1104
|
-
int32_t debug;
|
|
1105
|
-
const char *provider;
|
|
1106
|
-
SherpaOnnxOfflineTtsMatchaModelConfig matcha;
|
|
1107
|
-
SherpaOnnxOfflineTtsKokoroModelConfig kokoro;
|
|
1108
|
-
SherpaOnnxOfflineTtsKittenModelConfig kitten;
|
|
1109
|
-
SherpaOnnxOfflineTtsZipvoiceModelConfig zipvoice;
|
|
1110
|
-
} SherpaOnnxOfflineTtsModelConfig;
|
|
1111
|
-
|
|
1112
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTtsConfig {
|
|
1113
|
-
SherpaOnnxOfflineTtsModelConfig model;
|
|
1114
|
-
const char *rule_fsts;
|
|
1115
|
-
int32_t max_num_sentences;
|
|
1116
|
-
const char *rule_fars;
|
|
1117
|
-
float silence_scale;
|
|
1118
|
-
} SherpaOnnxOfflineTtsConfig;
|
|
1119
|
-
|
|
1120
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxGeneratedAudio {
|
|
1121
|
-
const float *samples; // in the range [-1, 1]
|
|
1122
|
-
int32_t n; // number of samples
|
|
1123
|
-
int32_t sample_rate;
|
|
1124
|
-
} SherpaOnnxGeneratedAudio;
|
|
1125
|
-
|
|
1126
|
-
// If the callback returns 0, then it stops generating
|
|
1127
|
-
// If the callback returns 1, then it keeps generating
|
|
1128
|
-
typedef int32_t (*SherpaOnnxGeneratedAudioCallback)(const float *samples,
|
|
1129
|
-
int32_t n);
|
|
1130
|
-
|
|
1131
|
-
typedef int32_t (*SherpaOnnxGeneratedAudioCallbackWithArg)(const float *samples,
|
|
1132
|
-
int32_t n,
|
|
1133
|
-
void *arg);
|
|
1134
|
-
|
|
1135
|
-
typedef int32_t (*SherpaOnnxGeneratedAudioProgressCallback)(
|
|
1136
|
-
const float *samples, int32_t n, float p);
|
|
1137
|
-
|
|
1138
|
-
typedef int32_t (*SherpaOnnxGeneratedAudioProgressCallbackWithArg)(
|
|
1139
|
-
const float *samples, int32_t n, float p, void *arg);
|
|
1140
|
-
|
|
1141
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTts SherpaOnnxOfflineTts;
|
|
1142
|
-
|
|
1143
|
-
// Create an instance of offline TTS. The user has to use DestroyOfflineTts()
|
|
1144
|
-
// to free the returned pointer to avoid memory leak.
|
|
1145
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineTts *SherpaOnnxCreateOfflineTts(
|
|
1146
|
-
const SherpaOnnxOfflineTtsConfig *config);
|
|
1147
|
-
|
|
1148
|
-
// Free the pointer returned by SherpaOnnxCreateOfflineTts()
|
|
1149
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyOfflineTts(
|
|
1150
|
-
const SherpaOnnxOfflineTts *tts);
|
|
1151
|
-
|
|
1152
|
-
// Return the sample rate of the current TTS object
|
|
1153
|
-
SHERPA_ONNX_API int32_t
|
|
1154
|
-
SherpaOnnxOfflineTtsSampleRate(const SherpaOnnxOfflineTts *tts);
|
|
1155
|
-
|
|
1156
|
-
// Return the number of speakers of the current TTS object
|
|
1157
|
-
SHERPA_ONNX_API int32_t
|
|
1158
|
-
SherpaOnnxOfflineTtsNumSpeakers(const SherpaOnnxOfflineTts *tts);
|
|
1159
|
-
|
|
1160
|
-
// Generate audio from the given text and speaker id (sid).
|
|
1161
|
-
// The user has to use SherpaOnnxDestroyOfflineTtsGeneratedAudio() to free the
|
|
1162
|
-
// returned pointer to avoid memory leak.
|
|
1163
|
-
SHERPA_ONNX_API const SherpaOnnxGeneratedAudio *SherpaOnnxOfflineTtsGenerate(
|
|
1164
|
-
const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid,
|
|
1165
|
-
float speed);
|
|
1166
|
-
|
|
1167
|
-
// callback is called whenever SherpaOnnxOfflineTtsConfig.max_num_sentences
|
|
1168
|
-
// sentences have been processed. The pointer passed to the callback
|
|
1169
|
-
// is freed once the callback is returned. So the caller should not keep
|
|
1170
|
-
// a reference to it.
|
|
1171
|
-
SHERPA_ONNX_API const SherpaOnnxGeneratedAudio *
|
|
1172
|
-
SherpaOnnxOfflineTtsGenerateWithCallback(
|
|
1173
|
-
const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid, float speed,
|
|
1174
|
-
SherpaOnnxGeneratedAudioCallback callback);
|
|
1175
|
-
|
|
1176
|
-
SHERPA_ONNX_API
|
|
1177
|
-
const SherpaOnnxGeneratedAudio *
|
|
1178
|
-
SherpaOnnxOfflineTtsGenerateWithProgressCallback(
|
|
1179
|
-
const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid, float speed,
|
|
1180
|
-
SherpaOnnxGeneratedAudioProgressCallback callback);
|
|
1181
|
-
|
|
1182
|
-
SHERPA_ONNX_API
|
|
1183
|
-
const SherpaOnnxGeneratedAudio *
|
|
1184
|
-
SherpaOnnxOfflineTtsGenerateWithProgressCallbackWithArg(
|
|
1185
|
-
const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid, float speed,
|
|
1186
|
-
SherpaOnnxGeneratedAudioProgressCallbackWithArg callback, void *arg);
|
|
1187
|
-
|
|
1188
|
-
// Same as SherpaOnnxGeneratedAudioCallback but you can pass an additional
|
|
1189
|
-
// `void* arg` to the callback.
|
|
1190
|
-
SHERPA_ONNX_API const SherpaOnnxGeneratedAudio *
|
|
1191
|
-
SherpaOnnxOfflineTtsGenerateWithCallbackWithArg(
|
|
1192
|
-
const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid, float speed,
|
|
1193
|
-
SherpaOnnxGeneratedAudioCallbackWithArg callback, void *arg);
|
|
1194
|
-
|
|
1195
|
-
SHERPA_ONNX_API const SherpaOnnxGeneratedAudio *
|
|
1196
|
-
SherpaOnnxOfflineTtsGenerateWithZipvoice(const SherpaOnnxOfflineTts *tts,
|
|
1197
|
-
const char *text,
|
|
1198
|
-
const char *prompt_text,
|
|
1199
|
-
const float *prompt_samples,
|
|
1200
|
-
int32_t n_prompt, int32_t prompt_sr,
|
|
1201
|
-
float speed, int32_t num_steps);
|
|
1202
|
-
|
|
1203
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyOfflineTtsGeneratedAudio(
|
|
1204
|
-
const SherpaOnnxGeneratedAudio *p);
|
|
1205
|
-
|
|
1206
|
-
// Write the generated audio to a wave file.
|
|
1207
|
-
// The saved wave file contains a single channel and has 16-bit samples.
|
|
1208
|
-
//
|
|
1209
|
-
// Return 1 if the write succeeded; return 0 on failure.
|
|
1210
|
-
SHERPA_ONNX_API int32_t SherpaOnnxWriteWave(const float *samples, int32_t n,
|
|
1211
|
-
int32_t sample_rate,
|
|
1212
|
-
const char *filename);
|
|
1213
|
-
|
|
1214
|
-
// the amount of bytes needed to store a wave file which contains a
|
|
1215
|
-
// single channel and has 16-bit samples.
|
|
1216
|
-
SHERPA_ONNX_API int64_t SherpaOnnxWaveFileSize(int32_t n_samples);
|
|
1217
|
-
|
|
1218
|
-
// Similar to SherpaOnnxWriteWave , it writes wave to allocated buffer;
|
|
1219
|
-
//
|
|
1220
|
-
// in some case (http tts api return wave binary file, server do not need to
|
|
1221
|
-
// write wave to fs)
|
|
1222
|
-
SHERPA_ONNX_API void SherpaOnnxWriteWaveToBuffer(const float *samples,
|
|
1223
|
-
int32_t n, int32_t sample_rate,
|
|
1224
|
-
char *buffer);
|
|
1225
|
-
|
|
1226
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxWave {
|
|
1227
|
-
// samples normalized to the range [-1, 1]
|
|
1228
|
-
const float *samples;
|
|
1229
|
-
int32_t sample_rate;
|
|
1230
|
-
int32_t num_samples;
|
|
1231
|
-
} SherpaOnnxWave;
|
|
1232
|
-
|
|
1233
|
-
// Return a NULL pointer on error. It supports only standard WAVE file.
|
|
1234
|
-
// Each sample should be 16-bit. It supports only single channel..
|
|
1235
|
-
//
|
|
1236
|
-
// If the returned pointer is not NULL, the user has to invoke
|
|
1237
|
-
// SherpaOnnxFreeWave() to free the returned pointer to avoid memory leak.
|
|
1238
|
-
SHERPA_ONNX_API const SherpaOnnxWave *SherpaOnnxReadWave(const char *filename);
|
|
1239
|
-
|
|
1240
|
-
// Similar to SherpaOnnxReadWave(), it has read the content of `filename`
|
|
1241
|
-
// into the array `data`.
|
|
1242
|
-
//
|
|
1243
|
-
// If the returned pointer is not NULL, the user has to invoke
|
|
1244
|
-
// SherpaOnnxFreeWave() to free the returned pointer to avoid memory leak.
|
|
1245
|
-
SHERPA_ONNX_API const SherpaOnnxWave *SherpaOnnxReadWaveFromBinaryData(
|
|
1246
|
-
const char *data, int32_t n);
|
|
1247
|
-
|
|
1248
|
-
SHERPA_ONNX_API void SherpaOnnxFreeWave(const SherpaOnnxWave *wave);
|
|
1249
|
-
|
|
1250
|
-
// ============================================================
|
|
1251
|
-
// For spoken language identification
|
|
1252
|
-
// ============================================================
|
|
1253
|
-
|
|
1254
|
-
SHERPA_ONNX_API typedef struct
|
|
1255
|
-
SherpaOnnxSpokenLanguageIdentificationWhisperConfig {
|
|
1256
|
-
const char *encoder;
|
|
1257
|
-
const char *decoder;
|
|
1258
|
-
int32_t tail_paddings;
|
|
1259
|
-
} SherpaOnnxSpokenLanguageIdentificationWhisperConfig;
|
|
1260
|
-
|
|
1261
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxSpokenLanguageIdentificationConfig {
|
|
1262
|
-
SherpaOnnxSpokenLanguageIdentificationWhisperConfig whisper;
|
|
1263
|
-
int32_t num_threads;
|
|
1264
|
-
int32_t debug;
|
|
1265
|
-
const char *provider;
|
|
1266
|
-
} SherpaOnnxSpokenLanguageIdentificationConfig;
|
|
1267
|
-
|
|
1268
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxSpokenLanguageIdentification
|
|
1269
|
-
SherpaOnnxSpokenLanguageIdentification;
|
|
1270
|
-
|
|
1271
|
-
// Create an instance of SpokenLanguageIdentification.
|
|
1272
|
-
// The user has to invoke SherpaOnnxDestroySpokenLanguageIdentification()
|
|
1273
|
-
// to free the returned pointer to avoid memory leak.
|
|
1274
|
-
SHERPA_ONNX_API const SherpaOnnxSpokenLanguageIdentification *
|
|
1275
|
-
SherpaOnnxCreateSpokenLanguageIdentification(
|
|
1276
|
-
const SherpaOnnxSpokenLanguageIdentificationConfig *config);
|
|
1277
|
-
|
|
1278
|
-
SHERPA_ONNX_API void SherpaOnnxDestroySpokenLanguageIdentification(
|
|
1279
|
-
const SherpaOnnxSpokenLanguageIdentification *slid);
|
|
1280
|
-
|
|
1281
|
-
// The user has to invoke SherpaOnnxDestroyOfflineStream()
|
|
1282
|
-
// to free the returned pointer to avoid memory leak
|
|
1283
|
-
SHERPA_ONNX_API SherpaOnnxOfflineStream *
|
|
1284
|
-
SherpaOnnxSpokenLanguageIdentificationCreateOfflineStream(
|
|
1285
|
-
const SherpaOnnxSpokenLanguageIdentification *slid);
|
|
1286
|
-
|
|
1287
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxSpokenLanguageIdentificationResult {
|
|
1288
|
-
// en for English
|
|
1289
|
-
// de for German
|
|
1290
|
-
// zh for Chinese
|
|
1291
|
-
// es for Spanish
|
|
1292
|
-
// ...
|
|
1293
|
-
const char *lang;
|
|
1294
|
-
} SherpaOnnxSpokenLanguageIdentificationResult;
|
|
1295
|
-
|
|
1296
|
-
// The user has to invoke SherpaOnnxDestroySpokenLanguageIdentificationResult()
|
|
1297
|
-
// to free the returned pointer to avoid memory leak
|
|
1298
|
-
SHERPA_ONNX_API const SherpaOnnxSpokenLanguageIdentificationResult *
|
|
1299
|
-
SherpaOnnxSpokenLanguageIdentificationCompute(
|
|
1300
|
-
const SherpaOnnxSpokenLanguageIdentification *slid,
|
|
1301
|
-
const SherpaOnnxOfflineStream *s);
|
|
1302
|
-
|
|
1303
|
-
SHERPA_ONNX_API void SherpaOnnxDestroySpokenLanguageIdentificationResult(
|
|
1304
|
-
const SherpaOnnxSpokenLanguageIdentificationResult *r);
|
|
1305
|
-
|
|
1306
|
-
// ============================================================
|
|
1307
|
-
// For speaker embedding extraction
|
|
1308
|
-
// ============================================================
|
|
1309
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxSpeakerEmbeddingExtractorConfig {
|
|
1310
|
-
const char *model;
|
|
1311
|
-
int32_t num_threads;
|
|
1312
|
-
int32_t debug;
|
|
1313
|
-
const char *provider;
|
|
1314
|
-
} SherpaOnnxSpeakerEmbeddingExtractorConfig;
|
|
1315
|
-
|
|
1316
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxSpeakerEmbeddingExtractor
|
|
1317
|
-
SherpaOnnxSpeakerEmbeddingExtractor;
|
|
1318
|
-
|
|
1319
|
-
// The user has to invoke SherpaOnnxDestroySpeakerEmbeddingExtractor()
|
|
1320
|
-
// to free the returned pointer to avoid memory leak
|
|
1321
|
-
SHERPA_ONNX_API const SherpaOnnxSpeakerEmbeddingExtractor *
|
|
1322
|
-
SherpaOnnxCreateSpeakerEmbeddingExtractor(
|
|
1323
|
-
const SherpaOnnxSpeakerEmbeddingExtractorConfig *config);
|
|
1324
|
-
|
|
1325
|
-
SHERPA_ONNX_API void SherpaOnnxDestroySpeakerEmbeddingExtractor(
|
|
1326
|
-
const SherpaOnnxSpeakerEmbeddingExtractor *p);
|
|
1327
|
-
|
|
1328
|
-
SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingExtractorDim(
|
|
1329
|
-
const SherpaOnnxSpeakerEmbeddingExtractor *p);
|
|
1330
|
-
|
|
1331
|
-
// The user has to invoke SherpaOnnxDestroyOnlineStream() to free the returned
|
|
1332
|
-
// pointer to avoid memory leak
|
|
1333
|
-
SHERPA_ONNX_API const SherpaOnnxOnlineStream *
|
|
1334
|
-
SherpaOnnxSpeakerEmbeddingExtractorCreateStream(
|
|
1335
|
-
const SherpaOnnxSpeakerEmbeddingExtractor *p);
|
|
1336
|
-
|
|
1337
|
-
// Return 1 if the stream has enough feature frames for computing embeddings.
|
|
1338
|
-
// Return 0 otherwise.
|
|
1339
|
-
SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingExtractorIsReady(
|
|
1340
|
-
const SherpaOnnxSpeakerEmbeddingExtractor *p,
|
|
1341
|
-
const SherpaOnnxOnlineStream *s);
|
|
1342
|
-
|
|
1343
|
-
// Compute the embedding of the stream.
|
|
1344
|
-
//
|
|
1345
|
-
// @return Return a pointer pointing to an array containing the embedding.
|
|
1346
|
-
// The length of the array is `dim` as returned by
|
|
1347
|
-
// SherpaOnnxSpeakerEmbeddingExtractorDim(p)
|
|
1348
|
-
//
|
|
1349
|
-
// The user has to invoke SherpaOnnxSpeakerEmbeddingExtractorDestroyEmbedding()
|
|
1350
|
-
// to free the returned pointer to avoid memory leak.
|
|
1351
|
-
SHERPA_ONNX_API const float *
|
|
1352
|
-
SherpaOnnxSpeakerEmbeddingExtractorComputeEmbedding(
|
|
1353
|
-
const SherpaOnnxSpeakerEmbeddingExtractor *p,
|
|
1354
|
-
const SherpaOnnxOnlineStream *s);
|
|
1355
|
-
|
|
1356
|
-
SHERPA_ONNX_API void SherpaOnnxSpeakerEmbeddingExtractorDestroyEmbedding(
|
|
1357
|
-
const float *v);
|
|
1358
|
-
|
|
1359
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxSpeakerEmbeddingManager
|
|
1360
|
-
SherpaOnnxSpeakerEmbeddingManager;
|
|
1361
|
-
|
|
1362
|
-
// The user has to invoke SherpaOnnxDestroySpeakerEmbeddingManager()
|
|
1363
|
-
// to free the returned pointer to avoid memory leak
|
|
1364
|
-
SHERPA_ONNX_API const SherpaOnnxSpeakerEmbeddingManager *
|
|
1365
|
-
SherpaOnnxCreateSpeakerEmbeddingManager(int32_t dim);
|
|
1366
|
-
|
|
1367
|
-
SHERPA_ONNX_API void SherpaOnnxDestroySpeakerEmbeddingManager(
|
|
1368
|
-
const SherpaOnnxSpeakerEmbeddingManager *p);
|
|
1369
|
-
|
|
1370
|
-
// Register the embedding of a user
|
|
1371
|
-
//
|
|
1372
|
-
// @param name The name of the user
|
|
1373
|
-
// @param p Pointer to an array containing the embeddings. The length of the
|
|
1374
|
-
// array must be equal to `dim` used to construct the manager `p`.
|
|
1375
|
-
//
|
|
1376
|
-
// @return Return 1 if added successfully. Return 0 on error
|
|
1377
|
-
SHERPA_ONNX_API int32_t
|
|
1378
|
-
SherpaOnnxSpeakerEmbeddingManagerAdd(const SherpaOnnxSpeakerEmbeddingManager *p,
|
|
1379
|
-
const char *name, const float *v);
|
|
1380
|
-
|
|
1381
|
-
// @param v Pointer to an array of embeddings. If there are n embeddings, then
|
|
1382
|
-
// v[0] is the pointer to the 0-th array containing the embeddings
|
|
1383
|
-
// v[1] is the pointer to the 1-st array containing the embeddings
|
|
1384
|
-
// v[n-1] is the pointer to the last array containing the embeddings
|
|
1385
|
-
// v[n] is a NULL pointer
|
|
1386
|
-
// @return Return 1 if added successfully. Return 0 on error
|
|
1387
|
-
SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingManagerAddList(
|
|
1388
|
-
const SherpaOnnxSpeakerEmbeddingManager *p, const char *name,
|
|
1389
|
-
const float **v);
|
|
1390
|
-
|
|
1391
|
-
// Similar to SherpaOnnxSpeakerEmbeddingManagerAddList() but the memory
|
|
1392
|
-
// is flattened.
|
|
1393
|
-
//
|
|
1394
|
-
// The length of the input array should be `n * dim`.
|
|
1395
|
-
//
|
|
1396
|
-
// @return Return 1 if added successfully. Return 0 on error
|
|
1397
|
-
SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingManagerAddListFlattened(
|
|
1398
|
-
const SherpaOnnxSpeakerEmbeddingManager *p, const char *name,
|
|
1399
|
-
const float *v, int32_t n);
|
|
1400
|
-
|
|
1401
|
-
// Remove a user.
|
|
1402
|
-
// @param naem The name of the user to remove.
|
|
1403
|
-
// @return Return 1 if removed successfully; return 0 on error.
|
|
1404
|
-
//
|
|
1405
|
-
// Note if the user does not exist, it also returns 0.
|
|
1406
|
-
SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingManagerRemove(
|
|
1407
|
-
const SherpaOnnxSpeakerEmbeddingManager *p, const char *name);
|
|
1408
|
-
|
|
1409
|
-
// Search if an existing users' embedding matches the given one.
|
|
1410
|
-
//
|
|
1411
|
-
// @param p Pointer to an array containing the embedding. The dim
|
|
1412
|
-
// of the array must equal to `dim` used to construct the manager `p`.
|
|
1413
|
-
// @param threshold A value between 0 and 1. If the similarity score exceeds
|
|
1414
|
-
// this threshold, we say a match is found.
|
|
1415
|
-
// @return Returns the name of the user if found. Return NULL if not found.
|
|
1416
|
-
// If not NULL, the caller has to invoke
|
|
1417
|
-
// SherpaOnnxSpeakerEmbeddingManagerFreeSearch() to free the returned
|
|
1418
|
-
// pointer to avoid memory leak.
|
|
1419
|
-
SHERPA_ONNX_API const char *SherpaOnnxSpeakerEmbeddingManagerSearch(
|
|
1420
|
-
const SherpaOnnxSpeakerEmbeddingManager *p, const float *v,
|
|
1421
|
-
float threshold);
|
|
1422
|
-
|
|
1423
|
-
SHERPA_ONNX_API void SherpaOnnxSpeakerEmbeddingManagerFreeSearch(
|
|
1424
|
-
const char *name);
|
|
1425
|
-
|
|
1426
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxSpeakerEmbeddingManagerSpeakerMatch {
|
|
1427
|
-
float score;
|
|
1428
|
-
const char *name;
|
|
1429
|
-
} SherpaOnnxSpeakerEmbeddingManagerSpeakerMatch;
|
|
1430
|
-
|
|
1431
|
-
SHERPA_ONNX_API typedef struct
|
|
1432
|
-
SherpaOnnxSpeakerEmbeddingManagerBestMatchesResult {
|
|
1433
|
-
const SherpaOnnxSpeakerEmbeddingManagerSpeakerMatch *matches;
|
|
1434
|
-
int32_t count;
|
|
1435
|
-
} SherpaOnnxSpeakerEmbeddingManagerBestMatchesResult;
|
|
1436
|
-
|
|
1437
|
-
// Get the best matching speakers whose embeddings match the given
|
|
1438
|
-
// embedding.
|
|
1439
|
-
//
|
|
1440
|
-
// @param p Pointer to the SherpaOnnxSpeakerEmbeddingManager instance.
|
|
1441
|
-
// @param v Pointer to an array containing the embedding vector.
|
|
1442
|
-
// @param threshold Minimum similarity score required for a match (between 0 and
|
|
1443
|
-
// 1).
|
|
1444
|
-
// @param n Number of best matches to retrieve.
|
|
1445
|
-
// @return Returns a pointer to
|
|
1446
|
-
// SherpaOnnxSpeakerEmbeddingManagerBestMatchesResult
|
|
1447
|
-
// containing the best matches found. Returns NULL if no matches are
|
|
1448
|
-
// found. The caller is responsible for freeing the returned pointer
|
|
1449
|
-
// using SherpaOnnxSpeakerEmbeddingManagerFreeBestMatches() to
|
|
1450
|
-
// avoid memory leaks.
|
|
1451
|
-
SHERPA_ONNX_API const SherpaOnnxSpeakerEmbeddingManagerBestMatchesResult *
|
|
1452
|
-
SherpaOnnxSpeakerEmbeddingManagerGetBestMatches(
|
|
1453
|
-
const SherpaOnnxSpeakerEmbeddingManager *p, const float *v, float threshold,
|
|
1454
|
-
int32_t n);
|
|
1455
|
-
|
|
1456
|
-
SHERPA_ONNX_API void SherpaOnnxSpeakerEmbeddingManagerFreeBestMatches(
|
|
1457
|
-
const SherpaOnnxSpeakerEmbeddingManagerBestMatchesResult *r);
|
|
1458
|
-
|
|
1459
|
-
// Check whether the input embedding matches the embedding of the input
|
|
1460
|
-
// speaker.
|
|
1461
|
-
//
|
|
1462
|
-
// It is for speaker verification.
|
|
1463
|
-
//
|
|
1464
|
-
// @param name The target speaker name.
|
|
1465
|
-
// @param p The input embedding to check.
|
|
1466
|
-
// @param threshold A value between 0 and 1.
|
|
1467
|
-
// @return Return 1 if it matches. Otherwise, it returns 0.
|
|
1468
|
-
SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingManagerVerify(
|
|
1469
|
-
const SherpaOnnxSpeakerEmbeddingManager *p, const char *name,
|
|
1470
|
-
const float *v, float threshold);
|
|
1471
|
-
|
|
1472
|
-
// Return 1 if the user with the name is in the manager.
|
|
1473
|
-
// Return 0 if the user does not exist.
|
|
1474
|
-
SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingManagerContains(
|
|
1475
|
-
const SherpaOnnxSpeakerEmbeddingManager *p, const char *name);
|
|
1476
|
-
|
|
1477
|
-
// Return number of speakers in the manager.
|
|
1478
|
-
SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingManagerNumSpeakers(
|
|
1479
|
-
const SherpaOnnxSpeakerEmbeddingManager *p);
|
|
1480
|
-
|
|
1481
|
-
// Return the name of all speakers in the manager.
|
|
1482
|
-
//
|
|
1483
|
-
// @return Return an array of pointers `ans`. If there are n speakers, then
|
|
1484
|
-
// - ans[0] contains the name of the 0-th speaker
|
|
1485
|
-
// - ans[1] contains the name of the 1-st speaker
|
|
1486
|
-
// - ans[n-1] contains the name of the last speaker
|
|
1487
|
-
// - ans[n] is NULL
|
|
1488
|
-
// If there are no users at all, then ans[0] is NULL. In any case,
|
|
1489
|
-
// `ans` is not NULL.
|
|
1490
|
-
//
|
|
1491
|
-
// Each name is NULL-terminated
|
|
1492
|
-
//
|
|
1493
|
-
// The caller has to invoke SherpaOnnxSpeakerEmbeddingManagerFreeAllSpeakers()
|
|
1494
|
-
// to free the returned pointer to avoid memory leak.
|
|
1495
|
-
SHERPA_ONNX_API const char *const *
|
|
1496
|
-
SherpaOnnxSpeakerEmbeddingManagerGetAllSpeakers(
|
|
1497
|
-
const SherpaOnnxSpeakerEmbeddingManager *p);
|
|
1498
|
-
|
|
1499
|
-
SHERPA_ONNX_API void SherpaOnnxSpeakerEmbeddingManagerFreeAllSpeakers(
|
|
1500
|
-
const char *const *names);
|
|
1501
|
-
|
|
1502
|
-
// ============================================================
|
|
1503
|
-
// For audio tagging
|
|
1504
|
-
// ============================================================
|
|
1505
|
-
SHERPA_ONNX_API typedef struct
|
|
1506
|
-
SherpaOnnxOfflineZipformerAudioTaggingModelConfig {
|
|
1507
|
-
const char *model;
|
|
1508
|
-
} SherpaOnnxOfflineZipformerAudioTaggingModelConfig;
|
|
1509
|
-
|
|
1510
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxAudioTaggingModelConfig {
|
|
1511
|
-
SherpaOnnxOfflineZipformerAudioTaggingModelConfig zipformer;
|
|
1512
|
-
const char *ced;
|
|
1513
|
-
int32_t num_threads;
|
|
1514
|
-
int32_t debug; // true to print debug information of the model
|
|
1515
|
-
const char *provider;
|
|
1516
|
-
} SherpaOnnxAudioTaggingModelConfig;
|
|
1517
|
-
|
|
1518
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxAudioTaggingConfig {
|
|
1519
|
-
SherpaOnnxAudioTaggingModelConfig model;
|
|
1520
|
-
const char *labels;
|
|
1521
|
-
int32_t top_k;
|
|
1522
|
-
} SherpaOnnxAudioTaggingConfig;
|
|
1523
|
-
|
|
1524
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxAudioEvent {
|
|
1525
|
-
const char *name;
|
|
1526
|
-
int32_t index;
|
|
1527
|
-
float prob;
|
|
1528
|
-
} SherpaOnnxAudioEvent;
|
|
1529
|
-
|
|
1530
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxAudioTagging SherpaOnnxAudioTagging;
|
|
1531
|
-
|
|
1532
|
-
// The user has to invoke
|
|
1533
|
-
// SherpaOnnxDestroyAudioTagging()
|
|
1534
|
-
// to free the returned pointer to avoid memory leak
|
|
1535
|
-
SHERPA_ONNX_API const SherpaOnnxAudioTagging *SherpaOnnxCreateAudioTagging(
|
|
1536
|
-
const SherpaOnnxAudioTaggingConfig *config);
|
|
1537
|
-
|
|
1538
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyAudioTagging(
|
|
1539
|
-
const SherpaOnnxAudioTagging *tagger);
|
|
1540
|
-
|
|
1541
|
-
// The user has to invoke SherpaOnnxDestroyOfflineStream()
|
|
1542
|
-
// to free the returned pointer to avoid memory leak
|
|
1543
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineStream *
|
|
1544
|
-
SherpaOnnxAudioTaggingCreateOfflineStream(const SherpaOnnxAudioTagging *tagger);
|
|
1545
|
-
|
|
1546
|
-
// Return an array of pointers. The length of the array is top_k + 1.
|
|
1547
|
-
// If top_k is -1, then config.top_k is used, where config is the config
|
|
1548
|
-
// used to create the input tagger.
|
|
1549
|
-
//
|
|
1550
|
-
// The ans[0]->prob has the largest probability among the array elements
|
|
1551
|
-
// The last element of the array is a null pointer
|
|
1552
|
-
//
|
|
1553
|
-
// The user has to use SherpaOnnxAudioTaggingFreeResults()
|
|
1554
|
-
// to free the returned pointer to avoid memory leak
|
|
1555
|
-
SHERPA_ONNX_API const SherpaOnnxAudioEvent *const *
|
|
1556
|
-
SherpaOnnxAudioTaggingCompute(const SherpaOnnxAudioTagging *tagger,
|
|
1557
|
-
const SherpaOnnxOfflineStream *s, int32_t top_k);
|
|
1558
|
-
|
|
1559
|
-
SHERPA_ONNX_API void SherpaOnnxAudioTaggingFreeResults(
|
|
1560
|
-
const SherpaOnnxAudioEvent *const *p);
|
|
1561
|
-
|
|
1562
|
-
// ============================================================
|
|
1563
|
-
// For punctuation
|
|
1564
|
-
// ============================================================
|
|
1565
|
-
|
|
1566
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflinePunctuationModelConfig {
|
|
1567
|
-
const char *ct_transformer;
|
|
1568
|
-
int32_t num_threads;
|
|
1569
|
-
int32_t debug; // true to print debug information of the model
|
|
1570
|
-
const char *provider;
|
|
1571
|
-
} SherpaOnnxOfflinePunctuationModelConfig;
|
|
1572
|
-
|
|
1573
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflinePunctuationConfig {
|
|
1574
|
-
SherpaOnnxOfflinePunctuationModelConfig model;
|
|
1575
|
-
} SherpaOnnxOfflinePunctuationConfig;
|
|
1576
|
-
|
|
1577
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflinePunctuation
|
|
1578
|
-
SherpaOnnxOfflinePunctuation;
|
|
1579
|
-
|
|
1580
|
-
// The user has to invoke SherpaOnnxDestroyOfflinePunctuation()
|
|
1581
|
-
// to free the returned pointer to avoid memory leak
|
|
1582
|
-
SHERPA_ONNX_API const SherpaOnnxOfflinePunctuation *
|
|
1583
|
-
SherpaOnnxCreateOfflinePunctuation(
|
|
1584
|
-
const SherpaOnnxOfflinePunctuationConfig *config);
|
|
1585
|
-
|
|
1586
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyOfflinePunctuation(
|
|
1587
|
-
const SherpaOnnxOfflinePunctuation *punct);
|
|
1588
|
-
|
|
1589
|
-
// Add punctuations to the input text.
|
|
1590
|
-
// The user has to invoke SherpaOfflinePunctuationFreeText()
|
|
1591
|
-
// to free the returned pointer to avoid memory leak
|
|
1592
|
-
SHERPA_ONNX_API const char *SherpaOfflinePunctuationAddPunct(
|
|
1593
|
-
const SherpaOnnxOfflinePunctuation *punct, const char *text);
|
|
1594
|
-
|
|
1595
|
-
SHERPA_ONNX_API void SherpaOfflinePunctuationFreeText(const char *text);
|
|
1596
|
-
|
|
1597
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOnlinePunctuationModelConfig {
|
|
1598
|
-
const char *cnn_bilstm;
|
|
1599
|
-
const char *bpe_vocab;
|
|
1600
|
-
int32_t num_threads;
|
|
1601
|
-
int32_t debug;
|
|
1602
|
-
const char *provider;
|
|
1603
|
-
} SherpaOnnxOnlinePunctuationModelConfig;
|
|
1604
|
-
|
|
1605
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOnlinePunctuationConfig {
|
|
1606
|
-
SherpaOnnxOnlinePunctuationModelConfig model;
|
|
1607
|
-
} SherpaOnnxOnlinePunctuationConfig;
|
|
1608
|
-
|
|
1609
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOnlinePunctuation
|
|
1610
|
-
SherpaOnnxOnlinePunctuation;
|
|
1611
|
-
|
|
1612
|
-
// Create an online punctuation processor. The user has to invoke
|
|
1613
|
-
// SherpaOnnxDestroyOnlinePunctuation() to free the returned pointer
|
|
1614
|
-
// to avoid memory leak
|
|
1615
|
-
SHERPA_ONNX_API const SherpaOnnxOnlinePunctuation *
|
|
1616
|
-
SherpaOnnxCreateOnlinePunctuation(
|
|
1617
|
-
const SherpaOnnxOnlinePunctuationConfig *config);
|
|
1618
|
-
|
|
1619
|
-
// Free a pointer returned by SherpaOnnxCreateOnlinePunctuation()
|
|
1620
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyOnlinePunctuation(
|
|
1621
|
-
const SherpaOnnxOnlinePunctuation *punctuation);
|
|
1622
|
-
|
|
1623
|
-
// Add punctuations to the input text. The user has to invoke
|
|
1624
|
-
// SherpaOnnxOnlinePunctuationFreeText() to free the returned pointer
|
|
1625
|
-
// to avoid memory leak
|
|
1626
|
-
SHERPA_ONNX_API const char *SherpaOnnxOnlinePunctuationAddPunct(
|
|
1627
|
-
const SherpaOnnxOnlinePunctuation *punctuation, const char *text);
|
|
1628
|
-
|
|
1629
|
-
// Free a pointer returned by SherpaOnnxOnlinePunctuationAddPunct()
|
|
1630
|
-
SHERPA_ONNX_API void SherpaOnnxOnlinePunctuationFreeText(const char *text);
|
|
1631
|
-
|
|
1632
|
-
// for resampling
|
|
1633
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxLinearResampler
|
|
1634
|
-
SherpaOnnxLinearResampler;
|
|
1635
|
-
|
|
1636
|
-
/*
|
|
1637
|
-
float min_freq = min(sampling_rate_in_hz, samp_rate_out_hz);
|
|
1638
|
-
float lowpass_cutoff = 0.99 * 0.5 * min_freq;
|
|
1639
|
-
int32_t lowpass_filter_width = 6;
|
|
1640
|
-
|
|
1641
|
-
You can set filter_cutoff_hz to lowpass_cutoff
|
|
1642
|
-
sand set num_zeros to lowpass_filter_width
|
|
1643
|
-
*/
|
|
1644
|
-
// The user has to invoke SherpaOnnxDestroyLinearResampler()
|
|
1645
|
-
// to free the returned pointer to avoid memory leak
|
|
1646
|
-
SHERPA_ONNX_API const SherpaOnnxLinearResampler *
|
|
1647
|
-
SherpaOnnxCreateLinearResampler(int32_t samp_rate_in_hz,
|
|
1648
|
-
int32_t samp_rate_out_hz,
|
|
1649
|
-
float filter_cutoff_hz, int32_t num_zeros);
|
|
1650
|
-
|
|
1651
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyLinearResampler(
|
|
1652
|
-
const SherpaOnnxLinearResampler *p);
|
|
1653
|
-
|
|
1654
|
-
SHERPA_ONNX_API void SherpaOnnxLinearResamplerReset(
|
|
1655
|
-
const SherpaOnnxLinearResampler *p);
|
|
1656
|
-
|
|
1657
|
-
typedef struct SherpaOnnxResampleOut {
|
|
1658
|
-
const float *samples;
|
|
1659
|
-
int32_t n;
|
|
1660
|
-
} SherpaOnnxResampleOut;
|
|
1661
|
-
// The user has to invoke SherpaOnnxLinearResamplerResampleFree()
|
|
1662
|
-
// to free the returned pointer to avoid memory leak.
|
|
1663
|
-
//
|
|
1664
|
-
// If this is the last segment, you can set flush to 1; otherwise, please
|
|
1665
|
-
// set flush to 0
|
|
1666
|
-
SHERPA_ONNX_API const SherpaOnnxResampleOut *SherpaOnnxLinearResamplerResample(
|
|
1667
|
-
const SherpaOnnxLinearResampler *p, const float *input, int32_t input_dim,
|
|
1668
|
-
int32_t flush);
|
|
1669
|
-
|
|
1670
|
-
SHERPA_ONNX_API void SherpaOnnxLinearResamplerResampleFree(
|
|
1671
|
-
const SherpaOnnxResampleOut *p);
|
|
1672
|
-
|
|
1673
|
-
SHERPA_ONNX_API int32_t SherpaOnnxLinearResamplerResampleGetInputSampleRate(
|
|
1674
|
-
const SherpaOnnxLinearResampler *p);
|
|
1675
|
-
|
|
1676
|
-
SHERPA_ONNX_API int32_t SherpaOnnxLinearResamplerResampleGetOutputSampleRate(
|
|
1677
|
-
const SherpaOnnxLinearResampler *p);
|
|
1678
|
-
|
|
1679
|
-
// =========================================================================
|
|
1680
|
-
// For offline speaker diarization (i.e., non-streaming speaker diarization)
|
|
1681
|
-
// =========================================================================
|
|
1682
|
-
SHERPA_ONNX_API typedef struct
|
|
1683
|
-
SherpaOnnxOfflineSpeakerSegmentationPyannoteModelConfig {
|
|
1684
|
-
const char *model;
|
|
1685
|
-
} SherpaOnnxOfflineSpeakerSegmentationPyannoteModelConfig;
|
|
1686
|
-
|
|
1687
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineSpeakerSegmentationModelConfig {
|
|
1688
|
-
SherpaOnnxOfflineSpeakerSegmentationPyannoteModelConfig pyannote;
|
|
1689
|
-
int32_t num_threads; // 1
|
|
1690
|
-
int32_t debug; // false
|
|
1691
|
-
const char *provider; // "cpu"
|
|
1692
|
-
} SherpaOnnxOfflineSpeakerSegmentationModelConfig;
|
|
1693
|
-
|
|
1694
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxFastClusteringConfig {
|
|
1695
|
-
// If greater than 0, then threshold is ignored.
|
|
1696
|
-
//
|
|
1697
|
-
// We strongly recommend that you set it if you know the number of clusters
|
|
1698
|
-
// in advance
|
|
1699
|
-
int32_t num_clusters;
|
|
1700
|
-
|
|
1701
|
-
// distance threshold.
|
|
1702
|
-
//
|
|
1703
|
-
// The smaller, the more clusters it will generate.
|
|
1704
|
-
// The larger, the fewer clusters it will generate.
|
|
1705
|
-
float threshold;
|
|
1706
|
-
} SherpaOnnxFastClusteringConfig;
|
|
1707
|
-
|
|
1708
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineSpeakerDiarizationConfig {
|
|
1709
|
-
SherpaOnnxOfflineSpeakerSegmentationModelConfig segmentation;
|
|
1710
|
-
SherpaOnnxSpeakerEmbeddingExtractorConfig embedding;
|
|
1711
|
-
SherpaOnnxFastClusteringConfig clustering;
|
|
1712
|
-
|
|
1713
|
-
// if a segment is less than this value, then it is discarded
|
|
1714
|
-
float min_duration_on; // in seconds
|
|
1715
|
-
|
|
1716
|
-
// if the gap between to segments of the same speaker is less than this value,
|
|
1717
|
-
// then these two segments are merged into a single segment.
|
|
1718
|
-
// We do this recursively.
|
|
1719
|
-
float min_duration_off; // in seconds
|
|
1720
|
-
} SherpaOnnxOfflineSpeakerDiarizationConfig;
|
|
1721
|
-
|
|
1722
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineSpeakerDiarization
|
|
1723
|
-
SherpaOnnxOfflineSpeakerDiarization;
|
|
1724
|
-
|
|
1725
|
-
// The users has to invoke SherpaOnnxDestroyOfflineSpeakerDiarization()
|
|
1726
|
-
// to free the returned pointer to avoid memory leak
|
|
1727
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineSpeakerDiarization *
|
|
1728
|
-
SherpaOnnxCreateOfflineSpeakerDiarization(
|
|
1729
|
-
const SherpaOnnxOfflineSpeakerDiarizationConfig *config);
|
|
1730
|
-
|
|
1731
|
-
// Free the pointer returned by SherpaOnnxCreateOfflineSpeakerDiarization()
|
|
1732
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyOfflineSpeakerDiarization(
|
|
1733
|
-
const SherpaOnnxOfflineSpeakerDiarization *sd);
|
|
1734
|
-
|
|
1735
|
-
// Expected sample rate of the input audio samples
|
|
1736
|
-
SHERPA_ONNX_API int32_t SherpaOnnxOfflineSpeakerDiarizationGetSampleRate(
|
|
1737
|
-
const SherpaOnnxOfflineSpeakerDiarization *sd);
|
|
1738
|
-
|
|
1739
|
-
// Only config->clustering is used. All other fields are ignored
|
|
1740
|
-
SHERPA_ONNX_API void SherpaOnnxOfflineSpeakerDiarizationSetConfig(
|
|
1741
|
-
const SherpaOnnxOfflineSpeakerDiarization *sd,
|
|
1742
|
-
const SherpaOnnxOfflineSpeakerDiarizationConfig *config);
|
|
1743
|
-
|
|
1744
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineSpeakerDiarizationResult
|
|
1745
|
-
SherpaOnnxOfflineSpeakerDiarizationResult;
|
|
1746
|
-
|
|
1747
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineSpeakerDiarizationSegment {
|
|
1748
|
-
float start;
|
|
1749
|
-
float end;
|
|
1750
|
-
int32_t speaker;
|
|
1751
|
-
} SherpaOnnxOfflineSpeakerDiarizationSegment;
|
|
1752
|
-
|
|
1753
|
-
SHERPA_ONNX_API int32_t SherpaOnnxOfflineSpeakerDiarizationResultGetNumSpeakers(
|
|
1754
|
-
const SherpaOnnxOfflineSpeakerDiarizationResult *r);
|
|
1755
|
-
|
|
1756
|
-
SHERPA_ONNX_API int32_t SherpaOnnxOfflineSpeakerDiarizationResultGetNumSegments(
|
|
1757
|
-
const SherpaOnnxOfflineSpeakerDiarizationResult *r);
|
|
1758
|
-
|
|
1759
|
-
// The user has to invoke SherpaOnnxOfflineSpeakerDiarizationDestroySegment()
|
|
1760
|
-
// to free the returned pointer to avoid memory leak.
|
|
1761
|
-
//
|
|
1762
|
-
// The returned pointer is the start address of an array.
|
|
1763
|
-
// Number of entries in the array equals to the value
|
|
1764
|
-
// returned by SherpaOnnxOfflineSpeakerDiarizationResultGetNumSegments()
|
|
1765
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineSpeakerDiarizationSegment *
|
|
1766
|
-
SherpaOnnxOfflineSpeakerDiarizationResultSortByStartTime(
|
|
1767
|
-
const SherpaOnnxOfflineSpeakerDiarizationResult *r);
|
|
1768
|
-
|
|
1769
|
-
SHERPA_ONNX_API void SherpaOnnxOfflineSpeakerDiarizationDestroySegment(
|
|
1770
|
-
const SherpaOnnxOfflineSpeakerDiarizationSegment *s);
|
|
1771
|
-
|
|
1772
|
-
typedef int32_t (*SherpaOnnxOfflineSpeakerDiarizationProgressCallback)(
|
|
1773
|
-
int32_t num_processed_chunks, int32_t num_total_chunks, void *arg);
|
|
1774
|
-
|
|
1775
|
-
typedef int32_t (*SherpaOnnxOfflineSpeakerDiarizationProgressCallbackNoArg)(
|
|
1776
|
-
int32_t num_processed_chunks, int32_t num_total_chunks);
|
|
1777
|
-
|
|
1778
|
-
// The user has to invoke SherpaOnnxOfflineSpeakerDiarizationDestroyResult()
|
|
1779
|
-
// to free the returned pointer to avoid memory leak.
|
|
1780
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineSpeakerDiarizationResult *
|
|
1781
|
-
SherpaOnnxOfflineSpeakerDiarizationProcess(
|
|
1782
|
-
const SherpaOnnxOfflineSpeakerDiarization *sd, const float *samples,
|
|
1783
|
-
int32_t n);
|
|
1784
|
-
|
|
1785
|
-
// The user has to invoke SherpaOnnxOfflineSpeakerDiarizationDestroyResult()
|
|
1786
|
-
// to free the returned pointer to avoid memory leak.
|
|
1787
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineSpeakerDiarizationResult *
|
|
1788
|
-
SherpaOnnxOfflineSpeakerDiarizationProcessWithCallback(
|
|
1789
|
-
const SherpaOnnxOfflineSpeakerDiarization *sd, const float *samples,
|
|
1790
|
-
int32_t n, SherpaOnnxOfflineSpeakerDiarizationProgressCallback callback,
|
|
1791
|
-
void *arg);
|
|
1792
|
-
|
|
1793
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineSpeakerDiarizationResult *
|
|
1794
|
-
SherpaOnnxOfflineSpeakerDiarizationProcessWithCallbackNoArg(
|
|
1795
|
-
const SherpaOnnxOfflineSpeakerDiarization *sd, const float *samples,
|
|
1796
|
-
int32_t n,
|
|
1797
|
-
SherpaOnnxOfflineSpeakerDiarizationProgressCallbackNoArg callback);
|
|
1798
|
-
|
|
1799
|
-
SHERPA_ONNX_API void SherpaOnnxOfflineSpeakerDiarizationDestroyResult(
|
|
1800
|
-
const SherpaOnnxOfflineSpeakerDiarizationResult *r);
|
|
1801
|
-
|
|
1802
|
-
// =========================================================================
|
|
1803
|
-
// For offline speech enhancement
|
|
1804
|
-
// =========================================================================
|
|
1805
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineSpeechDenoiserGtcrnModelConfig {
|
|
1806
|
-
const char *model;
|
|
1807
|
-
} SherpaOnnxOfflineSpeechDenoiserGtcrnModelConfig;
|
|
1808
|
-
|
|
1809
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineSpeechDenoiserModelConfig {
|
|
1810
|
-
SherpaOnnxOfflineSpeechDenoiserGtcrnModelConfig gtcrn;
|
|
1811
|
-
int32_t num_threads;
|
|
1812
|
-
int32_t debug; // true to print debug information of the model
|
|
1813
|
-
const char *provider;
|
|
1814
|
-
} SherpaOnnxOfflineSpeechDenoiserModelConfig;
|
|
1815
|
-
|
|
1816
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineSpeechDenoiserConfig {
|
|
1817
|
-
SherpaOnnxOfflineSpeechDenoiserModelConfig model;
|
|
1818
|
-
} SherpaOnnxOfflineSpeechDenoiserConfig;
|
|
1819
|
-
|
|
1820
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineSpeechDenoiser
|
|
1821
|
-
SherpaOnnxOfflineSpeechDenoiser;
|
|
1822
|
-
|
|
1823
|
-
// The users has to invoke SherpaOnnxDestroyOfflineSpeechDenoiser()
|
|
1824
|
-
// to free the returned pointer to avoid memory leak
|
|
1825
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineSpeechDenoiser *
|
|
1826
|
-
SherpaOnnxCreateOfflineSpeechDenoiser(
|
|
1827
|
-
const SherpaOnnxOfflineSpeechDenoiserConfig *config);
|
|
1828
|
-
|
|
1829
|
-
// Free the pointer returned by SherpaOnnxCreateOfflineSpeechDenoiser()
|
|
1830
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyOfflineSpeechDenoiser(
|
|
1831
|
-
const SherpaOnnxOfflineSpeechDenoiser *sd);
|
|
1832
|
-
|
|
1833
|
-
SHERPA_ONNX_API int32_t SherpaOnnxOfflineSpeechDenoiserGetSampleRate(
|
|
1834
|
-
const SherpaOnnxOfflineSpeechDenoiser *sd);
|
|
1835
|
-
|
|
1836
|
-
SHERPA_ONNX_API typedef struct SherpaOnnxDenoisedAudio {
|
|
1837
|
-
const float *samples; // in the range [-1, 1]
|
|
1838
|
-
int32_t n; // number of samples
|
|
1839
|
-
int32_t sample_rate;
|
|
1840
|
-
} SherpaOnnxDenoisedAudio;
|
|
1841
|
-
|
|
1842
|
-
// Run speech denosing on input samples
|
|
1843
|
-
// @param samples A 1-D array containing the input audio samples. Each sample
|
|
1844
|
-
// should be in the range [-1, 1].
|
|
1845
|
-
// @param n Number of samples
|
|
1846
|
-
// @param sample_rate Sample rate of the input samples
|
|
1847
|
-
//
|
|
1848
|
-
// The user MUST use SherpaOnnxDestroyDenoisedAudio() to free the returned
|
|
1849
|
-
// pointer to avoid memory leak.
|
|
1850
|
-
SHERPA_ONNX_API const SherpaOnnxDenoisedAudio *
|
|
1851
|
-
SherpaOnnxOfflineSpeechDenoiserRun(const SherpaOnnxOfflineSpeechDenoiser *sd,
|
|
1852
|
-
const float *samples, int32_t n,
|
|
1853
|
-
int32_t sample_rate);
|
|
1854
|
-
|
|
1855
|
-
SHERPA_ONNX_API void SherpaOnnxDestroyDenoisedAudio(
|
|
1856
|
-
const SherpaOnnxDenoisedAudio *p);
|
|
1857
|
-
|
|
1858
|
-
#ifdef __OHOS__
|
|
1859
|
-
|
|
1860
|
-
// It is for HarmonyOS
|
|
1861
|
-
typedef struct NativeResourceManager NativeResourceManager;
|
|
1862
|
-
|
|
1863
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineSpeechDenoiser *
|
|
1864
|
-
SherpaOnnxCreateOfflineSpeechDenoiserOHOS(
|
|
1865
|
-
const SherpaOnnxOfflineSpeechDenoiserConfig *config,
|
|
1866
|
-
NativeResourceManager *mgr);
|
|
1867
|
-
|
|
1868
|
-
/// @param config Config for the recognizer.
|
|
1869
|
-
/// @return Return a pointer to the recognizer. The user has to invoke
|
|
1870
|
-
// SherpaOnnxDestroyOnlineRecognizer() to free it to avoid memory leak.
|
|
1871
|
-
SHERPA_ONNX_API const SherpaOnnxOnlineRecognizer *
|
|
1872
|
-
SherpaOnnxCreateOnlineRecognizerOHOS(
|
|
1873
|
-
const SherpaOnnxOnlineRecognizerConfig *config, NativeResourceManager *mgr);
|
|
1874
|
-
|
|
1875
|
-
/// @param config Config for the recognizer.
|
|
1876
|
-
/// @return Return a pointer to the recognizer. The user has to invoke
|
|
1877
|
-
// SherpaOnnxDestroyOfflineRecognizer() to free it to avoid memory
|
|
1878
|
-
// leak.
|
|
1879
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineRecognizer *
|
|
1880
|
-
SherpaOnnxCreateOfflineRecognizerOHOS(
|
|
1881
|
-
const SherpaOnnxOfflineRecognizerConfig *config,
|
|
1882
|
-
NativeResourceManager *mgr);
|
|
1883
|
-
|
|
1884
|
-
// Return an instance of VoiceActivityDetector.
|
|
1885
|
-
// The user has to use SherpaOnnxDestroyVoiceActivityDetector() to free
|
|
1886
|
-
// the returned pointer to avoid memory leak.
|
|
1887
|
-
SHERPA_ONNX_API const SherpaOnnxVoiceActivityDetector *
|
|
1888
|
-
SherpaOnnxCreateVoiceActivityDetectorOHOS(
|
|
1889
|
-
const SherpaOnnxVadModelConfig *config, float buffer_size_in_seconds,
|
|
1890
|
-
NativeResourceManager *mgr);
|
|
1891
|
-
|
|
1892
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineTts *SherpaOnnxCreateOfflineTtsOHOS(
|
|
1893
|
-
const SherpaOnnxOfflineTtsConfig *config, NativeResourceManager *mgr);
|
|
1894
|
-
|
|
1895
|
-
SHERPA_ONNX_API const SherpaOnnxSpeakerEmbeddingExtractor *
|
|
1896
|
-
SherpaOnnxCreateSpeakerEmbeddingExtractorOHOS(
|
|
1897
|
-
const SherpaOnnxSpeakerEmbeddingExtractorConfig *config,
|
|
1898
|
-
NativeResourceManager *mgr);
|
|
1899
|
-
|
|
1900
|
-
SHERPA_ONNX_API const SherpaOnnxKeywordSpotter *
|
|
1901
|
-
SherpaOnnxCreateKeywordSpotterOHOS(const SherpaOnnxKeywordSpotterConfig *config,
|
|
1902
|
-
NativeResourceManager *mgr);
|
|
1903
|
-
|
|
1904
|
-
SHERPA_ONNX_API const SherpaOnnxOfflineSpeakerDiarization *
|
|
1905
|
-
SherpaOnnxCreateOfflineSpeakerDiarizationOHOS(
|
|
1906
|
-
const SherpaOnnxOfflineSpeakerDiarizationConfig *config,
|
|
1907
|
-
NativeResourceManager *mgr);
|
|
1908
|
-
#endif
|
|
1909
|
-
|
|
1910
|
-
#if defined(__GNUC__)
|
|
1911
|
-
#pragma GCC diagnostic pop
|
|
1912
|
-
#endif
|
|
1913
|
-
|
|
1914
|
-
#ifdef __cplusplus
|
|
1915
|
-
} /* extern "C" */
|
|
1916
|
-
#endif
|
|
1917
|
-
|
|
1918
|
-
#endif // SHERPA_ONNX_C_API_C_API_H_
|