Skip to content

Commit 06d94e2

Browse files
author
litongjava
committed
change to whisper_full_parallel
1 parent 0561957 commit 06d94e2

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

stream_components_params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace stream_components {
3737

3838
struct service_params {
3939
int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
40+
int32_t n_processors = 4;
4041
bool speed_up = false;
4142
bool translate = false;
4243
bool no_fallback = false;

stream_components_service.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@ using namespace stream_components;
55

66
// -- WhisperService --
77

8-
WhisperService::WhisperService(const struct service_params &server_params,
8+
WhisperService::WhisperService(const struct service_params &service_params,
99
const struct audio_params &audio_params,
1010
const struct whisper_context_params &cparams)
11-
: server_params(server_params),
11+
: service_params(service_params),
1212
audio_params(audio_params),
13-
ctx(whisper_init_from_file_with_params(server_params.model.c_str(), cparams)) {
13+
ctx(whisper_init_from_file_with_params(service_params.model.c_str(), cparams)) {
1414
{
1515
fprintf(stderr, "\n");
1616
if (!whisper_is_multilingual(ctx)) {
17-
if (server_params.language != "en" || server_params.translate) {
18-
this->server_params.language = "en";
19-
this->server_params.translate = false;
17+
if (service_params.language != "en" || service_params.translate) {
18+
this->service_params.language = "en";
19+
this->service_params.translate = false;
2020
fprintf(stderr, "%s: WARNING: model is not multilingual, ignoring language and translation options\n",
2121
__func__);
2222
}
2323
}
2424
fprintf(stderr, "%s: serving with %d threads, lang = %s, task = %s, timestamps = %d ...\n",
2525
__func__,
26-
server_params.n_threads,
27-
server_params.language.c_str(),
28-
server_params.translate ? "translate" : "transcribe",
29-
server_params.no_timestamps ? 0 : 1);
26+
service_params.n_threads,
27+
service_params.language.c_str(),
28+
service_params.translate ? "translate" : "transcribe",
29+
service_params.no_timestamps ? 0 : 1);
3030

3131
// if (!params.use_vad) {
3232
// fprintf(stderr, "%s: n_new_line = %d, no_context = %d\n", __func__, n_new_line, params.no_context);
@@ -51,25 +51,26 @@ bool WhisperService::process(const float *samples, int sample_count) {
5151
wparams.max_tokens = 0;
5252
wparams.token_timestamps = true;
5353

54-
wparams.translate = server_params.translate;
54+
wparams.translate = service_params.translate;
5555
wparams.single_segment = !audio_params.use_vad;
56-
wparams.language = server_params.language.c_str();
57-
wparams.n_threads = server_params.n_threads;
56+
wparams.language = service_params.language.c_str();
57+
wparams.n_threads = service_params.n_threads;
5858

5959
wparams.audio_ctx = audio_params.audio_ctx;
60-
wparams.speed_up = server_params.speed_up;
60+
wparams.speed_up = service_params.speed_up;
6161

62-
wparams.tdrz_enable = server_params.tinydiarize; // [TDRZ]
62+
wparams.tdrz_enable = service_params.tinydiarize; // [TDRZ]
6363

6464
// disable temperature fallback
6565
//wparams.temperature_inc = -1.0f;
66-
wparams.temperature_inc = server_params.no_fallback ? 0.0f : wparams.temperature_inc;
66+
wparams.temperature_inc = service_params.no_fallback ? 0.0f : wparams.temperature_inc;
6767

68-
wparams.prompt_tokens = server_params.no_context ? nullptr : prompt_tokens.data();
69-
wparams.prompt_n_tokens = server_params.no_context ? 0 : prompt_tokens.size();
68+
wparams.prompt_tokens = service_params.no_context ? nullptr : prompt_tokens.data();
69+
wparams.prompt_n_tokens = service_params.no_context ? 0 : prompt_tokens.size();
7070

7171
// *** Run the actual inference!!! ***
72-
if (whisper_full(ctx, wparams, samples, sample_count) != 0) {
72+
//if (whisper_full(ctx, wparams, samples, sample_count) != 0) {
73+
if (whisper_full_parallel(ctx, wparams, samples, sample_count,service_params.n_processors) != 0) {
7374
return false;
7475
}
7576

@@ -84,7 +85,7 @@ bool WhisperService::process(const float *samples, int sample_count) {
8485
//pcmf32_old = std::vector<float>(pcmf32.end() - n_samples_keep, pcmf32.end());
8586

8687
// Add tokens of the last full length segment as the prompt
87-
if (!server_params.no_context) {
88+
if (!service_params.no_context) {
8889
prompt_tokens.clear();
8990

9091
const int n_segments = whisper_full_n_segments(ctx);

stream_components_service.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace stream_components {
2424

2525
bool process(const float *samples,int size);
2626

27-
service_params server_params;
27+
service_params service_params;
2828
audio_params audio_params;
2929

3030
struct whisper_context *ctx;

0 commit comments

Comments
 (0)