From: bradmit Date: Fri, 24 Nov 2023 07:33:13 +0000 (+1100) Subject: whisper : add whisper_lang_str_full (#1546) X-Git-Tag: upstream/1.7.4~1231 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=34f70b3a56b40d1a824dfbc201478d0d94228a6e;p=pkg%2Fggml%2Fsources%2Fwhisper.cpp whisper : add whisper_lang_str_full (#1546) * Update whisper.h add whisper_lang_fullstr to retrieve the full language name * Update whisper.cpp add whisper_lang_fullstr to return the full language name * fullstr -> str_full --------- Co-authored-by: Georgi Gerganov --- diff --git a/whisper.cpp b/whisper.cpp index 2727bada..79361487 100644 --- a/whisper.cpp +++ b/whisper.cpp @@ -3593,6 +3593,17 @@ const char * whisper_lang_str(int id) { return nullptr; } +const char * whisper_lang_str_full(int id) { + for (const auto & kv : g_lang) { + if (kv.second.first == id) { + return kv.second.second.c_str(); + } + } + + WHISPER_LOG_ERROR("%s: unknown language id %d\n", __func__, id); + return nullptr; +} + int whisper_lang_auto_detect_with_state( struct whisper_context * ctx, struct whisper_state * state, diff --git a/whisper.h b/whisper.h index 41eb88a6..bd3409fc 100644 --- a/whisper.h +++ b/whisper.h @@ -315,6 +315,9 @@ extern "C" { // Return the short string of the specified language id (e.g. 2 -> "de"), returns nullptr if not found WHISPER_API const char * whisper_lang_str(int id); + // Return the short string of the specified language name (e.g. 2 -> "german"), returns nullptr if not found + WHISPER_API const char * whisper_lang_str_full(int id); + // Use mel data at offset_ms to try and auto-detect the spoken language // Make sure to call whisper_pcm_to_mel() or whisper_set_mel() first // Returns the top language id or negative on failure