added multilingual support for whisper

This commit is contained in:
Concedo
2025-01-09 23:28:52 +08:00
parent 0cb599546e
commit 91b6e29af3
6 changed files with 49 additions and 8 deletions
+13 -3
View File
@@ -5355,13 +5355,19 @@ int whisper_full_with_state(
const auto lang_id = whisper_lang_auto_detect_with_state(ctx, state, 0, params.n_threads, probs.data());
if (lang_id < 0) {
WHISPER_LOG_ERROR("%s: failed to auto-detect language\n", __func__);
if(params.debug_mode)
{
printf("\n%s: failed to auto-detect language\n", __func__);
}
return -3;
}
state->lang_id = lang_id;
params.language = whisper_lang_str(lang_id);
WHISPER_LOG_INFO("%s: auto-detected language: %s (p = %f)\n", __func__, params.language, probs[whisper_lang_id(params.language)]);
if(params.debug_mode)
{
printf("\n%s: auto-detected language: %s (p = %f)\n", __func__, params.language, probs[whisper_lang_id(params.language)]);
}
if (params.detect_language) {
return 0;
}
@@ -5477,7 +5483,11 @@ int whisper_full_with_state(
std::vector<whisper_token> prompt_init = { whisper_token_sot(ctx), };
if (whisper_is_multilingual(ctx)) {
const int lang_id = whisper_lang_id(params.language);
int lang_id = whisper_lang_id(params.language);
if(lang_id<0)
{
lang_id = 0; //default to english
}
state->lang_id = lang_id;
prompt_init.push_back(whisper_token_lang(ctx, lang_id));
if (params.translate) {
+3 -2
View File
@@ -217,6 +217,7 @@ whisper_generation_outputs whispertype_generate(const whisper_generation_inputs
const std::string b64data = std::string(inputs.audio_data);
const std::string initprompt = std::string(inputs.prompt);
const std::string langcode = std::string(inputs.langcode);
std::vector<float> pcmf32; // mono-channel F32 PCM
std::vector<std::vector<float>> pcmf32s; // stereo-channel F32 PCM
@@ -236,7 +237,7 @@ whisper_generation_outputs whispertype_generate(const whisper_generation_inputs
wparams.print_timestamps = false;
wparams.print_special = false;
wparams.translate = false;
wparams.language = "auto";
wparams.language = langcode.c_str();
wparams.detect_language = false;
wparams.n_threads = 4;
wparams.n_max_text_ctx = wparams.n_max_text_ctx;
@@ -248,7 +249,7 @@ whisper_generation_outputs whispertype_generate(const whisper_generation_inputs
wparams.split_on_word = false;
wparams.audio_ctx = 0;
wparams.speed_up = false;
wparams.debug_mode = false;
wparams.debug_mode = (whisperdebugmode==1);
wparams.tdrz_enable = false;
wparams.suppress_regex = nullptr;
wparams.suppress_non_speech_tokens = inputs.suppress_non_speech;