diff --git a/android/src/main/jni.cpp b/android/src/main/jni.cpp index 665d17e..360eb3d 100644 --- a/android/src/main/jni.cpp +++ b/android/src/main/jni.cpp @@ -236,12 +236,12 @@ struct whisper_full_params createFullParams(JNIEnv *env, jobject options) { jstring prompt = readablemap::getString(env, options, "prompt", nullptr); if (prompt != nullptr) { params.initial_prompt = env->GetStringUTFChars(prompt, nullptr); - env->ReleaseStringUTFChars(prompt, params.initial_prompt); + env->DeleteLocalRef(prompt); } jstring language = readablemap::getString(env, options, "language", nullptr); if (language != nullptr) { params.language = env->GetStringUTFChars(language, nullptr); - env->ReleaseStringUTFChars(language, params.language); + env->DeleteLocalRef(language); } return params; } @@ -330,10 +330,10 @@ Java_com_rnwhisper_WhisperContext_createRealtimeTranscribeJob( vad.freq_thold = readablemap::getFloat(env, options, "vadFreqThold", 100.0f); jstring audio_output_path = readablemap::getString(env, options, "audioOutputPath", nullptr); - std::string *audio_output_path_str = nullptr; + const char* audio_output_path_str = nullptr; if (audio_output_path != nullptr) { - audio_output_path_str = new std::string(env->GetStringUTFChars(audio_output_path, nullptr)); - env->ReleaseStringUTFChars(audio_output_path, audio_output_path_str->c_str()); + audio_output_path_str = env->GetStringUTFChars(audio_output_path, nullptr); + env->DeleteLocalRef(audio_output_path); } job->set_realtime_params( vad, @@ -357,6 +357,7 @@ Java_com_rnwhisper_WhisperContext_finishRealtimeTranscribeJob( rnwhisper::job *job = rnwhisper::job_get(job_id); if (job->audio_output_path != nullptr) { + RNWHISPER_LOG_INFO("job->params.language: %s\n", job->params.language); std::vector slice_n_samples_vec; jint *slice_n_samples_arr = env->GetIntArrayElements(slice_n_samples, nullptr); slice_n_samples_vec = std::vector(slice_n_samples_arr, slice_n_samples_arr + env->GetArrayLength(slice_n_samples)); @@ -365,7 +366,7 @@ Java_com_rnwhisper_WhisperContext_finishRealtimeTranscribeJob( // TODO: Append in real time so we don't need to keep all slices & also reduce memory usage rnaudioutils::save_wav_file( rnaudioutils::concat_short_buffers(job->pcm_slices, slice_n_samples_vec), - *job->audio_output_path + job->audio_output_path ); } rnwhisper::job_remove(job_id); diff --git a/cpp/rn-audioutils.cpp b/cpp/rn-audioutils.cpp index ae7d3e4..292a704 100644 --- a/cpp/rn-audioutils.cpp +++ b/cpp/rn-audioutils.cpp @@ -61,6 +61,8 @@ void save_wav_file(const std::vector& raw, const std::string& file) { output.write(reinterpret_cast(data.data()), data.size()); output.close(); + + RNWHISPER_LOG_INFO("Saved audio file: %s\n", file.c_str()); } } // namespace rnaudioutils diff --git a/cpp/rn-whisper.cpp b/cpp/rn-whisper.cpp index e1855c8..31c549b 100644 --- a/cpp/rn-whisper.cpp +++ b/cpp/rn-whisper.cpp @@ -63,7 +63,7 @@ void job::set_realtime_params( vad_params params, int sec, int slice_sec, - std::string* output_path + const char* output_path ) { vad = params; if (vad.vad_ms < 2000) vad.vad_ms = 2000; diff --git a/cpp/rn-whisper.h b/cpp/rn-whisper.h index 7516a19..5daa90c 100644 --- a/cpp/rn-whisper.h +++ b/cpp/rn-whisper.h @@ -31,9 +31,9 @@ struct job { vad_params vad; int audio_sec = 0; int audio_slice_sec = 0; - std::string* audio_output_path = nullptr; + const char* audio_output_path = nullptr; std::vector pcm_slices; - void set_realtime_params(vad_params vad, int audio_sec, int audio_slice_sec, std::string* audio_output_path); + void set_realtime_params(vad_params vad, int sec, int slice_sec, const char* output_path); bool vad_simple(int slice_index, int n_samples, int n); void put_pcm_data(short* pcm, int slice_index, int n_samples, int n); float* pcm_slice_to_f32(int slice_index, int size); diff --git a/ios/RNWhisperContext.mm b/ios/RNWhisperContext.mm index 6e4e269..d7ab52e 100644 --- a/ios/RNWhisperContext.mm +++ b/ios/RNWhisperContext.mm @@ -119,7 +119,6 @@ - (void)prepareRealtime:(int)jobId options:(NSDictionary *)options { self->recordState.sliceNSamples.push_back(0); self->recordState.job = rnwhisper::job_new(jobId, [self createParams:options jobId:jobId]); - std::string audio_output_path = options[@"audioOutputPath"] != nil ? [options[@"audioOutputPath"] UTF8String] : ""; self->recordState.job->set_realtime_params( { .use_vad = options[@"useVad"] != nil ? [options[@"useVad"] boolValue] : false, @@ -129,7 +128,7 @@ - (void)prepareRealtime:(int)jobId options:(NSDictionary *)options { }, options[@"realtimeAudioSec"] != nil ? [options[@"realtimeAudioSec"] intValue] : 0, options[@"realtimeAudioSliceSec"] != nil ? [options[@"realtimeAudioSliceSec"] intValue] : 0, - options[@"audioOutputPath"] != nil ? &audio_output_path : nullptr + options[@"audioOutputPath"] != nil ? [options[@"audioOutputPath"] UTF8String] : nullptr ); self->recordState.isUseSlices = self->recordState.job->audio_slice_sec < self->recordState.job->audio_sec; @@ -227,7 +226,7 @@ - (void)finishRealtimeTranscribe:(RNWhisperContextRecordState*) state result:(NS // TODO: Append in real time so we don't need to keep all slices & also reduce memory usage rnaudioutils::save_wav_file( rnaudioutils::concat_short_buffers(state->job->pcm_slices, state->sliceNSamples), - *state->job->audio_output_path + state->job->audio_output_path ); } state->transcribeHandler(state->job->job_id, @"end", result);