diff --git a/source/speech/manager.py b/source/speech/manager.py index 78f0fad5257..0815c63a327 100644 --- a/source/speech/manager.py +++ b/source/speech/manager.py @@ -336,12 +336,15 @@ def _removeCompletedFromQueue(self, index): return False, False for seqIndex, seq in enumerate(self._curPriQueue.pendingSequences): lastCommand = seq[-1] if isinstance(seq, list) else None - if isinstance(lastCommand, IndexCommand) and index >= lastCommand.index: - endOfUtterance = isinstance(self._curPriQueue.pendingSequences[seqIndex + 1][0], EndUtteranceCommand) - if endOfUtterance: - # Remove the EndUtteranceCommand as well. - seqIndex += 1 - break # Found it! + if isinstance(lastCommand, IndexCommand): + if index > lastCommand.index: + log.debugWarning(f"Reached speech index {index :d}, but index {lastCommand.index :d} never handled") + elif index == lastCommand.index: + endOfUtterance = isinstance(self._curPriQueue.pendingSequences[seqIndex + 1][0], EndUtteranceCommand) + if endOfUtterance: + # Remove the EndUtteranceCommand as well. + seqIndex += 1 + break # Found it! else: # Unknown index. Probably from a previous utterance which was cancelled. return False, False