Skip to content

Fix StringIndexOutOfBoundsException on repeated pause (#638)#642

Open
aki1770-del wants to merge 1 commit into
dlutton:masterfrom
aki1770-del:fix/pause-substring-bounds
Open

Fix StringIndexOutOfBoundsException on repeated pause (#638)#642
aki1770-del wants to merge 1 commit into
dlutton:masterfrom
aki1770-del:fix/pause-substring-bounds

Conversation

@aki1770-del

Copy link
Copy Markdown

Fixes #638. lastProgress is relative to the current utterance but is not reset when pause trims pauseText — a second pause arriving before the next onRangeStart applies the stale index to the already-shortened string, throwing StringIndexOutOfBoundsException (reproducible: speak, wait past the halfway point, then pause twice quickly).

Change: coerce the index into the valid range, treat an at/past-end index as fully-spoken (clear pause state), and reset lastProgress after consuming it — consistent with the existing resets in stop and onDone.

Verification (build-verified locally before submitting; Android 11 / API 30 emulator, Google TTS):

  • Stock plugin: the reporter's exact crash reproduced — StringIndexOutOfBoundsException: length=44; index=119 at FlutterTtsPlugin.kt:363.
  • With this fix, the identical sequence plus 20× rapid play/pause/pause cycles and a 25-cycle pause/resume run over multi-byte Japanese text: no exception, no FATAL.

lastProgress is set by onRangeStart() relative to the current utterance
and is not consumed when pause trims pauseText. A repeated pause before
the next onRangeStart (e.g. rapid pause taps) re-applies the stale index
to the already-shortened text and crashes with
StringIndexOutOfBoundsException. Coerce the index into bounds, treat
fully-spoken as nothing-left-to-resume, and reset lastProgress once it
has been consumed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StringIndexOutOfBoundsException

1 participant