Skip to content

Commit

Permalink
Fix Dart APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj committed Sep 20, 2024
1 parent 862211c commit f3fdfc2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion flutter/sherpa_onnx/lib/src/keyword_spotter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class KeywordSpotterConfig {
this.keywordsScore = 1.0,
this.keywordsThreshold = 0.25,
this.keywordsFile = '',
this.keywordsBuf = '',
this.keywordsBufSize = 0,
});

@override
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;
Expand All @@ -35,6 +37,8 @@ class KeywordSpotterConfig {
final double keywordsScore;
final double keywordsThreshold;
final String keywordsFile;
final String keywordsBuf;
final int keywordsBufSize;
}

class KeywordResult {
Expand Down Expand Up @@ -89,9 +93,12 @@ class KeywordSpotter {
c.ref.keywordsScore = config.keywordsScore;
c.ref.keywordsThreshold = config.keywordsThreshold;
c.ref.keywordsFile = config.keywordsFile.toNativeUtf8();
c.ref.keywordsBuf = config.keywordsBuf.toNativeUtf8();
c.ref.keywordsBufSize = config.keywordsBufSize;

final ptr = SherpaOnnxBindings.createKeywordSpotter?.call(c) ?? nullptr;

calloc.free(c.ref.keywordsBuf);
calloc.free(c.ref.keywordsFile);
calloc.free(c.ref.model.bpeVocab);
calloc.free(c.ref.model.modelingUnit);
Expand Down
5 changes: 5 additions & 0 deletions flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ final class SherpaOnnxKeywordSpotterConfig extends Struct {
external double keywordsThreshold;

external Pointer<Utf8> keywordsFile;

external Pointer<Utf8> keywordsBuf;

@Int32()
external int keywordsBufSize;
}

final class SherpaOnnxOfflinePunctuation extends Opaque {}
Expand Down

0 comments on commit f3fdfc2

Please sign in to comment.