From 8d60666cbc5bad8670116542fb6302b3145af193 Mon Sep 17 00:00:00 2001 From: Amanda Der Bedrosian Date: Thu, 26 Sep 2024 11:20:12 -0700 Subject: [PATCH] Adding in a way to retrieve the detected language for golang bindings Adding in a function, GetDetectedLanguage, which will retrieve the detected language, if available. --- bindings/go/pkg/whisper/context.go | 4 ++++ bindings/go/pkg/whisper/interface.go | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bindings/go/pkg/whisper/context.go b/bindings/go/pkg/whisper/context.go index 87e27b8e763..d1b6d120066 100644 --- a/bindings/go/pkg/whisper/context.go +++ b/bindings/go/pkg/whisper/context.go @@ -289,6 +289,10 @@ func (context *context) IsLANG(t Token, lang string) bool { } } +func (context *context) GetDetectedLanguage() string { + return whisper.Whisper_lang_str(context.model.ctx.Whisper_full_lang_id()) +} + /////////////////////////////////////////////////////////////////////////////// // PRIVATE METHODS diff --git a/bindings/go/pkg/whisper/interface.go b/bindings/go/pkg/whisper/interface.go index 5c7554c7bdb..657f1c1a08a 100644 --- a/bindings/go/pkg/whisper/interface.go +++ b/bindings/go/pkg/whisper/interface.go @@ -37,10 +37,12 @@ type Model interface { // Context is the speech recognition context. type Context interface { - 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 + 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 + GetDetectedLanguage() string // Get auto detected language + SetOffset(time.Duration) // Set offset SetDuration(time.Duration) // Set duration