From 834d4c309fcd7eaa32291c6d2318a4ff40b9a3ec Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Tue, 24 Mar 2026 10:38:48 +0800 Subject: [PATCH] Add missing fields of OnlineRecongizerResult to Go API. --- scripts/go/sherpa_onnx.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/scripts/go/sherpa_onnx.go b/scripts/go/sherpa_onnx.go index 4032c6d8e3..cf0fccba8c 100644 --- a/scripts/go/sherpa_onnx.go +++ b/scripts/go/sherpa_onnx.go @@ -164,7 +164,10 @@ type OnlineRecognizerConfig struct { // It contains the recognition result for a online stream. type OnlineRecognizerResult struct { - Text string + Text string + Tokens []string + Timestamps []float32 + Json string } // The online recognizer class. It wraps a pointer from C. @@ -404,8 +407,24 @@ func (recognizer *OnlineRecognizer) DecodeStreams(s []*OnlineStream) { func (recognizer *OnlineRecognizer) GetResult(s *OnlineStream) *OnlineRecognizerResult { p := C.SherpaOnnxGetOnlineStreamResult(recognizer.impl, s.impl) defer C.SherpaOnnxDestroyOnlineRecognizerResult(p) + n := int(p.count) result := &OnlineRecognizerResult{} result.Text = C.GoString(p.text) + result.Json = C.GoString(p.json) + if n > 0 { + result.Tokens = make([]string, n) + tokens := unsafe.Slice(p.tokens_arr, n) + for i := 0; i < n; i++ { + result.Tokens[i] = C.GoString(tokens[i]) + } + } + if p.timestamps != nil && n > 0 { + result.Timestamps = make([]float32, n) + timestamps := unsafe.Slice(p.timestamps, n) + for i := 0; i < n; i++ { + result.Timestamps[i] = float32(timestamps[i]) + } + } return result }