Skip to content

Commit bc1f43f

Browse files
committed
feat: use initial_prompt param instead of rn_whisper_convert_prompt
ref: ggml-org/whisper.cpp#645
1 parent b9f1e96 commit bc1f43f

File tree

4 files changed

+2
-40
lines changed

4 files changed

+2
-40
lines changed

android/src/main/jni/whisper/jni.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,7 @@ Java_com_rnwhisper_WhisperContext_fullTranscribe(
163163
params.temperature_inc = temperature_inc;
164164
}
165165
if (prompt != nullptr) {
166-
rn_whisper_convert_prompt(
167-
context,
168-
params,
169-
new std::string(env->GetStringUTFChars(prompt, nullptr))
170-
);
166+
params.initial_prompt = env->GetStringUTFChars(prompt, nullptr);
171167
}
172168

173169
params.encoder_begin_callback = [](struct whisper_context * /*ctx*/, struct whisper_state * /*state*/, void * user_data) {

cpp/rn-whisper.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,6 @@
66

77
extern "C" {
88

9-
void rn_whisper_convert_prompt(
10-
struct whisper_context * ctx,
11-
struct whisper_full_params params,
12-
std::string * prompt
13-
) {
14-
std::vector<whisper_token> prompt_tokens;
15-
if (!prompt->empty()) {
16-
prompt_tokens.resize(1024);
17-
prompt_tokens.resize(whisper_tokenize(ctx, prompt->c_str(), prompt_tokens.data(), prompt_tokens.size()));
18-
19-
// fprintf(stderr, "\n");
20-
// fprintf(stderr, "initial prompt: '%s'\n", prompt->c_str());
21-
// fprintf(stderr, "initial tokens: [ ");
22-
// for (int i = 0; i < (int) prompt_tokens.size(); ++i) {
23-
// fprintf(stderr, "%d ", prompt_tokens[i]);
24-
// }
25-
// fprintf(stderr, "]\n");
26-
27-
params.prompt_tokens = prompt_tokens.data();
28-
params.prompt_n_tokens = prompt_tokens.size();
29-
}
30-
}
31-
329
std::unordered_map<int, bool> abort_map;
3310

3411
bool* rn_whisper_assign_abort_map(int job_id) {

cpp/rn-whisper.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
extern "C" {
66
#endif
77

8-
void rn_whisper_convert_prompt(
9-
struct whisper_context * ctx,
10-
struct whisper_full_params params,
11-
std::string * prompt
12-
);
13-
148
bool* rn_whisper_assign_abort_map(int job_id);
159
void rn_whisper_remove_abort_map(int job_id);
1610
void rn_whisper_abort_transcribe(int job_id);

ios/RNWhisperContext.mm

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,7 @@ - (int)fullTranscribe:(int)jobId audioData:(float *)audioData audioDataCount:(in
354354
}
355355

356356
if (options[@"prompt"] != nil) {
357-
std::string *prompt = new std::string([options[@"prompt"] UTF8String]);
358-
rn_whisper_convert_prompt(
359-
self->ctx,
360-
params,
361-
prompt
362-
);
357+
params.initial_prompt = [options[@"prompt"] UTF8String];
363358
}
364359

365360
params.encoder_begin_callback = [](struct whisper_context * /*ctx*/, struct whisper_state * /*state*/, void * user_data) {

0 commit comments

Comments
 (0)