Spaces:
Sleeping
Sleeping
whisper : add whisper_full_lang_id() for getting the context lang (#461)
Browse files- whisper.cpp +8 -1
- whisper.h +3 -0
whisper.cpp
CHANGED
|
@@ -592,6 +592,8 @@ struct whisper_context {
|
|
| 592 |
|
| 593 |
mutable std::mt19937 rng; // used for sampling at t > 0.0
|
| 594 |
|
|
|
|
|
|
|
| 595 |
// [EXPERIMENTAL] token-level timestamps data
|
| 596 |
int64_t t_beg;
|
| 597 |
int64_t t_last;
|
|
@@ -3478,7 +3480,7 @@ int whisper_full(
|
|
| 3478 |
fprintf(stderr, "%s: failed to auto-detect language\n", __func__);
|
| 3479 |
return -3;
|
| 3480 |
}
|
| 3481 |
-
|
| 3482 |
params.language = whisper_lang_str(lang_id);
|
| 3483 |
|
| 3484 |
fprintf(stderr, "%s: auto-detected language: %s (p = %f)\n", __func__, params.language, probs[whisper_lang_id(params.language)]);
|
|
@@ -3575,6 +3577,7 @@ int whisper_full(
|
|
| 3575 |
std::vector<whisper_token> prompt_init = { whisper_token_sot(ctx) };
|
| 3576 |
if (whisper_is_multilingual(ctx)) {
|
| 3577 |
const int lang_id = whisper_lang_id(params.language);
|
|
|
|
| 3578 |
prompt_init.push_back(whisper_token_lang(ctx, lang_id));
|
| 3579 |
if (params.translate) {
|
| 3580 |
prompt_init.push_back(whisper_token_translate());
|
|
@@ -4295,6 +4298,10 @@ int whisper_full_n_segments(struct whisper_context * ctx) {
|
|
| 4295 |
return ctx->result_all.size();
|
| 4296 |
}
|
| 4297 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4298 |
int64_t whisper_full_get_segment_t0(struct whisper_context * ctx, int i_segment) {
|
| 4299 |
return ctx->result_all[i_segment].t0;
|
| 4300 |
}
|
|
|
|
| 592 |
|
| 593 |
mutable std::mt19937 rng; // used for sampling at t > 0.0
|
| 594 |
|
| 595 |
+
int lang_id;
|
| 596 |
+
|
| 597 |
// [EXPERIMENTAL] token-level timestamps data
|
| 598 |
int64_t t_beg;
|
| 599 |
int64_t t_last;
|
|
|
|
| 3480 |
fprintf(stderr, "%s: failed to auto-detect language\n", __func__);
|
| 3481 |
return -3;
|
| 3482 |
}
|
| 3483 |
+
ctx->lang_id = lang_id;
|
| 3484 |
params.language = whisper_lang_str(lang_id);
|
| 3485 |
|
| 3486 |
fprintf(stderr, "%s: auto-detected language: %s (p = %f)\n", __func__, params.language, probs[whisper_lang_id(params.language)]);
|
|
|
|
| 3577 |
std::vector<whisper_token> prompt_init = { whisper_token_sot(ctx) };
|
| 3578 |
if (whisper_is_multilingual(ctx)) {
|
| 3579 |
const int lang_id = whisper_lang_id(params.language);
|
| 3580 |
+
ctx->lang_id = lang_id;
|
| 3581 |
prompt_init.push_back(whisper_token_lang(ctx, lang_id));
|
| 3582 |
if (params.translate) {
|
| 3583 |
prompt_init.push_back(whisper_token_translate());
|
|
|
|
| 4298 |
return ctx->result_all.size();
|
| 4299 |
}
|
| 4300 |
|
| 4301 |
+
int whisper_full_lang_id(struct whisper_context * ctx) {
|
| 4302 |
+
return ctx->lang_id;
|
| 4303 |
+
}
|
| 4304 |
+
|
| 4305 |
int64_t whisper_full_get_segment_t0(struct whisper_context * ctx, int i_segment) {
|
| 4306 |
return ctx->result_all[i_segment].t0;
|
| 4307 |
}
|
whisper.h
CHANGED
|
@@ -330,6 +330,9 @@ extern "C" {
|
|
| 330 |
// A segment can be a few words, a sentence, or even a paragraph.
|
| 331 |
WHISPER_API int whisper_full_n_segments(struct whisper_context * ctx);
|
| 332 |
|
|
|
|
|
|
|
|
|
|
| 333 |
// Get the start and end time of the specified segment.
|
| 334 |
WHISPER_API int64_t whisper_full_get_segment_t0(struct whisper_context * ctx, int i_segment);
|
| 335 |
WHISPER_API int64_t whisper_full_get_segment_t1(struct whisper_context * ctx, int i_segment);
|
|
|
|
| 330 |
// A segment can be a few words, a sentence, or even a paragraph.
|
| 331 |
WHISPER_API int whisper_full_n_segments(struct whisper_context * ctx);
|
| 332 |
|
| 333 |
+
// Language id associated with the current context
|
| 334 |
+
WHISPER_API int whisper_full_lang_id(struct whisper_context * ctx);
|
| 335 |
+
|
| 336 |
// Get the start and end time of the specified segment.
|
| 337 |
WHISPER_API int64_t whisper_full_get_segment_t0(struct whisper_context * ctx, int i_segment);
|
| 338 |
WHISPER_API int64_t whisper_full_get_segment_t1(struct whisper_context * ctx, int i_segment);
|