Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions composables/use-text-to-speech.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export function useTextToSpeech(options: TTSOptions = {}) {
const shouldResumeWhenOnline = ref(false)
const currentBufferIndex = ref<0 | 1>(0)
const idleBufferIndex = computed<0 | 1>(() => (currentBufferIndex.value === 0 ? 1 : 0))
const consecutiveAudioErrors = ref(0)
const MAX_CONSECUTIVE_ERRORS = 3
Comment on lines +64 to +65
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The consecutive error counter should be reset when users manually skip to a different segment (via skipForward, skipBackward, or skipToIndex). Currently, if there are 2 consecutive errors and the user skips forward, the next error would immediately pause playback, even though the user is trying a different segment. Consider resetting the counter when playCurrentElement() is called from user actions, or add a reset in the skip functions themselves.

Copilot uses AI. Check for mistakes.
const currentTTSSegmentIndex = ref(0)
const ttsSegments = ref<TTSSegment[]>([])
const currentTTSSegment = computed(() => {
Expand Down Expand Up @@ -210,6 +212,7 @@ export function useTextToSpeech(options: TTSOptions = {}) {

audio.onended = () => {
isTextToSpeechPlaying.value = false
consecutiveAudioErrors.value = 0
playNextElement()
}

Expand Down Expand Up @@ -243,6 +246,12 @@ export function useTextToSpeech(options: TTSOptions = {}) {
}

options.onError?.(error)
consecutiveAudioErrors.value += 1
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider logging the error count increment to help with debugging and monitoring. The current console.warn only appears after reaching the limit. Adding a log like "Audio error (count consecutiveAudioErrors/MAX_CONSECUTIVE_ERRORS)" would help track the error frequency.

Suggested change
consecutiveAudioErrors.value += 1
consecutiveAudioErrors.value += 1
console.warn(`Audio error (${consecutiveAudioErrors.value}/${MAX_CONSECUTIVE_ERRORS})`)

Copilot uses AI. Check for mistakes.
if (consecutiveAudioErrors.value >= MAX_CONSECUTIVE_ERRORS) {
console.warn(`TTS paused after ${MAX_CONSECUTIVE_ERRORS} consecutive audio errors`)
pauseTextToSpeech()
return
}
Comment on lines +249 to +254
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The consecutive error counter should also be reset when the user manually intervenes (e.g., when calling startTextToSpeech with an index, skipForward, skipBackward, or stopTextToSpeech). Currently, if a user experiences 2 errors, then manually skips to the next segment, they would only need 1 more error before TTS pauses, even though their manual action suggests they want to continue playing. Consider resetting the counter in user-initiated actions.

Copilot uses AI. Check for mistakes.
setTimeout(() => {
if (isTextToSpeechOn.value && isTextToSpeechPlaying.value) {
playNextElement()
Expand Down Expand Up @@ -342,6 +351,7 @@ export function useTextToSpeech(options: TTSOptions = {}) {
}

function resetAudio() {
consecutiveAudioErrors.value = 0
currentBufferIndex.value = 0
audioBuffers.value.forEach((audio) => {
if (audio) {
Expand Down
Loading