Skip to content

Commit

Permalink
Add chengePauseFor method for late setup. Add ignoreElapsedPause arg …
Browse files Browse the repository at this point in the history
…for _setupListenAndPause
  • Loading branch information
Ievgenii Kovtun authored and sowens-csd committed Jun 26, 2023
1 parent 3ac08be commit 1134d7d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions speech_to_text/lib/speech_to_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,13 @@ class SpeechToText {
if (_pauseFor == null || _pauseFor!.compareTo(pauseFor) != 0) {
_listenTimer?.cancel();
_listenTimer = null;
//Reset _lastSpeechEventAt for new pauseFor duration will count from now but not from start of listen
_lastSpeechEventAt = clock.now().millisecondsSinceEpoch;
_setupListenAndPause(pauseFor, _listenFor);
//Ignore elapsed pause for prevent immediately stop listen
_setupListenAndPause(pauseFor, _listenFor, ignoreElapsedPause: true);
}
}

void _setupListenAndPause(
Duration? initialPauseFor, Duration? initialListenFor) {
Duration? initialPauseFor, Duration? initialListenFor, {bool ignoreElapsedPause = false}) {
_pauseFor = null;
_listenFor = null;
if (null == initialPauseFor && null == initialListenFor) {
Expand All @@ -461,7 +460,7 @@ class SpeechToText {
var pauseFor = initialPauseFor;
var listenFor = initialListenFor;
if (null != pauseFor) {
var remainingMillis = pauseFor.inMilliseconds - _elapsedSinceSpeechEvent;
var remainingMillis = pauseFor.inMilliseconds - (ignoreElapsedPause ? 0 : _elapsedSinceSpeechEvent);
pauseFor = Duration(milliseconds: max(remainingMillis, 0));
}
if (null != listenFor) {
Expand Down

0 comments on commit 1134d7d

Please sign in to comment.