Skip to content

Commit

Permalink
Add blank penalty for various language bindings. (#1234)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Aug 8, 2024
1 parent ba4cb61 commit 94e2562
Show file tree
Hide file tree
Showing 38 changed files with 123 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@ sherpa-onnx-telespeech-ctc-*
lib*.a
sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17
*.bak
vits-melo-tts-zh_en
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## 1.10.21

* Fix ffmpeg c api example (#1185)
* Fix splitting sentences for MeloTTS (#1186)
* Non-streaming WebSocket client for Java. (#1190)
* Fix copying asset files for flutter examples. (#1191)
* Add Chinese+English tts example for flutter (#1192)
* Add speaker identification and verification exmaple for Dart API (#1194)
* Fix reading non-standard wav files. (#1199)
* Add ReazonSpeech Japanese pre-trained model (#1203)
* Describe how to add new words for MeloTTS models (#1209)
* Remove libonnxruntime_providers_cuda.so as a dependency. (#1210)
* Fix setting SenseVoice language. (#1214)
* Support passing TTS callback in Swift API (#1218)
* Add MeloTTS example for ios (#1223)
* Add online punctuation and casing prediction model for English language (#1224)
* Fix python two pass ASR examples (#1230)
* Add blank penalty for various language bindings

## 1.10.20

* Add Dart API for audio tagging
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ project(sherpa-onnx)
# ./nodejs-addon-examples
# ./dart-api-examples/
# ./CHANGELOG.md
set(SHERPA_ONNX_VERSION "1.10.20")
set(SHERPA_ONNX_VERSION "1.10.21")

# Disable warning about
#
Expand Down
4 changes: 3 additions & 1 deletion build-ios-no-tts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ echo "Generate xcframework"

mkdir -p "build/simulator/lib"
for f in libkaldi-native-fbank-core.a libsherpa-onnx-c-api.a libsherpa-onnx-core.a \
libsherpa-onnx-fst.a libsherpa-onnx-kaldifst-core.a libkaldi-decoder-core.a libssentencepiece_core.a; do
libsherpa-onnx-fst.a libsherpa-onnx-fstfar.a libsherpa-onnx-kaldifst-core.a libkaldi-decoder-core.a libssentencepiece_core.a; do
lipo -create build/simulator_arm64/lib/${f} \
build/simulator_x86_64/lib/${f} \
-output build/simulator/lib/${f}
Expand All @@ -139,6 +139,7 @@ libtool -static -o build/simulator/sherpa-onnx.a \
build/simulator/lib/libsherpa-onnx-c-api.a \
build/simulator/lib/libsherpa-onnx-core.a \
build/simulator/lib/libsherpa-onnx-fst.a \
build/simulator/lib/libsherpa-onnx-fstfar.a \
build/simulator/lib/libsherpa-onnx-kaldifst-core.a \
build/simulator/lib/libkaldi-decoder-core.a \
build/simulator/lib/libssentencepiece_core.a
Expand All @@ -148,6 +149,7 @@ libtool -static -o build/os64/sherpa-onnx.a \
build/os64/lib/libsherpa-onnx-c-api.a \
build/os64/lib/libsherpa-onnx-core.a \
build/os64/lib/libsherpa-onnx-fst.a \
build/os64/lib/libsherpa-onnx-fstfar.a \
build/os64/lib/libsherpa-onnx-kaldifst-core.a \
build/os64/lib/libkaldi-decoder-core.a \
build/os64/lib/libssentencepiece_core.a
Expand Down
2 changes: 1 addition & 1 deletion dart-api-examples/add-punctuations/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
sdk: ^3.4.0

dependencies:
sherpa_onnx: ^1.10.20
sherpa_onnx: ^1.10.21
path: ^1.9.0
args: ^2.5.0

Expand Down
2 changes: 1 addition & 1 deletion dart-api-examples/audio-tagging/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
sdk: ^3.4.0

dependencies:
sherpa_onnx: ^1.10.20
sherpa_onnx: ^1.10.21
path: ^1.9.0
args: ^2.5.0

Expand Down
2 changes: 1 addition & 1 deletion dart-api-examples/keyword-spotter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
sdk: ^3.4.0

dependencies:
sherpa_onnx: ^1.10.20
sherpa_onnx: ^1.10.21
# sherpa_onnx:
# path: ../../flutter/sherpa_onnx
path: ^1.9.0
Expand Down
2 changes: 1 addition & 1 deletion dart-api-examples/non-streaming-asr/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:

# Add regular dependencies here.
dependencies:
sherpa_onnx: ^1.10.20
sherpa_onnx: ^1.10.21
path: ^1.9.0
args: ^2.5.0

Expand Down
2 changes: 1 addition & 1 deletion dart-api-examples/speaker-identification/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
sdk: ^3.4.0

dependencies:
sherpa_onnx: ^1.10.20
sherpa_onnx: ^1.10.21
path: ^1.9.0
args: ^2.5.0

Expand Down
2 changes: 1 addition & 1 deletion dart-api-examples/streaming-asr/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ environment:

# Add regular dependencies here.
dependencies:
sherpa_onnx: ^1.10.20
sherpa_onnx: ^1.10.21
path: ^1.9.0
args: ^2.5.0

Expand Down
2 changes: 1 addition & 1 deletion dart-api-examples/tts/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ environment:

# Add regular dependencies here.
dependencies:
sherpa_onnx: ^1.10.20
sherpa_onnx: ^1.10.21
path: ^1.9.0
args: ^2.5.0

Expand Down
2 changes: 1 addition & 1 deletion dart-api-examples/vad-with-non-streaming-asr/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:
sdk: ^3.4.0

dependencies:
sherpa_onnx: ^1.10.20
sherpa_onnx: ^1.10.21
path: ^1.9.0
args: ^2.5.0

Expand Down
2 changes: 1 addition & 1 deletion dart-api-examples/vad/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
sdk: ^3.4.0

dependencies:
sherpa_onnx: ^1.10.20
sherpa_onnx: ^1.10.21
path: ^1.9.0
args: ^2.5.0

Expand Down
4 changes: 2 additions & 2 deletions flutter-examples/streaming_asr/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >
publish_to: 'none'

version: 1.10.20
version: 1.10.21

topics:
- speech-recognition
Expand All @@ -30,7 +30,7 @@ dependencies:
record: ^5.1.0
url_launcher: ^6.2.6

sherpa_onnx: ^1.10.20
sherpa_onnx: ^1.10.21
# sherpa_onnx:
# path: ../../flutter/sherpa_onnx

Expand Down
4 changes: 2 additions & 2 deletions flutter-examples/tts/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.10.20
version: 1.10.21

environment:
sdk: '>=3.4.0 <4.0.0'
Expand All @@ -17,7 +17,7 @@ dependencies:
cupertino_icons: ^1.0.6
path_provider: ^2.1.3
path: ^1.9.0
sherpa_onnx: ^1.10.20
sherpa_onnx: ^1.10.21
url_launcher: ^6.2.6
audioplayers: ^5.0.0

Expand Down
7 changes: 6 additions & 1 deletion flutter/sherpa_onnx/lib/src/offline_recognizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ class OfflineRecognizerConfig {
this.hotwordsScore = 1.5,
this.ruleFsts = '',
this.ruleFars = '',
this.blankPenalty = 0.0,
});

@override
String toString() {
return 'OfflineRecognizerConfig(feat: $feat, model: $model, lm: $lm, decodingMethod: $decodingMethod, maxActivePaths: $maxActivePaths, hotwordsFile: $hotwordsFile, hotwordsScore: $hotwordsScore, ruleFsts: $ruleFsts, ruleFars: $ruleFars)';
return 'OfflineRecognizerConfig(feat: $feat, model: $model, lm: $lm, decodingMethod: $decodingMethod, maxActivePaths: $maxActivePaths, hotwordsFile: $hotwordsFile, hotwordsScore: $hotwordsScore, ruleFsts: $ruleFsts, ruleFars: $ruleFars, blankPenalty: $blankPenalty)';
}

final FeatureConfig feat;
Expand All @@ -179,6 +180,8 @@ class OfflineRecognizerConfig {

final String ruleFsts;
final String ruleFars;

final double blankPenalty;
}

class OfflineRecognizerResult {
Expand Down Expand Up @@ -268,6 +271,8 @@ class OfflineRecognizer {
c.ref.ruleFsts = config.ruleFsts.toNativeUtf8();
c.ref.ruleFars = config.ruleFars.toNativeUtf8();

c.ref.blankPenalty = config.blankPenalty;

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

calloc.free(c.ref.ruleFars);
Expand Down
7 changes: 6 additions & 1 deletion flutter/sherpa_onnx/lib/src/online_recognizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ class OnlineRecognizerConfig {
this.ctcFstDecoderConfig = const OnlineCtcFstDecoderConfig(),
this.ruleFsts = '',
this.ruleFars = '',
this.blankPenalty = 0.0,
});

@override
String toString() {
return 'OnlineRecognizerConfig(feat: $feat, model: $model, decodingMethod: $decodingMethod, maxActivePaths: $maxActivePaths, enableEndpoint: $enableEndpoint, rule1MinTrailingSilence: $rule1MinTrailingSilence, rule2MinTrailingSilence: $rule2MinTrailingSilence, rule3MinUtteranceLength: $rule3MinUtteranceLength, hotwordsFile: $hotwordsFile, hotwordsScore: $hotwordsScore, ctcFstDecoderConfig: $ctcFstDecoderConfig, ruleFsts: $ruleFsts, ruleFars: $ruleFars)';
return 'OnlineRecognizerConfig(feat: $feat, model: $model, decodingMethod: $decodingMethod, maxActivePaths: $maxActivePaths, enableEndpoint: $enableEndpoint, rule1MinTrailingSilence: $rule1MinTrailingSilence, rule2MinTrailingSilence: $rule2MinTrailingSilence, rule3MinUtteranceLength: $rule3MinUtteranceLength, hotwordsFile: $hotwordsFile, hotwordsScore: $hotwordsScore, ctcFstDecoderConfig: $ctcFstDecoderConfig, ruleFsts: $ruleFsts, ruleFars: $ruleFars, blankPenalty: $blankPenalty)';
}

final FeatureConfig feat;
Expand All @@ -142,6 +143,8 @@ class OnlineRecognizerConfig {
final OnlineCtcFstDecoderConfig ctcFstDecoderConfig;
final String ruleFsts;
final String ruleFars;

final double blankPenalty;
}

class OnlineRecognizerResult {
Expand Down Expand Up @@ -209,6 +212,8 @@ class OnlineRecognizer {
c.ref.ruleFsts = config.ruleFsts.toNativeUtf8();
c.ref.ruleFars = config.ruleFars.toNativeUtf8();

c.ref.blankPenalty = config.blankPenalty;

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

calloc.free(c.ref.ruleFars);
Expand Down
6 changes: 6 additions & 0 deletions flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ final class SherpaOnnxOfflineRecognizerConfig extends Struct {

external Pointer<Utf8> ruleFsts;
external Pointer<Utf8> ruleFars;

@Float()
external double blankPenalty;
}

final class SherpaOnnxOnlineTransducerModelConfig extends Struct {
Expand Down Expand Up @@ -269,6 +272,9 @@ final class SherpaOnnxOnlineRecognizerConfig extends Struct {

external Pointer<Utf8> ruleFsts;
external Pointer<Utf8> ruleFars;

@Float()
external double blankPenalty;
}

final class SherpaOnnxSileroVadModelConfig extends Struct {
Expand Down
12 changes: 6 additions & 6 deletions flutter/sherpa_onnx/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ topics:
- voice-activity-detection

# remember to change the version in ../sherpa_onnx_macos/macos/sherpa_onnx_macos.podspec
version: 1.10.20
version: 1.10.21

homepage: https://github.com/k2-fsa/sherpa-onnx

Expand All @@ -30,23 +30,23 @@ dependencies:
flutter:
sdk: flutter

sherpa_onnx_android: ^1.10.20
sherpa_onnx_android: ^1.10.21
# sherpa_onnx_android:
# path: ../sherpa_onnx_android

sherpa_onnx_macos: ^1.10.20
sherpa_onnx_macos: ^1.10.21
# sherpa_onnx_macos:
# path: ../sherpa_onnx_macos

sherpa_onnx_linux: ^1.10.20
sherpa_onnx_linux: ^1.10.21
# sherpa_onnx_linux:
# path: ../sherpa_onnx_linux
#
sherpa_onnx_windows: ^1.10.20
sherpa_onnx_windows: ^1.10.21
# sherpa_onnx_windows:
# path: ../sherpa_onnx_windows

sherpa_onnx_ios: ^1.10.20
sherpa_onnx_ios: ^1.10.21
# sherpa_onnx_ios:
# path: ../sherpa_onnx_ios

Expand Down
2 changes: 1 addition & 1 deletion flutter/sherpa_onnx_ios/ios/sherpa_onnx_ios.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# https://groups.google.com/g/dart-ffi/c/nUATMBy7r0c
Pod::Spec.new do |s|
s.name = 'sherpa_onnx_ios'
s.version = '1.10.20'
s.version = '1.10.21'
s.summary = 'A new Flutter FFI plugin project.'
s.description = <<-DESC
A new Flutter FFI plugin project.
Expand Down
2 changes: 1 addition & 1 deletion flutter/sherpa_onnx_macos/macos/sherpa_onnx_macos.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'sherpa_onnx_macos'
s.version = '1.10.20'
s.version = '1.10.21'
s.summary = 'sherpa-onnx Flutter FFI plugin project.'
s.description = <<-DESC
sherpa-onnx Flutter FFI plugin project.
Expand Down
2 changes: 1 addition & 1 deletion nodejs-addon-examples/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"dependencies": {
"sherpa-onnx-node": "^1.10.20"
"sherpa-onnx-node": "^1.10.21"
}
}
8 changes: 4 additions & 4 deletions scripts/dotnet/OfflineRecognizerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace SherpaOnnx
{

[StructLayout(LayoutKind.Sequential)]
public struct OfflineRecognizerConfig
{
Expand All @@ -20,6 +19,7 @@ public OfflineRecognizerConfig()
HotwordsScore = 1.5F;
RuleFsts = "";
RuleFars = "";
BlankPenalty = 0.0F;
}
public FeatureConfig FeatConfig;
public OfflineModelConfig ModelConfig;
Expand All @@ -40,7 +40,7 @@ public OfflineRecognizerConfig()

[MarshalAs(UnmanagedType.LPStr)]
public string RuleFars;
}


}
public float BlankPenalty;
}
}
6 changes: 4 additions & 2 deletions scripts/dotnet/OnlineRecognizerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public OnlineRecognizerConfig()
CtcFstDecoderConfig = new OnlineCtcFstDecoderConfig();
RuleFsts = "";
RuleFars = "";
BlankPenalty = 0.0F;
}
public FeatureConfig FeatConfig;
public OnlineModelConfig ModelConfig;
Expand Down Expand Up @@ -69,6 +70,7 @@ public OnlineRecognizerConfig()

[MarshalAs(UnmanagedType.LPStr)]
public string RuleFars;
}

}
public float BlankPenalty;
}
}
1 change: 1 addition & 0 deletions scripts/node-addon-api/src/non-streaming-asr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ CreateOfflineRecognizerWrapper(const Napi::CallbackInfo &info) {
SHERPA_ONNX_ASSIGN_ATTR_FLOAT(hotwords_score, hotwordsScore);
SHERPA_ONNX_ASSIGN_ATTR_STR(rule_fsts, ruleFsts);
SHERPA_ONNX_ASSIGN_ATTR_STR(rule_fars, ruleFars);
SHERPA_ONNX_ASSIGN_ATTR_FLOAT(blank_penalty, blankPenalty);

SherpaOnnxOfflineRecognizer *recognizer =
SherpaOnnxCreateOfflineRecognizer(&c);
Expand Down
1 change: 1 addition & 0 deletions scripts/node-addon-api/src/streaming-asr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ static Napi::External<SherpaOnnxOnlineRecognizer> CreateOnlineRecognizerWrapper(
SHERPA_ONNX_ASSIGN_ATTR_FLOAT(hotwords_score, hotwordsScore);
SHERPA_ONNX_ASSIGN_ATTR_STR(rule_fsts, ruleFsts);
SHERPA_ONNX_ASSIGN_ATTR_STR(rule_fars, ruleFars);
SHERPA_ONNX_ASSIGN_ATTR_FLOAT(blank_penalty, blankPenalty);

c.ctc_fst_decoder_config = GetCtcFstDecoderConfig(o);

Expand Down
Loading

0 comments on commit 94e2562

Please sign in to comment.