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++ {