Fix CI errors introduced by supporting loading keywords from buffers (#1366)
This commit is contained in:
@@ -19,11 +19,13 @@ class KeywordSpotterConfig {
|
|||||||
this.keywordsScore = 1.0,
|
this.keywordsScore = 1.0,
|
||||||
this.keywordsThreshold = 0.25,
|
this.keywordsThreshold = 0.25,
|
||||||
this.keywordsFile = '',
|
this.keywordsFile = '',
|
||||||
|
this.keywordsBuf = '',
|
||||||
|
this.keywordsBufSize = 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'KeywordSpotterConfig(feat: $feat, model: $model, maxActivePaths: $maxActivePaths, numTrailingBlanks: $numTrailingBlanks, keywordsScore: $keywordsScore, keywordsThreshold: $keywordsThreshold, keywordsFile: $keywordsFile)';
|
return 'KeywordSpotterConfig(feat: $feat, model: $model, maxActivePaths: $maxActivePaths, numTrailingBlanks: $numTrailingBlanks, keywordsScore: $keywordsScore, keywordsThreshold: $keywordsThreshold, keywordsFile: $keywordsFile, keywordsBuf: $keywordsBuf, keywordsBufSize: $keywordsBufSize)';
|
||||||
}
|
}
|
||||||
|
|
||||||
final FeatureConfig feat;
|
final FeatureConfig feat;
|
||||||
@@ -35,6 +37,8 @@ class KeywordSpotterConfig {
|
|||||||
final double keywordsScore;
|
final double keywordsScore;
|
||||||
final double keywordsThreshold;
|
final double keywordsThreshold;
|
||||||
final String keywordsFile;
|
final String keywordsFile;
|
||||||
|
final String keywordsBuf;
|
||||||
|
final int keywordsBufSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
class KeywordResult {
|
class KeywordResult {
|
||||||
@@ -89,9 +93,12 @@ class KeywordSpotter {
|
|||||||
c.ref.keywordsScore = config.keywordsScore;
|
c.ref.keywordsScore = config.keywordsScore;
|
||||||
c.ref.keywordsThreshold = config.keywordsThreshold;
|
c.ref.keywordsThreshold = config.keywordsThreshold;
|
||||||
c.ref.keywordsFile = config.keywordsFile.toNativeUtf8();
|
c.ref.keywordsFile = config.keywordsFile.toNativeUtf8();
|
||||||
|
c.ref.keywordsBuf = config.keywordsBuf.toNativeUtf8();
|
||||||
|
c.ref.keywordsBufSize = config.keywordsBufSize;
|
||||||
|
|
||||||
final ptr = SherpaOnnxBindings.createKeywordSpotter?.call(c) ?? nullptr;
|
final ptr = SherpaOnnxBindings.createKeywordSpotter?.call(c) ?? nullptr;
|
||||||
|
|
||||||
|
calloc.free(c.ref.keywordsBuf);
|
||||||
calloc.free(c.ref.keywordsFile);
|
calloc.free(c.ref.keywordsFile);
|
||||||
calloc.free(c.ref.model.bpeVocab);
|
calloc.free(c.ref.model.bpeVocab);
|
||||||
calloc.free(c.ref.model.modelingUnit);
|
calloc.free(c.ref.model.modelingUnit);
|
||||||
|
|||||||
@@ -371,6 +371,11 @@ final class SherpaOnnxKeywordSpotterConfig extends Struct {
|
|||||||
external double keywordsThreshold;
|
external double keywordsThreshold;
|
||||||
|
|
||||||
external Pointer<Utf8> keywordsFile;
|
external Pointer<Utf8> keywordsFile;
|
||||||
|
|
||||||
|
external Pointer<Utf8> keywordsBuf;
|
||||||
|
|
||||||
|
@Int32()
|
||||||
|
external int keywordsBufSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
final class SherpaOnnxOfflinePunctuation extends Opaque {}
|
final class SherpaOnnxOfflinePunctuation extends Opaque {}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ namespace SherpaOnnx
|
|||||||
KeywordsScore = 1.0F;
|
KeywordsScore = 1.0F;
|
||||||
KeywordsThreshold = 0.25F;
|
KeywordsThreshold = 0.25F;
|
||||||
KeywordsFile = "";
|
KeywordsFile = "";
|
||||||
|
KeywordsBuf= "";
|
||||||
|
KeywordsBufSize= 0;
|
||||||
}
|
}
|
||||||
public FeatureConfig FeatConfig;
|
public FeatureConfig FeatConfig;
|
||||||
public OnlineModelConfig ModelConfig;
|
public OnlineModelConfig ModelConfig;
|
||||||
@@ -28,5 +30,10 @@ namespace SherpaOnnx
|
|||||||
|
|
||||||
[MarshalAs(UnmanagedType.LPStr)]
|
[MarshalAs(UnmanagedType.LPStr)]
|
||||||
public string KeywordsFile;
|
public string KeywordsFile;
|
||||||
|
|
||||||
|
[MarshalAs(UnmanagedType.LPStr)]
|
||||||
|
public string KeywordsBuf;
|
||||||
|
|
||||||
|
public int KeywordsBufSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
package sherpa_onnx
|
package sherpa_onnx
|
||||||
|
|
||||||
// #cgo LDFLAGS: -L ${SRCDIR}/lib/aarch64-unknown-linux-gnu -lsherpa-onnx-c-api -lsherpa-onnx-core -lkaldi-native-fbank-core -lkaldi-decoder-core -lsherpa-onnx-kaldifst-core -lsherpa-onnx-fstfar -lsherpa-onnx-fst -lpiper_phonemize -lespeak-ng -lucd -lonnxruntime -lssentencepiece_core -Wl,-rpath,${SRCDIR}/lib/aarch64-unknown-linux-gnu
|
// #cgo LDFLAGS: -L ${SRCDIR}/lib/aarch64-unknown-linux-gnu -lsherpa-onnx-c-api -lonnxruntime -Wl,-rpath,${SRCDIR}/lib/aarch64-unknown-linux-gnu
|
||||||
import "C"
|
import "C"
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ static Napi::External<SherpaOnnxKeywordSpotter> CreateKeywordSpotterWrapper(
|
|||||||
SHERPA_ONNX_ASSIGN_ATTR_FLOAT(keywords_score, keywordsScore);
|
SHERPA_ONNX_ASSIGN_ATTR_FLOAT(keywords_score, keywordsScore);
|
||||||
SHERPA_ONNX_ASSIGN_ATTR_FLOAT(keywords_threshold, keywordsThreshold);
|
SHERPA_ONNX_ASSIGN_ATTR_FLOAT(keywords_threshold, keywordsThreshold);
|
||||||
SHERPA_ONNX_ASSIGN_ATTR_STR(keywords_file, keywordsFile);
|
SHERPA_ONNX_ASSIGN_ATTR_STR(keywords_file, keywordsFile);
|
||||||
|
SHERPA_ONNX_ASSIGN_ATTR_STR(keywords_buf, keywordsBuf);
|
||||||
|
SHERPA_ONNX_ASSIGN_ATTR_INT32(keywords_buf_size, keywordsBufSize);
|
||||||
|
|
||||||
SherpaOnnxKeywordSpotter *kws = SherpaOnnxCreateKeywordSpotter(&c);
|
SherpaOnnxKeywordSpotter *kws = SherpaOnnxCreateKeywordSpotter(&c);
|
||||||
|
|
||||||
@@ -86,6 +88,10 @@ static Napi::External<SherpaOnnxKeywordSpotter> CreateKeywordSpotterWrapper(
|
|||||||
delete[] c.keywords_file;
|
delete[] c.keywords_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c.keywords_buf) {
|
||||||
|
delete[] c.keywords_buf;
|
||||||
|
}
|
||||||
|
|
||||||
if (!kws) {
|
if (!kws) {
|
||||||
Napi::TypeError::New(env, "Please check your config!")
|
Napi::TypeError::New(env, "Please check your config!")
|
||||||
.ThrowAsJavaScriptException();
|
.ThrowAsJavaScriptException();
|
||||||
|
|||||||
@@ -966,7 +966,9 @@ func sherpaOnnxKeywordSpotterConfig(
|
|||||||
maxActivePaths: Int = 4,
|
maxActivePaths: Int = 4,
|
||||||
numTrailingBlanks: Int = 1,
|
numTrailingBlanks: Int = 1,
|
||||||
keywordsScore: Float = 1.0,
|
keywordsScore: Float = 1.0,
|
||||||
keywordsThreshold: Float = 0.25
|
keywordsThreshold: Float = 0.25,
|
||||||
|
keywordsBuf: String = "",
|
||||||
|
keywordsBufSize: Int = 0
|
||||||
) -> SherpaOnnxKeywordSpotterConfig {
|
) -> SherpaOnnxKeywordSpotterConfig {
|
||||||
return SherpaOnnxKeywordSpotterConfig(
|
return SherpaOnnxKeywordSpotterConfig(
|
||||||
feat_config: featConfig,
|
feat_config: featConfig,
|
||||||
@@ -975,7 +977,9 @@ func sherpaOnnxKeywordSpotterConfig(
|
|||||||
num_trailing_blanks: Int32(numTrailingBlanks),
|
num_trailing_blanks: Int32(numTrailingBlanks),
|
||||||
keywords_score: keywordsScore,
|
keywords_score: keywordsScore,
|
||||||
keywords_threshold: keywordsThreshold,
|
keywords_threshold: keywordsThreshold,
|
||||||
keywords_file: toCPointer(keywordsFile)
|
keywords_file: toCPointer(keywordsFile),
|
||||||
|
keywords_buf: toCPointer(keywordsBuf),
|
||||||
|
keywords_buf_size: Int32(keywordsBufSize)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -172,10 +172,18 @@ function initKwsConfig(config, Module) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!('keywordsBuf' in config)) {
|
||||||
|
config.keywordsBuf = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!('keywordsBufSize' in config)) {
|
||||||
|
config.keywordsBufSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
let featConfig = initFeatureExtractorConfig(config.featConfig, Module);
|
let featConfig = initFeatureExtractorConfig(config.featConfig, Module);
|
||||||
|
|
||||||
let modelConfig = initModelConfig(config.modelConfig, Module);
|
let modelConfig = initModelConfig(config.modelConfig, Module);
|
||||||
let numBytes = featConfig.len + modelConfig.len + 4 * 5;
|
let numBytes = featConfig.len + modelConfig.len + 4 * 7;
|
||||||
|
|
||||||
let ptr = Module._malloc(numBytes);
|
let ptr = Module._malloc(numBytes);
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
@@ -198,11 +206,22 @@ function initKwsConfig(config, Module) {
|
|||||||
offset += 4;
|
offset += 4;
|
||||||
|
|
||||||
let keywordsLen = Module.lengthBytesUTF8(config.keywords) + 1;
|
let keywordsLen = Module.lengthBytesUTF8(config.keywords) + 1;
|
||||||
let keywordsBuffer = Module._malloc(keywordsLen);
|
let keywordsBufLen = Module.lengthBytesUTF8(config.keywordsBuf) + 1;
|
||||||
|
|
||||||
|
let keywordsBuffer = Module._malloc(keywordsLen + keywordsBufLen);
|
||||||
Module.stringToUTF8(config.keywords, keywordsBuffer, keywordsLen);
|
Module.stringToUTF8(config.keywords, keywordsBuffer, keywordsLen);
|
||||||
|
Module.stringToUTF8(
|
||||||
|
config.keywordsBuf, keywordsBuffer + keywordsLen, keywordsBufLen);
|
||||||
|
|
||||||
Module.setValue(ptr + offset, keywordsBuffer, 'i8*');
|
Module.setValue(ptr + offset, keywordsBuffer, 'i8*');
|
||||||
offset += 4;
|
offset += 4;
|
||||||
|
|
||||||
|
Module.setValue(ptr + offset, keywordsBuffer + keywordsLen, 'i8*');
|
||||||
|
offset += 4;
|
||||||
|
|
||||||
|
Module.setValue(ptr + offset, config.keywordsBufLen, 'i32');
|
||||||
|
offset += 4;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ptr: ptr, len: numBytes, featConfig: featConfig, modelConfig: modelConfig,
|
ptr: ptr, len: numBytes, featConfig: featConfig, modelConfig: modelConfig,
|
||||||
keywordsBuffer: keywordsBuffer
|
keywordsBuffer: keywordsBuffer
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ static_assert(sizeof(SherpaOnnxOnlineModelConfig) ==
|
|||||||
static_assert(sizeof(SherpaOnnxFeatureConfig) == 2 * 4, "");
|
static_assert(sizeof(SherpaOnnxFeatureConfig) == 2 * 4, "");
|
||||||
static_assert(sizeof(SherpaOnnxKeywordSpotterConfig) ==
|
static_assert(sizeof(SherpaOnnxKeywordSpotterConfig) ==
|
||||||
sizeof(SherpaOnnxFeatureConfig) +
|
sizeof(SherpaOnnxFeatureConfig) +
|
||||||
sizeof(SherpaOnnxOnlineModelConfig) + 5 * 4,
|
sizeof(SherpaOnnxOnlineModelConfig) + 7 * 4,
|
||||||
"");
|
"");
|
||||||
|
|
||||||
void CopyHeap(const char *src, int32_t num_bytes, char *dst) {
|
void CopyHeap(const char *src, int32_t num_bytes, char *dst) {
|
||||||
|
|||||||
Reference in New Issue
Block a user