]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
go : support "auto" as an option when set language (#462)
authorpolarmoon <redacted>
Sat, 4 Feb 2023 07:09:27 +0000 (23:09 -0800)
committerGitHub <redacted>
Sat, 4 Feb 2023 07:09:27 +0000 (09:09 +0200)
Co-authored-by: Ming <redacted>
bindings/go/params.go
bindings/go/pkg/whisper/context.go
bindings/go/pkg/whisper/interface.go

index 08757d7b2333b48d60382495397fb9f2ff2c1b76..c413895c01e2fb271dbd2989940680347654b6e9 100644 (file)
@@ -49,6 +49,10 @@ func (p *Params) SetSpeedup(v bool) {
 
 // Set language id
 func (p *Params) SetLanguage(lang int) error {
+       if lang == -1 {
+               p.language = nil
+               return nil
+       }
        str := C.whisper_lang_str(C.int(lang))
        if str == nil {
                return ErrInvalidLanguage
index a4fe5134cf7f6b6add01e5fe5e5074ea0da9fc33..0a6e9cbc2277c0298d4cc4a2e26008385c8791a7 100644 (file)
@@ -46,7 +46,10 @@ func (context *context) SetLanguage(lang string) error {
        if !context.model.IsMultilingual() {
                return ErrModelNotMultilingual
        }
-       if id := context.model.ctx.Whisper_lang_id(lang); id < 0 {
+
+       if lang == "auto" {
+               context.params.SetLanguage(-1)
+       } else if id := context.model.ctx.Whisper_lang_id(lang); id < 0 {
                return ErrUnsupportedLanguage
        } else if err := context.params.SetLanguage(id); err != nil {
                return err
@@ -61,6 +64,10 @@ func (context *context) IsMultilingual() bool {
 
 // Get language
 func (context *context) Language() string {
+       id := context.params.Language()
+       if id == -1 {
+               return "auto"
+       }
        return whisper.Whisper_lang_str(context.params.Language())
 }
 
index 4242963fb804205e31f5cba929cb24eeefa2ea1c..a1d3f68227813b512052a67cb7c103f5f1786015 100644 (file)
@@ -29,7 +29,7 @@ type Model interface {
 
 // Context is the speach recognition context.
 type Context interface {
-       SetLanguage(string) error // Set the language to use for speech recognition.
+       SetLanguage(string) error // Set the language to use for speech recognition, use "auto" for auto detect language.
        SetTranslate(bool)        // Set translate flag
        IsMultilingual() bool     // Return true if the model is multilingual.
        Language() string         // Get language