add Tokens []string, Timestamps []float32, Lang string, Emotion string, Event string (#1277)
This commit is contained in:
committed by
GitHub
parent
17c8237ee4
commit
a8556e31ba
@@ -3,12 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
sherpa "github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx"
|
|
||||||
flag "github.com/spf13/pflag"
|
|
||||||
"github.com/youpy/go-wav"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
sherpa "github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx"
|
||||||
|
flag "github.com/spf13/pflag"
|
||||||
|
"github.com/youpy/go-wav"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -80,7 +81,16 @@ func main() {
|
|||||||
log.Println("Decoding done!")
|
log.Println("Decoding done!")
|
||||||
result := stream.GetResult()
|
result := stream.GetResult()
|
||||||
|
|
||||||
log.Println(strings.ToLower(result.Text))
|
log.Println("Text: " + strings.ToLower(result.Text))
|
||||||
|
log.Println("Emotion: " + result.Emotion)
|
||||||
|
log.Println("Lang: " + result.Lang)
|
||||||
|
log.Println("Event: " + result.Event)
|
||||||
|
for _, v := range result.Timestamps {
|
||||||
|
log.Printf("Timestamp: %+v\n", v)
|
||||||
|
}
|
||||||
|
for _, v := range result.Tokens {
|
||||||
|
log.Println("Token: " + v)
|
||||||
|
}
|
||||||
log.Printf("Wave duration: %v seconds", float32(len(samples))/float32(sampleRate))
|
log.Printf("Wave duration: %v seconds", float32(len(samples))/float32(sampleRate))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -441,6 +441,11 @@ type OfflineStream struct {
|
|||||||
// It contains recognition result of an offline stream.
|
// It contains recognition result of an offline stream.
|
||||||
type OfflineRecognizerResult struct {
|
type OfflineRecognizerResult struct {
|
||||||
Text string
|
Text string
|
||||||
|
Tokens []string
|
||||||
|
Timestamps []float32
|
||||||
|
Lang string
|
||||||
|
Emotion string
|
||||||
|
Event string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Frees the internal pointer of the recognition to avoid memory leak.
|
// Frees the internal pointer of the recognition to avoid memory leak.
|
||||||
@@ -593,7 +598,23 @@ func (s *OfflineStream) GetResult() *OfflineRecognizerResult {
|
|||||||
defer C.SherpaOnnxDestroyOfflineRecognizerResult(p)
|
defer C.SherpaOnnxDestroyOfflineRecognizerResult(p)
|
||||||
result := &OfflineRecognizerResult{}
|
result := &OfflineRecognizerResult{}
|
||||||
result.Text = C.GoString(p.text)
|
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++ {
|
||||||
|
result.Tokens[i] = C.GoString(tokens[i])
|
||||||
|
}
|
||||||
|
if p.timestamps == nil {
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
result.Timestamps = make([]float32, n)
|
||||||
|
timestamps := (*[1 << 28]C.float)(unsafe.Pointer(p.timestamps))[:n:n]
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
result.Timestamps[i] = float32(timestamps[i])
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user