Spaces:
Running
Running
Andy Maloney
commited on
Commit
·
763a6f3
1
Parent(s):
2117da6
whisper : use ranged-based for loops for readability
Browse files- whisper.cpp +15 -15
whisper.cpp
CHANGED
|
@@ -2472,12 +2472,12 @@ int whisper_lang_auto_detect(
|
|
| 2472 |
}
|
| 2473 |
|
| 2474 |
{
|
| 2475 |
-
for (
|
| 2476 |
if (lang_probs) {
|
| 2477 |
-
lang_probs[
|
| 2478 |
}
|
| 2479 |
|
| 2480 |
-
//printf("%s: lang %2d (%3s): %f\n", __func__,
|
| 2481 |
}
|
| 2482 |
}
|
| 2483 |
|
|
@@ -3225,17 +3225,17 @@ int whisper_full_parallel(
|
|
| 3225 |
for (int i = 0; i < n_processors - 1; ++i) {
|
| 3226 |
auto & results_i = ctxs[i].result_all;
|
| 3227 |
|
| 3228 |
-
for (
|
| 3229 |
// correct the segment timestamp taking into account the offset
|
| 3230 |
-
|
| 3231 |
-
|
| 3232 |
|
| 3233 |
// make sure that segments are not overlapping
|
| 3234 |
if (!ctx->result_all.empty()) {
|
| 3235 |
-
|
| 3236 |
}
|
| 3237 |
|
| 3238 |
-
ctx->result_all.push_back(std::move(
|
| 3239 |
|
| 3240 |
// call the new_segment_callback for each segment
|
| 3241 |
if (params.new_segment_callback) {
|
|
@@ -3330,18 +3330,18 @@ static int64_t sample_to_timestamp(int i_sample) {
|
|
| 3330 |
static float voice_length(const std::string & text) {
|
| 3331 |
float res = 0.0f;
|
| 3332 |
|
| 3333 |
-
for (
|
| 3334 |
-
if (
|
| 3335 |
res += 0.01f;
|
| 3336 |
-
} else if (
|
| 3337 |
res += 2.00f;
|
| 3338 |
-
} else if (
|
| 3339 |
res += 3.00f;
|
| 3340 |
-
} else if (
|
| 3341 |
res += 3.00f;
|
| 3342 |
-
} else if (
|
| 3343 |
res += 3.00f;
|
| 3344 |
-
} else if (
|
| 3345 |
res += 3.00f;
|
| 3346 |
} else {
|
| 3347 |
res += 1.00f;
|
|
|
|
| 2472 |
}
|
| 2473 |
|
| 2474 |
{
|
| 2475 |
+
for (const auto & prob : probs_id) {
|
| 2476 |
if (lang_probs) {
|
| 2477 |
+
lang_probs[prob.second] = prob.first;
|
| 2478 |
}
|
| 2479 |
|
| 2480 |
+
//printf("%s: lang %2d (%3s): %f\n", __func__, prob.second, whisper_lang_str(prob.second), prob.first);
|
| 2481 |
}
|
| 2482 |
}
|
| 2483 |
|
|
|
|
| 3225 |
for (int i = 0; i < n_processors - 1; ++i) {
|
| 3226 |
auto & results_i = ctxs[i].result_all;
|
| 3227 |
|
| 3228 |
+
for (auto & result : results_i) {
|
| 3229 |
// correct the segment timestamp taking into account the offset
|
| 3230 |
+
result.t0 += 100*((i + 1)*n_samples_per_processor)/WHISPER_SAMPLE_RATE + offset_t;
|
| 3231 |
+
result.t1 += 100*((i + 1)*n_samples_per_processor)/WHISPER_SAMPLE_RATE + offset_t;
|
| 3232 |
|
| 3233 |
// make sure that segments are not overlapping
|
| 3234 |
if (!ctx->result_all.empty()) {
|
| 3235 |
+
result.t0 = std::max(result.t0, ctx->result_all.back().t1);
|
| 3236 |
}
|
| 3237 |
|
| 3238 |
+
ctx->result_all.push_back(std::move(result));
|
| 3239 |
|
| 3240 |
// call the new_segment_callback for each segment
|
| 3241 |
if (params.new_segment_callback) {
|
|
|
|
| 3330 |
static float voice_length(const std::string & text) {
|
| 3331 |
float res = 0.0f;
|
| 3332 |
|
| 3333 |
+
for (char c : text) {
|
| 3334 |
+
if (c == ' ') {
|
| 3335 |
res += 0.01f;
|
| 3336 |
+
} else if (c == ',') {
|
| 3337 |
res += 2.00f;
|
| 3338 |
+
} else if (c == '.') {
|
| 3339 |
res += 3.00f;
|
| 3340 |
+
} else if (c == '!') {
|
| 3341 |
res += 3.00f;
|
| 3342 |
+
} else if (c == '?') {
|
| 3343 |
res += 3.00f;
|
| 3344 |
+
} else if (c >= '0' && c <= '9') {
|
| 3345 |
res += 3.00f;
|
| 3346 |
} else {
|
| 3347 |
res += 1.00f;
|