Skip to content

Commit 02113ff

Browse files
committed
Minor fixes
1 parent a91344c commit 02113ff

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

  • packages/react-native-executorch/common/rnexecutorch/models/speech_to_text/whisper

‎packages/react-native-executorch/common/rnexecutorch/models/speech_to_text/whisper/ASR.cpp‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
#include <algorithm>
2-
#include <array>
3-
#include <numeric>
4-
#include <random>
5-
61
#include "ASR.h"
72
#include "Constants.h"
83
#include "Params.h"
@@ -11,6 +6,12 @@
116
#include <rnexecutorch/data_processing/Numerical.h>
127
#include <rnexecutorch/data_processing/gzip.h>
138

9+
#include <algorithm>
10+
#include <array>
11+
#include <numeric>
12+
#include <random>
13+
#include <ranges>
14+
1415
namespace rnexecutorch::models::speech_to_text::whisper {
1516

1617
using executorch::runtime::etensor::ScalarType;
@@ -451,7 +452,7 @@ ASR::estimateWordLevelTimestampsLinear(std::span<const uint64_t> tokens,
451452
puncts += w.back();
452453
w.pop_back();
453454
}
454-
std::reverse(puncts.begin(), puncts.end());
455+
std::ranges::reverse(puncts);
455456

456457
// Add the core word.
457458
wordObjs.emplace_back(std::move(w), wStart, wEnd);

‎packages/react-native-executorch/common/rnexecutorch/models/speech_to_text/whisper/OnlineASR.cpp‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#include "OnlineASR.h"
2+
#include "Constants.h"
3+
#include "Params.h"
4+
#include "Utils.h"
25

36
#include <algorithm>
47
#include <iterator>
58
#include <ranges>
69
#include <utility>
710

8-
#include "Constants.h"
9-
#include "Params.h"
10-
#include "Utils.h"
11-
1211
namespace rnexecutorch::models::speech_to_text::whisper::stream {
1312

1413
OnlineASR::OnlineASR(const ASR *asr) : asr_(asr) {
@@ -41,8 +40,8 @@ void OnlineASR::insertAudioChunk(std::span<const float> audio) {
4140
}
4241

4342
ProcessResult OnlineASR::process(const DecodingOptions &options) {
44-
constexpr float kStreamSafeBufferMaxSamples =
45-
params::kStreamSafeBufferDuration * constants::kSamplingRate;
43+
constexpr size_t kStreamSafeBufferMaxSamples = static_cast<size_t>(
44+
params::kStreamSafeBufferDuration * constants::kSamplingRate);
4645

4746
std::vector<float> audioCopy;
4847

@@ -115,8 +114,7 @@ ProcessResult OnlineASR::process(const DecodingOptions &options) {
115114
// in a 'good' spot - where it will remove a significant audio chunk, yet
116115
// won't affect most recent, unfinished speech samples.
117116
size_t bufferSize = audioBuffer_.size();
118-
if (std::cmp_greater<size_t, size_t>(bufferSize,
119-
kStreamSafeBufferMaxSamples)) {
117+
if (bufferSize > kStreamSafeBufferMaxSamples) {
120118
auto newCommitted = commitAndClean(words);
121119

122120
committed.insert(committed.end(),

0 commit comments

Comments
 (0)