go : support "auto" as an option when set language (#462)
Co-authored-by: Ming <ming@localhost>
This commit is contained in:
parent
291980369c
commit
b2fc4c7010
@ -49,6 +49,10 @@ func (p *Params) SetSpeedup(v bool) {
|
|||||||
|
|
||||||
// Set language id
|
// Set language id
|
||||||
func (p *Params) SetLanguage(lang int) error {
|
func (p *Params) SetLanguage(lang int) error {
|
||||||
|
if lang == -1 {
|
||||||
|
p.language = nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
str := C.whisper_lang_str(C.int(lang))
|
str := C.whisper_lang_str(C.int(lang))
|
||||||
if str == nil {
|
if str == nil {
|
||||||
return ErrInvalidLanguage
|
return ErrInvalidLanguage
|
||||||
|
@ -46,7 +46,10 @@ func (context *context) SetLanguage(lang string) error {
|
|||||||
if !context.model.IsMultilingual() {
|
if !context.model.IsMultilingual() {
|
||||||
return ErrModelNotMultilingual
|
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
|
return ErrUnsupportedLanguage
|
||||||
} else if err := context.params.SetLanguage(id); err != nil {
|
} else if err := context.params.SetLanguage(id); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -61,6 +64,10 @@ func (context *context) IsMultilingual() bool {
|
|||||||
|
|
||||||
// Get language
|
// Get language
|
||||||
func (context *context) Language() string {
|
func (context *context) Language() string {
|
||||||
|
id := context.params.Language()
|
||||||
|
if id == -1 {
|
||||||
|
return "auto"
|
||||||
|
}
|
||||||
return whisper.Whisper_lang_str(context.params.Language())
|
return whisper.Whisper_lang_str(context.params.Language())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ type Model interface {
|
|||||||
|
|
||||||
// Context is the speach recognition context.
|
// Context is the speach recognition context.
|
||||||
type Context interface {
|
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
|
SetTranslate(bool) // Set translate flag
|
||||||
IsMultilingual() bool // Return true if the model is multilingual.
|
IsMultilingual() bool // Return true if the model is multilingual.
|
||||||
Language() string // Get language
|
Language() string // Get language
|
||||||
|
Loading…
Reference in New Issue
Block a user