Skip to content

Commit

Permalink
chore(cpp): correct spaces of rn-whisper.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Nov 29, 2023
1 parent 1c0d893 commit 54fbf4a
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions cpp/rn-whisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@ extern "C" {
std::unordered_map<int, bool> abort_map;

bool* rn_whisper_assign_abort_map(int job_id) {
abort_map[job_id] = false;
return &abort_map[job_id];
abort_map[job_id] = false;
return &abort_map[job_id];
}

void rn_whisper_remove_abort_map(int job_id) {
if (abort_map.find(job_id) != abort_map.end()) {
abort_map.erase(job_id);
}
if (abort_map.find(job_id) != abort_map.end()) {
abort_map.erase(job_id);
}
}

void rn_whisper_abort_transcribe(int job_id) {
if (abort_map.find(job_id) != abort_map.end()) {
abort_map[job_id] = true;
}
if (abort_map.find(job_id) != abort_map.end()) {
abort_map[job_id] = true;
}
}

bool rn_whisper_transcribe_is_aborted(int job_id) {
if (abort_map.find(job_id) != abort_map.end()) {
return abort_map[job_id];
}
return false;
if (abort_map.find(job_id) != abort_map.end()) {
return abort_map[job_id];
}
return false;
}

void rn_whisper_abort_all_transcribe() {
for (auto it = abort_map.begin(); it != abort_map.end(); ++it) {
it->second = true;
}
for (auto it = abort_map.begin(); it != abort_map.end(); ++it) {
it->second = true;
}
}

void high_pass_filter(std::vector<float> & data, float cutoff, float sample_rate) {
Expand All @@ -52,41 +52,41 @@ void high_pass_filter(std::vector<float> & data, float cutoff, float sample_rate
}

bool rn_whisper_vad_simple(std::vector<float> & pcmf32, int sample_rate, int last_ms, float vad_thold, float freq_thold, bool verbose) {
const int n_samples = pcmf32.size();
const int n_samples_last = (sample_rate * last_ms) / 1000;
const int n_samples = pcmf32.size();
const int n_samples_last = (sample_rate * last_ms) / 1000;

if (n_samples_last >= n_samples) {
// not enough samples - assume no speech
return false;
}
if (n_samples_last >= n_samples) {
// not enough samples - assume no speech
return false;
}

if (freq_thold > 0.0f) {
high_pass_filter(pcmf32, freq_thold, sample_rate);
}
if (freq_thold > 0.0f) {
high_pass_filter(pcmf32, freq_thold, sample_rate);
}

float energy_all = 0.0f;
float energy_last = 0.0f;
float energy_all = 0.0f;
float energy_last = 0.0f;

for (int i = 0; i < n_samples; i++) {
energy_all += fabsf(pcmf32[i]);
for (int i = 0; i < n_samples; i++) {
energy_all += fabsf(pcmf32[i]);

if (i >= n_samples - n_samples_last) {
energy_last += fabsf(pcmf32[i]);
if (i >= n_samples - n_samples_last) {
energy_last += fabsf(pcmf32[i]);
}
}
}

energy_all /= n_samples;
energy_last /= n_samples_last;
energy_all /= n_samples;
energy_last /= n_samples_last;

if (verbose) {
fprintf(stderr, "%s: energy_all: %f, energy_last: %f, vad_thold: %f, freq_thold: %f\n", __func__, energy_all, energy_last, vad_thold, freq_thold);
}
if (verbose) {
fprintf(stderr, "%s: energy_all: %f, energy_last: %f, vad_thold: %f, freq_thold: %f\n", __func__, energy_all, energy_last, vad_thold, freq_thold);
}

if (energy_last > vad_thold*energy_all) {
return false;
}
if (energy_last > vad_thold*energy_all) {
return false;
}

return true;
return true;
}

}
}

0 comments on commit 54fbf4a

Please sign in to comment.