Add Dart API for homophone replacer (#2167)
This commit is contained in:
@@ -5,6 +5,7 @@ import 'dart:ffi';
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
import './feature_config.dart';
|
||||
import './homophone_replacer_config.dart';
|
||||
import './offline_stream.dart';
|
||||
import './sherpa_onnx_bindings.dart';
|
||||
import './utils.dart';
|
||||
@@ -403,6 +404,7 @@ class OfflineRecognizerConfig {
|
||||
this.ruleFsts = '',
|
||||
this.ruleFars = '',
|
||||
this.blankPenalty = 0.0,
|
||||
this.hr = const HomophoneReplacerConfig(),
|
||||
});
|
||||
|
||||
factory OfflineRecognizerConfig.fromJson(Map<String, dynamic> json) {
|
||||
@@ -421,12 +423,13 @@ class OfflineRecognizerConfig {
|
||||
ruleFsts: json['ruleFsts'] as String? ?? '',
|
||||
ruleFars: json['ruleFars'] as String? ?? '',
|
||||
blankPenalty: (json['blankPenalty'] as num?)?.toDouble() ?? 0.0,
|
||||
hr: HomophoneReplacerConfig.fromJson(json['hr'] as Map<String, dynamic>),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'OfflineRecognizerConfig(feat: $feat, model: $model, lm: $lm, decodingMethod: $decodingMethod, maxActivePaths: $maxActivePaths, hotwordsFile: $hotwordsFile, hotwordsScore: $hotwordsScore, ruleFsts: $ruleFsts, ruleFars: $ruleFars, blankPenalty: $blankPenalty)';
|
||||
return 'OfflineRecognizerConfig(feat: $feat, model: $model, lm: $lm, decodingMethod: $decodingMethod, maxActivePaths: $maxActivePaths, hotwordsFile: $hotwordsFile, hotwordsScore: $hotwordsScore, ruleFsts: $ruleFsts, ruleFars: $ruleFars, blankPenalty: $blankPenalty, hr: $hr)';
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
@@ -440,6 +443,7 @@ class OfflineRecognizerConfig {
|
||||
'ruleFsts': ruleFsts,
|
||||
'ruleFars': ruleFars,
|
||||
'blankPenalty': blankPenalty,
|
||||
'hr': hr.toJson(),
|
||||
};
|
||||
|
||||
final FeatureConfig feat;
|
||||
@@ -457,6 +461,7 @@ class OfflineRecognizerConfig {
|
||||
final String ruleFars;
|
||||
|
||||
final double blankPenalty;
|
||||
final HomophoneReplacerConfig hr;
|
||||
}
|
||||
|
||||
class OfflineRecognizerResult {
|
||||
@@ -598,8 +603,15 @@ class OfflineRecognizer {
|
||||
|
||||
c.ref.blankPenalty = config.blankPenalty;
|
||||
|
||||
c.ref.hr.dictDir = config.hr.dictDir.toNativeUtf8();
|
||||
c.ref.hr.lexicon = config.hr.lexicon.toNativeUtf8();
|
||||
c.ref.hr.ruleFsts = config.hr.ruleFsts.toNativeUtf8();
|
||||
|
||||
final ptr = SherpaOnnxBindings.createOfflineRecognizer?.call(c) ?? nullptr;
|
||||
|
||||
calloc.free(c.ref.hr.dictDir);
|
||||
calloc.free(c.ref.hr.lexicon);
|
||||
calloc.free(c.ref.hr.ruleFsts);
|
||||
calloc.free(c.ref.ruleFars);
|
||||
calloc.free(c.ref.ruleFsts);
|
||||
calloc.free(c.ref.hotwordsFile);
|
||||
|
||||
Reference in New Issue
Block a user