From bf06b268d07c1ed9c24234f2508bedca44a47449 Mon Sep 17 00:00:00 2001 From: lllwan <32893806+lllwan@users.noreply.github.com> Date: Tue, 17 Sep 2024 13:39:56 +0800 Subject: [PATCH] Fix sherpa_onnx.go (#1353) --- scripts/go/sherpa_onnx.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/go/sherpa_onnx.go b/scripts/go/sherpa_onnx.go index ad5060c2c..85ab8e0b1 100644 --- a/scripts/go/sherpa_onnx.go +++ b/scripts/go/sherpa_onnx.go @@ -610,12 +610,15 @@ func (recognizer *OfflineRecognizer) DecodeStreams(s []*OfflineStream) { func (s *OfflineStream) GetResult() *OfflineRecognizerResult { p := C.SherpaOnnxGetOfflineStreamResult(s.impl) defer C.SherpaOnnxDestroyOfflineRecognizerResult(p) + n := int(p.count) + if n == 0 { + return nil + } result := &OfflineRecognizerResult{} result.Text = C.GoString(p.text) result.Lang = C.GoString(p.lang) result.Emotion = C.GoString(p.emotion) result.Event = C.GoString(p.event) - n := int(p.count) result.Tokens = make([]string, n) tokens := (*[1 << 28]*C.char)(unsafe.Pointer(p.tokens_arr))[:n:n] for i := 0; i < n; i++ {