Skip to content

Commit 8a6dec2

Browse files
authored
Fix building for various language bindings after adding zipvoice (#2709)
1 parent ece3183 commit 8a6dec2

17 files changed

+335
-84
lines changed

.github/scripts/test-dot-net.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ rm -rf sherpa-onnx-*
7171
./run-whisper.sh
7272
rm -rf sherpa-onnx-*
7373

74-
./run-whisper-large-v3.sh
75-
rm -rf sherpa-onnx-*
74+
# ./run-whisper-large-v3.sh
75+
# rm -rf sherpa-onnx-*
7676

7777
./run-tdnn-yesno.sh
7878
rm -rf sherpa-onnx-*

.github/workflows/test-dot-net.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ jobs:
112112
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
113113
114114
- name: Free Disk Space (Ubuntu)
115-
if: false
115+
if: true
116116
uses: jlumbroso/free-disk-space@main
117117
with:
118118
# this might remove tools that are actually needed,
@@ -129,7 +129,7 @@ jobs:
129129
swap-storage: true
130130

131131
- name: Check space
132-
if: false
132+
if: true
133133
shell: bash
134134
run: |
135135
df -h

flutter/sherpa_onnx/lib/src/audio_tagging.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,17 @@ class AudioTagging {
157157
final ptr =
158158
SherpaOnnxBindings.sherpaOnnxCreateAudioTagging?.call(c) ?? nullptr;
159159

160-
if (ptr == nullptr) {
161-
throw Exception(
162-
"Failed to create audio tagging. Please check your config");
163-
}
164-
165160
calloc.free(labelsPtr);
166161
calloc.free(providerPtr);
167162
calloc.free(cedPtr);
168163
calloc.free(zipformerPtr);
169164
calloc.free(c);
170165

166+
if (ptr == nullptr) {
167+
throw Exception(
168+
"Failed to create audio tagging. Please check your config");
169+
}
170+
171171
return AudioTagging._(ptr: ptr, config: config);
172172
}
173173

flutter/sherpa_onnx/lib/src/keyword_spotter.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ class KeywordSpotter {
146146

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

149-
if (ptr == nullptr) {
150-
throw Exception("Failed to create kws. Please check your config");
151-
}
152-
153149
calloc.free(c.ref.keywordsBuf);
154150
calloc.free(c.ref.keywordsFile);
155151
calloc.free(c.ref.model.bpeVocab);
@@ -167,6 +163,10 @@ class KeywordSpotter {
167163
calloc.free(c.ref.model.transducer.joiner);
168164
calloc.free(c);
169165

166+
if (ptr == nullptr) {
167+
throw Exception("Failed to create kws. Please check your config");
168+
}
169+
170170
return KeywordSpotter._(ptr: ptr, config: config);
171171
}
172172

flutter/sherpa_onnx/lib/src/offline_punctuation.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ class OfflinePunctuation {
6969

7070
// The user has to invoke OfflinePunctuation.free() to avoid memory leak.
7171
factory OfflinePunctuation({required OfflinePunctuationConfig config}) {
72+
if (SherpaOnnxBindings.sherpaOnnxCreateOfflinePunctuation == null) {
73+
throw Exception("Please initialize sherpa-onnx first");
74+
}
75+
7276
final c = calloc<SherpaOnnxOfflinePunctuationConfig>();
7377

7478
final ctTransformerPtr = config.model.ctTransformer.toNativeUtf8();
@@ -79,23 +83,19 @@ class OfflinePunctuation {
7983
final providerPtr = config.model.provider.toNativeUtf8();
8084
c.ref.model.provider = providerPtr;
8185

82-
if (SherpaOnnxBindings.sherpaOnnxCreateOfflinePunctuation == null) {
83-
throw Exception("Please initialize sherpa-onnx first");
84-
}
85-
8686
final ptr =
8787
SherpaOnnxBindings.sherpaOnnxCreateOfflinePunctuation?.call(c) ??
8888
nullptr;
8989

90+
calloc.free(providerPtr);
91+
calloc.free(ctTransformerPtr);
92+
calloc.free(c);
93+
9094
if (ptr == nullptr) {
9195
throw Exception(
9296
"Failed to create offline punctuation. Please check your config");
9397
}
9498

95-
calloc.free(providerPtr);
96-
calloc.free(ctTransformerPtr);
97-
calloc.free(c);
98-
9999
return OfflinePunctuation._(ptr: ptr, config: config);
100100
}
101101

flutter/sherpa_onnx/lib/src/offline_speaker_diarization.dart

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ class OfflineSpeakerDiarization {
192192
/// The user is responsible to call the OfflineSpeakerDiarization.free()
193193
/// method of the returned instance to avoid memory leak.
194194
factory OfflineSpeakerDiarization(OfflineSpeakerDiarizationConfig config) {
195+
if (SherpaOnnxBindings.sherpaOnnxCreateOfflineSpeakerDiarization == null) {
196+
throw Exception("Please initialize sherpa-onnx first");
197+
}
198+
195199
final c = calloc<SherpaOnnxOfflineSpeakerDiarizationConfig>();
196200

197201
c.ref.segmentation.pyannote.model =
@@ -211,31 +215,25 @@ class OfflineSpeakerDiarization {
211215
c.ref.minDurationOn = config.minDurationOn;
212216
c.ref.minDurationOff = config.minDurationOff;
213217

214-
if (SherpaOnnxBindings.sherpaOnnxCreateOfflineSpeakerDiarization == null) {
215-
throw Exception("Please initialize sherpa-onnx first");
216-
}
217-
218218
final ptr =
219219
SherpaOnnxBindings.sherpaOnnxCreateOfflineSpeakerDiarization?.call(c) ??
220220
nullptr;
221221

222-
if (ptr == nullptr) {
223-
throw Exception(
224-
"Failed to create offline speaker diarization. Please check your config");
225-
}
226-
227222
calloc.free(c.ref.embedding.provider);
228223
calloc.free(c.ref.embedding.model);
229224
calloc.free(c.ref.segmentation.provider);
230225
calloc.free(c.ref.segmentation.pyannote.model);
226+
calloc.free(c);
231227

232-
int sampleRate = 0;
233-
if (ptr != nullptr) {
234-
sampleRate = SherpaOnnxBindings
235-
.sherpaOnnxOfflineSpeakerDiarizationGetSampleRate
236-
?.call(ptr) ??
237-
0;
228+
if (ptr == nullptr) {
229+
throw Exception(
230+
"Failed to create offline speaker diarization. Please check your config");
238231
}
232+
233+
int sampleRate = SherpaOnnxBindings
234+
.sherpaOnnxOfflineSpeakerDiarizationGetSampleRate
235+
?.call(ptr) ?? 0;
236+
239237
return OfflineSpeakerDiarization._(
240238
ptr: ptr, config: config, sampleRate: sampleRate);
241239
}

flutter/sherpa_onnx/lib/src/offline_speech_denoiser.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,15 @@ class OfflineSpeechDenoiser {
126126
SherpaOnnxBindings.sherpaOnnxCreateOfflineSpeechDenoiser?.call(c) ??
127127
nullptr;
128128

129+
calloc.free(c.ref.model.provider);
130+
calloc.free(c.ref.model.gtcrn.model);
131+
calloc.free(c);
132+
129133
if (ptr == nullptr) {
130134
throw Exception(
131135
"Failed to create offline speech denoiser. Please check your config");
132136
}
133137

134-
calloc.free(c.ref.model.provider);
135-
calloc.free(c.ref.model.gtcrn.model);
136-
137138
return OfflineSpeechDenoiser._(ptr: ptr, config: config);
138139
}
139140

flutter/sherpa_onnx/lib/src/online_punctuation.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ class OnlinePunctuation {
7777

7878
// The user has to invoke OnlinePunctuation.free() to avoid memory leak.
7979
factory OnlinePunctuation({required OnlinePunctuationConfig config}) {
80+
if (SherpaOnnxBindings.sherpaOnnxCreateOnlinePunctuation == null) {
81+
throw Exception("Please initialize sherpa-onnx first");
82+
}
83+
8084
final c = calloc<SherpaOnnxOnlinePunctuationConfig>();
8185

8286
final cnnBiLstmPtr = config.model.cnnBiLstm.toNativeUtf8();
@@ -89,24 +93,19 @@ class OnlinePunctuation {
8993
final providerPtr = config.model.provider.toNativeUtf8();
9094
c.ref.model.provider = providerPtr;
9195

92-
if (SherpaOnnxBindings.sherpaOnnxCreateOnlinePunctuation == null) {
93-
throw Exception("Please initialize sherpa-onnx first");
94-
}
95-
9696
final ptr = SherpaOnnxBindings.sherpaOnnxCreateOnlinePunctuation?.call(c) ??
9797
nullptr;
9898

99-
if (ptr == nullptr) {
100-
throw Exception(
101-
"Failed to create online punctuation. Please check your config");
102-
}
103-
104-
// Free the allocated strings and struct memory
10599
calloc.free(providerPtr);
106100
calloc.free(cnnBiLstmPtr);
107101
calloc.free(bpeVocabPtr);
108102
calloc.free(c);
109103

104+
if (ptr == nullptr) {
105+
throw Exception(
106+
"Failed to create online punctuation. Please check your config");
107+
}
108+
110109
return OnlinePunctuation._(ptr: ptr, config: config);
111110
}
112111

flutter/sherpa_onnx/lib/src/online_recognizer.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ class OnlineRecognizer {
363363
/// The user is responsible to call the OnlineRecognizer.free()
364364
/// method of the returned instance to avoid memory leak.
365365
factory OnlineRecognizer(OnlineRecognizerConfig config) {
366+
if (SherpaOnnxBindings.createOnlineRecognizer == null) {
367+
throw Exception("Please initialize sherpa-onnx first");
368+
}
369+
366370
final c = calloc<SherpaOnnxOnlineRecognizerConfig>();
367371
c.ref.feat.sampleRate = config.feat.sampleRate;
368372
c.ref.feat.featureDim = config.feat.featureDim;
@@ -419,17 +423,8 @@ class OnlineRecognizer {
419423
c.ref.hr.lexicon = config.hr.lexicon.toNativeUtf8();
420424
c.ref.hr.ruleFsts = config.hr.ruleFsts.toNativeUtf8();
421425

422-
if (SherpaOnnxBindings.createOnlineRecognizer == null) {
423-
throw Exception("Please initialize sherpa-onnx first");
424-
}
425-
426426
final ptr = SherpaOnnxBindings.createOnlineRecognizer?.call(c) ?? nullptr;
427427

428-
if (ptr == nullptr) {
429-
throw Exception(
430-
"Failed to create online recognizer. Please check your config");
431-
}
432-
433428
calloc.free(c.ref.hr.lexicon);
434429
calloc.free(c.ref.hr.ruleFsts);
435430
calloc.free(c.ref.ruleFars);
@@ -453,6 +448,11 @@ class OnlineRecognizer {
453448
calloc.free(c.ref.model.transducer.joiner);
454449
calloc.free(c);
455450

451+
if (ptr == nullptr) {
452+
throw Exception(
453+
"Failed to create online recognizer. Please check your config");
454+
}
455+
456456
return OnlineRecognizer._(ptr: ptr, config: config);
457457
}
458458

flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,27 @@ final class SherpaOnnxOfflineTtsKittenModelConfig extends Struct {
214214
external double lengthScale;
215215
}
216216

217+
final class SherpaOnnxOfflineTtsZipVoiceModelConfig extends Struct {
218+
external Pointer<Utf8> tokens;
219+
external Pointer<Utf8> textModel;
220+
external Pointer<Utf8> flowMatchingModel;
221+
external Pointer<Utf8> vocoder;
222+
external Pointer<Utf8> dataDir;
223+
external Pointer<Utf8> pinyinDict;
224+
225+
@Float()
226+
external double featScale;
227+
228+
@Float()
229+
external double tShift;
230+
231+
@Float()
232+
external double targetRms;
233+
234+
@Float()
235+
external double guidanceScale;
236+
}
237+
217238
final class SherpaOnnxOfflineTtsModelConfig extends Struct {
218239
external SherpaOnnxOfflineTtsVitsModelConfig vits;
219240
@Int32()
@@ -226,6 +247,7 @@ final class SherpaOnnxOfflineTtsModelConfig extends Struct {
226247
external SherpaOnnxOfflineTtsMatchaModelConfig matcha;
227248
external SherpaOnnxOfflineTtsKokoroModelConfig kokoro;
228249
external SherpaOnnxOfflineTtsKittenModelConfig kitten;
250+
external SherpaOnnxOfflineTtsZipVoiceModelConfig zipvoice;
229251
}
230252

231253
final class SherpaOnnxOfflineTtsConfig extends Struct {

0 commit comments

Comments
 (0)