@@ -46,6 +46,8 @@ void OnlineASR::insertAudioChunk(std::span<const float> audio) {
4646ProcessResult 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 }
0 commit comments