Add Golang API for spoken language identification. (#709)
This commit is contained in:
2
scripts/go/_internal/vad-spoken-language-identification/.gitignore
vendored
Normal file
2
scripts/go/_internal/vad-spoken-language-identification/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
vad-spoken-language-identification
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
module vad-spoken-language-identification
|
||||
|
||||
go 1.12
|
||||
|
||||
replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
|
||||
1
scripts/go/_internal/vad-spoken-language-identification/main.go
Symbolic link
1
scripts/go/_internal/vad-spoken-language-identification/main.go
Symbolic link
@@ -0,0 +1 @@
|
||||
/Users/fangjun/open-source/sherpa-onnx/go-api-examples/vad-spoken-language-identification/main.go
|
||||
1
scripts/go/_internal/vad-spoken-language-identification/run.sh
Symbolic link
1
scripts/go/_internal/vad-spoken-language-identification/run.sh
Symbolic link
@@ -0,0 +1 @@
|
||||
/Users/fangjun/open-source/sherpa-onnx/go-api-examples/vad-spoken-language-identification/run.sh
|
||||
@@ -783,3 +783,72 @@ func (vad *VoiceActivityDetector) Front() *SpeechSegment {
|
||||
func (vad *VoiceActivityDetector) Reset() {
|
||||
C.SherpaOnnxVoiceActivityDetectorReset(vad.impl)
|
||||
}
|
||||
|
||||
// Spoken language identification
|
||||
|
||||
type SpokenLanguageIdentificationWhisperConfig struct {
|
||||
Encoder string
|
||||
Decoder string
|
||||
TailPaddings int
|
||||
}
|
||||
|
||||
type SpokenLanguageIdentificationConfig struct {
|
||||
Whisper SpokenLanguageIdentificationWhisperConfig
|
||||
NumThreads int
|
||||
Debug int
|
||||
Provider string
|
||||
}
|
||||
|
||||
type SpokenLanguageIdentification struct {
|
||||
impl *C.struct_SherpaOnnxSpokenLanguageIdentification
|
||||
}
|
||||
|
||||
type SpokenLanguageIdentificationResult struct {
|
||||
Lang string
|
||||
}
|
||||
|
||||
func NewSpokenLanguageIdentification(config *SpokenLanguageIdentificationConfig) *SpokenLanguageIdentification {
|
||||
c := C.struct_SherpaOnnxSpokenLanguageIdentificationConfig{}
|
||||
|
||||
c.whisper.encoder = C.CString(config.Whisper.Encoder)
|
||||
defer C.free(unsafe.Pointer(c.whisper.encoder))
|
||||
|
||||
c.whisper.decoder = C.CString(config.Whisper.Decoder)
|
||||
defer C.free(unsafe.Pointer(c.whisper.decoder))
|
||||
|
||||
c.whisper.tail_paddings = C.int(config.Whisper.TailPaddings)
|
||||
|
||||
c.num_threads = C.int(config.NumThreads)
|
||||
c.debug = C.int(config.Debug)
|
||||
|
||||
c.provider = C.CString(config.Provider)
|
||||
defer C.free(unsafe.Pointer(c.provider))
|
||||
|
||||
slid := &SpokenLanguageIdentification{}
|
||||
slid.impl = C.SherpaOnnxCreateSpokenLanguageIdentification(&c)
|
||||
|
||||
return slid
|
||||
}
|
||||
|
||||
func DeleteSpokenLanguageIdentification(slid *SpokenLanguageIdentification) {
|
||||
C.SherpaOnnxDestroySpokenLanguageIdentification(slid.impl)
|
||||
slid.impl = nil
|
||||
}
|
||||
|
||||
// The user has to invoke DeleteOfflineStream() to free the returned value
|
||||
// to avoid memory leak
|
||||
func (slid *SpokenLanguageIdentification) CreateStream() *OfflineStream {
|
||||
stream := &OfflineStream{}
|
||||
stream.impl = C.SherpaOnnxSpokenLanguageIdentificationCreateOfflineStream(slid.impl)
|
||||
return stream
|
||||
}
|
||||
|
||||
func (slid *SpokenLanguageIdentification) Compute(stream *OfflineStream) *SpokenLanguageIdentificationResult {
|
||||
r := C.SherpaOnnxSpokenLanguageIdentificationCompute(slid.impl, stream.impl)
|
||||
// defer C.SherpaOnnxDestroySpokenLanguageIdentificationResult(r)
|
||||
|
||||
ans := &SpokenLanguageIdentificationResult{}
|
||||
ans.Lang = C.GoString(r.lang)
|
||||
|
||||
return ans
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user