franck-li
Committed by GitHub

go.mod set to use go 1.17, and use unsafe.Slice to optimize the code (#1920)

Co-authored-by: liyuzhi <liyuzhi@info.easeus.com.cn>
正在显示 32 个修改的文件 包含 41 行增加41 行删除
1 module add-punctuation 1 module add-punctuation
2 2
3 -go 1.12 3 +go 1.17
1 module audio-tagging 1 module audio-tagging
2 2
3 -go 1.12 3 +go 1.17
4 4
1 module keyword-spotting-from-file 1 module keyword-spotting-from-file
2 2
3 -go 1.12 3 +go 1.17
4 4
1 module non-streaming-decode-files 1 module non-streaming-decode-files
2 2
3 -go 1.12 3 +go 1.17
1 module non-streaming-speaker-diarization 1 module non-streaming-speaker-diarization
2 2
3 -go 1.12 3 +go 1.17
1 module non-streaming-tts 1 module non-streaming-tts
2 2
3 -go 1.12 3 +go 1.17
1 module real-time-speech-recognition-from-microphone 1 module real-time-speech-recognition-from-microphone
2 2
3 -go 1.12 3 +go 1.17
4 4
5 require ( 5 require (
6 github.com/csukuangfj/portaudio-go v1.0.3 6 github.com/csukuangfj/portaudio-go v1.0.3
1 module speaker-identification 1 module speaker-identification
2 2
3 -go 1.12 3 +go 1.17
1 module streaming-decode-files 1 module streaming-decode-files
2 2
3 -go 1.12 3 +go 1.17
1 module streaming-hlg-decoding 1 module streaming-hlg-decoding
2 2
3 -go 1.12 3 +go 1.17
1 module vad-asr-paraformer 1 module vad-asr-paraformer
2 2
3 -go 1.12 3 +go 1.17
1 module vad-asr-whisper 1 module vad-asr-whisper
2 2
3 -go 1.12 3 +go 1.17
1 module vad-speaker-identification 1 module vad-speaker-identification
2 2
3 -go 1.12 3 +go 1.17
1 module vad-spoken-language-identification 1 module vad-spoken-language-identification
2 2
3 -go 1.12 3 +go 1.17
1 module vad 1 module vad
2 2
3 -go 1.12 3 +go 1.17
1 module add-punctuation 1 module add-punctuation
2 2
3 -go 1.12 3 +go 1.17
4 4
5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../ 5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
1 module audio-tagging 1 module audio-tagging
2 2
3 -go 1.12 3 +go 1.17
4 4
5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../ 5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
1 module sherpa_onnx 1 module sherpa_onnx
2 2
3 -go 1.12 3 +go 1.17
1 module keyword-spotting-from-file 1 module keyword-spotting-from-file
2 2
3 -go 1.12 3 +go 1.17
4 4
5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../ 5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
1 module non-streaming-decode-files 1 module non-streaming-decode-files
2 2
3 -go 1.12 3 +go 1.17
4 4
5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../ 5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
1 module non-streaming-speaker-diarization 1 module non-streaming-speaker-diarization
2 2
3 -go 1.12 3 +go 1.17
4 4
5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../ 5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
1 module non-streaming-tts 1 module non-streaming-tts
2 2
3 -go 1.12 3 +go 1.17
4 4
5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../ 5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
1 module real-time-speech-recognition-from-microphone 1 module real-time-speech-recognition-from-microphone
2 2
3 -go 1.12 3 +go 1.17
4 4
5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../ 5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
1 module speaker-identification 1 module speaker-identification
2 2
3 -go 1.12 3 +go 1.17
4 4
5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../ 5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
1 module streaming-decode-files 1 module streaming-decode-files
2 2
3 -go 1.12 3 +go 1.17
4 4
5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../ 5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
1 module streaming-hlg-decoding 1 module streaming-hlg-decoding
2 2
3 -go 1.12 3 +go 1.17
4 4
5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../ 5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
1 module vad-asr-paraformer 1 module vad-asr-paraformer
2 2
3 -go 1.12 3 +go 1.17
4 4
5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../ 5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
1 module vad-asr-whisper 1 module vad-asr-whisper
2 2
3 -go 1.12 3 +go 1.17
4 4
5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../ 5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
1 module vad-speaker-identification 1 module vad-speaker-identification
2 2
3 -go 1.12 3 +go 1.17
4 4
5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../ 5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
1 module vad-spoken-language-identification 1 module vad-spoken-language-identification
2 2
3 -go 1.12 3 +go 1.17
4 4
5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../ 5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
1 module vad 1 module vad
2 2
3 -go 1.12 3 +go 1.17
4 4
5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../ 5 replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
@@ -659,7 +659,7 @@ func (s *OfflineStream) GetResult() *OfflineRecognizerResult { @@ -659,7 +659,7 @@ func (s *OfflineStream) GetResult() *OfflineRecognizerResult {
659 result.Emotion = C.GoString(p.emotion) 659 result.Emotion = C.GoString(p.emotion)
660 result.Event = C.GoString(p.event) 660 result.Event = C.GoString(p.event)
661 result.Tokens = make([]string, n) 661 result.Tokens = make([]string, n)
662 - tokens := (*[1 << 10]*C.char)(unsafe.Pointer(p.tokens_arr))[:n:n] 662 + tokens := unsafe.Slice(p.tokens_arr, n)
663 for i := 0; i < n; i++ { 663 for i := 0; i < n; i++ {
664 result.Tokens[i] = C.GoString(tokens[i]) 664 result.Tokens[i] = C.GoString(tokens[i])
665 } 665 }
@@ -667,7 +667,7 @@ func (s *OfflineStream) GetResult() *OfflineRecognizerResult { @@ -667,7 +667,7 @@ func (s *OfflineStream) GetResult() *OfflineRecognizerResult {
667 return result 667 return result
668 } 668 }
669 result.Timestamps = make([]float32, n) 669 result.Timestamps = make([]float32, n)
670 - timestamps := (*[1 << 10]C.float)(unsafe.Pointer(p.timestamps))[:n:n] 670 + timestamps := unsafe.Slice(p.timestamps, n)
671 for i := 0; i < n; i++ { 671 for i := 0; i < n; i++ {
672 result.Timestamps[i] = float32(timestamps[i]) 672 result.Timestamps[i] = float32(timestamps[i])
673 } 673 }
@@ -858,7 +858,7 @@ func (tts *OfflineTts) Generate(text string, sid int, speed float32) *GeneratedA @@ -858,7 +858,7 @@ func (tts *OfflineTts) Generate(text string, sid int, speed float32) *GeneratedA
858 858
859 // see https://stackoverflow.com/questions/48756732/what-does-1-30c-yourtype-do-exactly-in-cgo 859 // see https://stackoverflow.com/questions/48756732/what-does-1-30c-yourtype-do-exactly-in-cgo
860 // :n:n means 0:n:n, means low:high:capacity 860 // :n:n means 0:n:n, means low:high:capacity
861 - samples := (*[1 << 10]C.float)(unsafe.Pointer(audio.samples))[:n:n] 861 + samples := unsafe.Slice(audio.samples, n)
862 // copy(ans.Samples, samples) 862 // copy(ans.Samples, samples)
863 for i := 0; i < n; i++ { 863 for i := 0; i < n; i++ {
864 ans.Samples[i] = float32(samples[i]) 864 ans.Samples[i] = float32(samples[i])
@@ -921,7 +921,7 @@ func (buffer *CircularBuffer) Get(start int, n int) []float32 { @@ -921,7 +921,7 @@ func (buffer *CircularBuffer) Get(start int, n int) []float32 {
921 921
922 result := make([]float32, n) 922 result := make([]float32, n)
923 923
924 - p := (*[1 << 10]C.float)(unsafe.Pointer(samples))[:n:n] 924 + p := unsafe.Slice(samples, n)
925 for i := 0; i < n; i++ { 925 for i := 0; i < n; i++ {
926 result[i] = float32(p[i]) 926 result[i] = float32(p[i])
927 } 927 }
@@ -1017,7 +1017,7 @@ func (vad *VoiceActivityDetector) Front() *SpeechSegment { @@ -1017,7 +1017,7 @@ func (vad *VoiceActivityDetector) Front() *SpeechSegment {
1017 n := int(f.n) 1017 n := int(f.n)
1018 ans.Samples = make([]float32, n) 1018 ans.Samples = make([]float32, n)
1019 1019
1020 - samples := (*[1 << 10]C.float)(unsafe.Pointer(f.samples))[:n:n] 1020 + samples := unsafe.Slice(f.samples, n)
1021 1021
1022 for i := 0; i < n; i++ { 1022 for i := 0; i < n; i++ {
1023 ans.Samples[i] = float32(samples[i]) 1023 ans.Samples[i] = float32(samples[i])
@@ -1171,7 +1171,7 @@ func (ex *SpeakerEmbeddingExtractor) Compute(stream *OnlineStream) []float32 { @@ -1171,7 +1171,7 @@ func (ex *SpeakerEmbeddingExtractor) Compute(stream *OnlineStream) []float32 {
1171 1171
1172 // see https://stackoverflow.com/questions/48756732/what-does-1-30c-yourtype-do-exactly-in-cgo 1172 // see https://stackoverflow.com/questions/48756732/what-does-1-30c-yourtype-do-exactly-in-cgo
1173 // :n:n means 0:n:n, means low:high:capacity 1173 // :n:n means 0:n:n, means low:high:capacity
1174 - c := (*[1 << 10]C.float)(unsafe.Pointer(embedding))[:n:n] 1174 + c := unsafe.Slice(embedding, n)
1175 1175
1176 for i := 0; i < n; i++ { 1176 for i := 0; i < n; i++ {
1177 ans[i] = float32(c[i]) 1177 ans[i] = float32(c[i])
@@ -1273,7 +1273,7 @@ func (m *SpeakerEmbeddingManager) AllSpeakers() []string { @@ -1273,7 +1273,7 @@ func (m *SpeakerEmbeddingManager) AllSpeakers() []string {
1273 } 1273 }
1274 1274
1275 // https://stackoverflow.com/questions/62012070/convert-array-of-strings-from-cgo-in-go 1275 // https://stackoverflow.com/questions/62012070/convert-array-of-strings-from-cgo-in-go
1276 - p := (*[1 << 10]*C.char)(unsafe.Pointer(all_speakers))[:n:n] 1276 + p := unsafe.Slice(all_speakers, n)
1277 1277
1278 ans := make([]string, n) 1278 ans := make([]string, n)
1279 1279
@@ -1307,7 +1307,7 @@ func ReadWave(filename string) *Wave { @@ -1307,7 +1307,7 @@ func ReadWave(filename string) *Wave {
1307 1307
1308 ans := &Wave{} 1308 ans := &Wave{}
1309 ans.SampleRate = int(w.sample_rate) 1309 ans.SampleRate = int(w.sample_rate)
1310 - samples := (*[1 << 10]C.float)(unsafe.Pointer(w.samples))[:n:n] 1310 + samples := unsafe.Slice(w.samples, n)
1311 1311
1312 ans.Samples = make([]float32, n) 1312 ans.Samples = make([]float32, n)
1313 1313
@@ -1428,7 +1428,7 @@ func (sd *OfflineSpeakerDiarization) Process(samples []float32) []OfflineSpeaker @@ -1428,7 +1428,7 @@ func (sd *OfflineSpeakerDiarization) Process(samples []float32) []OfflineSpeaker
1428 1428
1429 ans := make([]OfflineSpeakerDiarizationSegment, n) 1429 ans := make([]OfflineSpeakerDiarizationSegment, n)
1430 1430
1431 - p := (*[1 << 10]C.struct_SherpaOnnxOfflineSpeakerDiarizationSegment)(unsafe.Pointer(s))[:n:n] 1431 + p := unsafe.Slice(s, n)
1432 1432
1433 for i := 0; i < n; i++ { 1433 for i := 0; i < n; i++ {
1434 ans[i].Start = float32(p[i].start) 1434 ans[i].Start = float32(p[i].start)
@@ -1725,7 +1725,7 @@ func (tagging *AudioTagging) Compute(s *OfflineStream, topK int32) []AudioEvent @@ -1725,7 +1725,7 @@ func (tagging *AudioTagging) Compute(s *OfflineStream, topK int32) []AudioEvent
1725 defer C.SherpaOnnxAudioTaggingFreeResults(r) 1725 defer C.SherpaOnnxAudioTaggingFreeResults(r)
1726 result := make([]AudioEvent, 0) 1726 result := make([]AudioEvent, 0)
1727 1727
1728 - p := (*[1 << 10]*C.struct_SherpaOnnxAudioEvent)(unsafe.Pointer(r)) 1728 + p := (*[1 << 25]*C.struct_SherpaOnnxAudioEvent)(unsafe.Pointer(r))
1729 i := 0 1729 i := 0
1730 for { 1730 for {
1731 if p[i] == nil { 1731 if p[i] == nil {