Skip to content

Commit

Permalink
fix other APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj committed Jun 4, 2024
1 parent 5db884e commit 0cc4948
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum OS X deployment ve

project(sherpa-onnx)

set(SHERPA_ONNX_VERSION "1.9.26")
set(SHERPA_ONNX_VERSION "1.9.27")

# Disable warning about
#
Expand Down
4 changes: 4 additions & 0 deletions scripts/dotnet/OfflineModelConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public OfflineModelConfig()
ModelType = "";
ModelingUnit = "cjkchar";
BpeVocab = "";
TeleSpeechCtc = "";
}
public OfflineTransducerModelConfig Transducer;
public OfflineParaformerModelConfig Paraformer;
Expand All @@ -50,5 +51,8 @@ public OfflineModelConfig()

[MarshalAs(UnmanagedType.LPStr)]
public string BpeVocab;

[MarshalAs(UnmanagedType.LPStr)]
public string TeleSpeechCtc;
}
}
4 changes: 4 additions & 0 deletions scripts/go/sherpa_onnx.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type OnlineModelConfig struct {
ModelType string // Optional. You can specify it for faster model initialization
ModelingUnit string // Optional. cjkchar, bpe, cjkchar+bpe
BpeVocab string // Optional.
TeleSpeechCtc string // Optional.
}

// Configuration for the feature extractor
Expand Down Expand Up @@ -195,6 +196,9 @@ func NewOnlineRecognizer(config *OnlineRecognizerConfig) *OnlineRecognizer {
c.model_config.bpe_vocab = C.CString(config.ModelConfig.BpeVocab)
defer C.free(unsafe.Pointer(c.model_config.bpe_vocab))

c.model_config.telespeech_ctc = C.CString(config.ModelConfig.TeleSpeechCtc)
defer C.free(unsafe.Pointer(c.model_config.telespeech_ctc))

c.decoding_method = C.CString(config.DecodingMethod)
defer C.free(unsafe.Pointer(c.decoding_method))

Expand Down
5 changes: 5 additions & 0 deletions scripts/node-addon-api/src/non-streaming-asr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ static SherpaOnnxOfflineModelConfig GetOfflineModelConfig(Napi::Object obj) {
SHERPA_ONNX_ASSIGN_ATTR_STR(model_type, modelType);
SHERPA_ONNX_ASSIGN_ATTR_STR(modeling_unit, modelingUnit);
SHERPA_ONNX_ASSIGN_ATTR_STR(bpe_vocab, bpeVocab);
SHERPA_ONNX_ASSIGN_ATTR_STR(telespeech_ctc, teleSpeechCtc);

return c;
}
Expand Down Expand Up @@ -242,6 +243,10 @@ CreateOfflineRecognizerWrapper(const Napi::CallbackInfo &info) {
delete[] c.model_config.bpe_vocab;
}

if (c.model_config.telespeech_ctc) {
delete[] c.model_config.telespeech_ctc;
}

if (c.lm_config.model) {
delete[] c.lm_config.model;
}
Expand Down
4 changes: 2 additions & 2 deletions swift-api-examples/SherpaOnnx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func sherpaOnnxOnlineModelConfig(
debug: Int32(debug),
model_type: toCPointer(modelType),
modeling_unit: toCPointer(modelingUnit),
bpeVocab: toCPointer(bpeVocab)
bpe_vocab: toCPointer(bpeVocab)
)
}

Expand Down Expand Up @@ -374,7 +374,7 @@ func sherpaOnnxOfflineModelConfig(
provider: toCPointer(provider),
model_type: toCPointer(modelType),
modeling_unit: toCPointer(modelingUnit),
bpeVocab: toCPointer(bpeVocab)
bpe_vocab: toCPointer(bpeVocab)
)
}

