Skip to content

Commit 4782eda

Browse files
committed
Rebase with other PR changes
1 parent b8cf8fa commit 4782eda

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ void OnlineASR::insertAudioChunk(std::span<const float> audio) {
4646
ProcessResult OnlineASR::process(const StreamingOptions &options) {
4747
constexpr size_t kStreamSafeBufferMaxSamples = static_cast<size_t>(
4848
params::kStreamSafeBufferDuration * constants::kSamplingRate);
49+
constexpr size_t kSafetyMarginSamples = static_cast<size_t>(
50+
params::kStreamSafetyThreshold * constants::kSamplingRate);
4951

5052
std::vector<float> audioCopy;
5153

@@ -69,9 +71,9 @@ ProcessResult OnlineASR::process(const StreamingOptions &options) {
6971
if (speechSegments.empty()) {
7072
// Extra cleanup to speed-up future processing by removing silence.
7173
if (audioCopy.size() > params::kVadDeadSamplesRemovalSamples) {
72-
std::scoped_lock<std::mutex> lock(streamingMutex);
74+
std::scoped_lock lock(streamingMutex);
7375
size_t cut = std::min(params::kVadDeadSamplesRemovalSamples -
74-
params::kStreamSafetyThresholdSamples,
76+
kSafetyMarginSamples,
7577
audioBuffer_.size());
7678
audioBuffer_.erase(audioBuffer_.begin(), audioBuffer_.begin() + cut);
7779
}
@@ -94,7 +96,7 @@ ProcessResult OnlineASR::process(const StreamingOptions &options) {
9496
} else {
9597
// Speech ended beyond margin. Commit existing transcript and clear
9698
// buffer.
97-
std::scoped_lock<std::mutex> lock(streamingMutex);
99+
std::scoped_lock lock(streamingMutex);
98100
std::vector<Word> committed = std::move(memory_.transcript);
99101
memory_.transcript.clear();
100102
memory_.eos.clear();
@@ -227,7 +229,7 @@ std::vector<Word> OnlineASR::commitAndClean(std::vector<Word> &transcript) {
227229
// recorded any speech. In this case we can safely cut the maximum amount of
228230
// audio data.
229231
if (memory_.eos.empty()) {
230-
size_t cut = bufferSize - params::kStreamSafetyThresholdSamples;
232+
size_t cut = bufferSize - kSafetyMarginSamples;
231233

232234
audioBuffer_.erase(audioBuffer_.begin(), audioBuffer_.begin() + cut);
233235
}

‎packages/react-native-executorch/common/rnexecutorch/models/speech_to_text/whisper/Params.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,13 @@ constexpr inline float kStreamMaxDuration =
2525
* cut is performed. Acts as the lower bound on what survives a cleanup.
2626
*/
2727
constexpr inline float kStreamSafetyThreshold = 3.F; // [s]
28-
constexpr inline size_t kStreamSafetyThresholdSamples =
29-
kStreamSafetyThreshold * constants::kSamplingRate;
3028

3129
/**
3230
* Forced-cleanup threshold. Once the buffer grows past this duration we run
3331
* the EOS-anchored cleanup routine.
3432
*/
3533
constexpr inline float kStreamSafeBufferDuration =
3634
kStreamMaxDuration - kStreamSafetyThreshold; // [s]
37-
constexpr inline size_t kStreamSafeBufferSamples =
38-
kStreamSafeBufferDuration * constants::kSamplingRate;
39-
4035
/**
4136
* An estimate of the number of words spoken per second.
4237
* Used for estimating transcription progress and buffer management heuristics.

0 commit comments

Comments
 (0)