@@ -239,9 +239,12 @@ func NewOnlineRecognizer(config *OnlineRecognizerConfig) *OnlineRecognizer {
239239 defer C .free (unsafe .Pointer (c .ctc_fst_decoder_config .graph ))
240240 c .ctc_fst_decoder_config .max_active = C .int (config .CtcFstDecoderConfig .MaxActive )
241241
242+ impl := C .SherpaOnnxCreateOnlineRecognizer (& c )
243+ if impl == nil {
244+ return nil
245+ }
242246 recognizer := & OnlineRecognizer {}
243- recognizer .impl = C .SherpaOnnxCreateOnlineRecognizer (& c )
244-
247+ recognizer .impl = impl
245248 return recognizer
246249}
247250
@@ -580,8 +583,12 @@ func NewOfflineRecognizer(config *OfflineRecognizerConfig) *OfflineRecognizer {
580583 c .rule_fars = C .CString (config .RuleFars )
581584 defer C .free (unsafe .Pointer (c .rule_fars ))
582585
586+ impl := C .SherpaOnnxCreateOfflineRecognizer (& c )
587+ if impl == nil {
588+ return nil
589+ }
583590 recognizer := & OfflineRecognizer {}
584- recognizer .impl = C . SherpaOnnxCreateOfflineRecognizer ( & c )
591+ recognizer .impl = impl
585592
586593 return recognizer
587594}
@@ -816,9 +823,12 @@ func NewOfflineTts(config *OfflineTtsConfig) *OfflineTts {
816823 c .model .provider = C .CString (config .Model .Provider )
817824 defer C .free (unsafe .Pointer (c .model .provider ))
818825
826+ impl := C .SherpaOnnxCreateOfflineTts (& c )
827+ if impl == nil {
828+ return nil
829+ }
819830 tts := & OfflineTts {}
820- tts .impl = C .SherpaOnnxCreateOfflineTts (& c )
821-
831+ tts .impl = impl
822832 return tts
823833}
824834
@@ -951,9 +961,12 @@ func NewVoiceActivityDetector(config *VadModelConfig, bufferSizeInSeconds float3
951961
952962 c .debug = C .int (config .Debug )
953963
964+ impl := C .SherpaOnnxCreateVoiceActivityDetector (& c , C .float (bufferSizeInSeconds ))
965+ if impl == nil {
966+ return nil
967+ }
954968 vad := & VoiceActivityDetector {}
955- vad .impl = C .SherpaOnnxCreateVoiceActivityDetector (& c , C .float (bufferSizeInSeconds ))
956-
969+ vad .impl = impl
957970 return vad
958971}
959972
@@ -1107,9 +1120,12 @@ func NewSpeakerEmbeddingExtractor(config *SpeakerEmbeddingExtractorConfig) *Spea
11071120 c .provider = C .CString (config .Provider )
11081121 defer C .free (unsafe .Pointer (c .provider ))
11091122
1123+ impl := C .SherpaOnnxCreateSpeakerEmbeddingExtractor (& c )
1124+ if impl == nil {
1125+ return nil
1126+ }
11101127 ex := & SpeakerEmbeddingExtractor {}
1111- ex .impl = C .SherpaOnnxCreateSpeakerEmbeddingExtractor (& c )
1112-
1128+ ex .impl = impl
11131129 return ex
11141130}
11151131
@@ -1159,8 +1175,12 @@ type SpeakerEmbeddingManager struct {
11591175// The user has to invoke [DeleteSpeakerEmbeddingManager]() to free the returned
11601176// value to avoid memory leak
11611177func NewSpeakerEmbeddingManager (dim int ) * SpeakerEmbeddingManager {
1178+ impl := C .SherpaOnnxCreateSpeakerEmbeddingManager (C .int (dim ))
1179+ if impl == nil {
1180+ return nil
1181+ }
11621182 m := & SpeakerEmbeddingManager {}
1163- m .impl = C . SherpaOnnxCreateSpeakerEmbeddingManager ( C . int ( dim ))
1183+ m .impl = impl
11641184 return m
11651185}
11661186
@@ -1435,9 +1455,12 @@ func NewOfflinePunctuation(config *OfflinePunctuationConfig) *OfflinePunctuation
14351455 cfg .model .provider = C .CString (config .Model .Provider )
14361456 defer C .free (unsafe .Pointer (cfg .model .provider ))
14371457
1458+ impl := C .SherpaOnnxCreateOfflinePunctuation (& cfg )
1459+ if impl == nil {
1460+ return nil
1461+ }
14381462 punc := & OfflinePunctuation {}
1439- punc .impl = C .SherpaOnnxCreateOfflinePunctuation (& cfg )
1440-
1463+ punc .impl = impl
14411464 return punc
14421465}
14431466
@@ -1544,9 +1567,12 @@ func NewKeywordSpotter(config *KeywordSpotterConfig) *KeywordSpotter {
15441567
15451568 c .keywords_buf_size = C .int (config .KeywordsBufSize )
15461569
1570+ impl := C .SherpaOnnxCreateKeywordSpotter (& c )
1571+ if impl == nil {
1572+ return nil
1573+ }
15471574 spotter := & KeywordSpotter {}
1548- spotter .impl = C .SherpaOnnxCreateKeywordSpotter (& c )
1549-
1575+ spotter .impl = impl
15501576 return spotter
15511577}
15521578
@@ -1665,9 +1691,12 @@ func NewAudioTagging(config *AudioTaggingConfig) *AudioTagging {
16651691
16661692 c .top_k = C .int (config .TopK )
16671693
1694+ impl := C .SherpaOnnxCreateAudioTagging (& c )
1695+ if impl == nil {
1696+ return nil
1697+ }
16681698 tagging := & AudioTagging {}
1669- tagging .impl = C .SherpaOnnxCreateAudioTagging (& c )
1670-
1699+ tagging .impl = impl
16711700 return tagging
16721701}
16731702
0 commit comments