Expand Down
19 changes: 16 additions & 3 deletions wasm/asr/sherpa-onnx-asr.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ function initSherpaOnnxOfflineModelConfig(config, Module) {
const tdnn = initSherpaOnnxOfflineTdnnModelConfig(config.tdnn, Module);

const len = transducer.len + paraformer.len + nemoCtc.len + whisper.len +
tdnn.len + 7 * 4;
tdnn.len + 8 * 4;
const ptr = Module._malloc(len);

let offset = 0;
Expand All @@ -553,9 +553,11 @@ function initSherpaOnnxOfflineModelConfig(config, Module) {
const modelTypeLen = Module.lengthBytesUTF8(config.modelType) + 1;
const modelingUnitLen = Module.lengthBytesUTF8(config.modelingUnit || '') + 1;
const bpeVocabLen = Module.lengthBytesUTF8(config.bpeVocab || '') + 1;
const teleSpeechCtcLen =
Module.lengthBytesUTF8(config.teleSpeechCtc || '') + 1;

const bufferLen =
tokensLen + providerLen + modelTypeLen + modelingUnitLen + bpeVocabLen;
const bufferLen = tokensLen + providerLen + modelTypeLen + modelingUnitLen +
bpeVocabLen + teleSpeechCtcLen;
const buffer = Module._malloc(bufferLen);

offset = 0;
Expand All @@ -575,6 +577,10 @@ function initSherpaOnnxOfflineModelConfig(config, Module) {
Module.stringToUTF8(config.bpeVocab || '', buffer + offset, bpeVocabLen);
offset += bpeVocabLen;

Module.stringToUTF8(
config.teleSpeechCtc || '', buffer + offset, teleSpeechCtcLen);
offset += teleSpeechCtcLen;

offset =
transducer.len + paraformer.len + nemoCtc.len + whisper.len + tdnn.len;
Module.setValue(ptr + offset, buffer, 'i8*'); // tokens
Expand Down Expand Up @@ -604,6 +610,13 @@ function initSherpaOnnxOfflineModelConfig(config, Module) {
'i8*'); // bpeVocab
offset += 4;

Module.setValue(
ptr + offset,
buffer + tokensLen + providerLen + modelTypeLen + modelingUnitLen +
bpeVocabLen,
'i8*'); // teleSpeechCtc
offset += 4;

return {
buffer: buffer, ptr: ptr, len: len, transducer: transducer,
paraformer: paraformer, nemoCtc: nemoCtc, whisper: whisper, tdnn: tdnn
Expand Down
3 changes: 2 additions & 1 deletion wasm/nodejs/sherpa-onnx-wasm-nodejs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static_assert(sizeof(SherpaOnnxOfflineModelConfig) ==
sizeof(SherpaOnnxOfflineParaformerModelConfig) +
sizeof(SherpaOnnxOfflineNemoEncDecCtcModelConfig) +
sizeof(SherpaOnnxOfflineWhisperModelConfig) +
sizeof(SherpaOnnxOfflineTdnnModelConfig) + 7 * 4,
sizeof(SherpaOnnxOfflineTdnnModelConfig) + 8 * 4,
"");
static_assert(sizeof(SherpaOnnxFeatureConfig) == 2 * 4, "");
static_assert(sizeof(SherpaOnnxOfflineRecognizerConfig) ==
Expand Down Expand Up @@ -92,6 +92,7 @@ void PrintOfflineRecognizerConfig(SherpaOnnxOfflineRecognizerConfig *config) {
fprintf(stdout, "model type: %s\n", model_config->model_type);
fprintf(stdout, "modeling unit: %s\n", model_config->modeling_unit);
fprintf(stdout, "bpe vocab: %s\n", model_config->bpe_vocab);
fprintf(stdout, "telespeech_ctc: %s\n", model_config->telespeech_ctc);

fprintf(stdout, "----------feat config----------\n");
fprintf(stdout, "sample rate: %d\n", feat->sample_rate);
Expand Down

0 comments on commit 0cc4948

Please sign in to comment.