OpenVision icon indicating copy to clipboard operation
OpenVision copied to clipboard

Speak a failed cloud-TTS sentence with the Apple voice

Open raphaelbarreiros opened this issue 2 months ago • 1 comments

In #61 the cloud voices (Grok and OpenAI) synthesize a reply sentence by sentence. When the request for one sentence fails (a 429, a timeout, or the phone going offline), that sentence is skipped and the error is only recorded in lastFailure. The rest of the reply still plays, so the user just hears a gap and has no idea part of the answer was lost.

A better fallback would be to speak the failed sentence with the Apple system voice (TTSService). The catch is ordering: the fallback should only start after the cloud player has finished the clips queued before that sentence, otherwise the two audio paths play over each other. If that turns out to be too fiddly, a simpler option is to finish the reply with a short spoken notice that part of it couldn't be read out.

This was agreed as a follow-up in the #61 review, so the PR could land without it.

raphaelbarreiros avatar Oct 02 '26 20:10 raphaelbarreiros

Thanks for writing this up. Labelling it help-wanted; @raphaelbarreiros you're the natural owner if you want it, otherwise it's open to anyone.

A suggested shape that avoids the ordering problem entirely, because it reuses the sequencing CloudTTSService already has:

  • The drainer plays clips strictly in queue order and already knows when it reaches a failed slot (synthesize returned nil). Instead of continue-ing past it, treat that slot as a third clip kind: pause the drainer, hand the sentence text to TTSService (Apple), await its completion callback, then resume the cloud queue. One audio path at a time, no races, and the clips queued after it keep synthesizing in the background during the fallback.
  • Keep isSpeaking true across the fallback so the recognizer stays paused and barge-in still works; stop() must also cancel the in-progress Apple utterance.
  • Offline case: if two consecutive slots fail, switch the rest of the reply to Apple outright rather than alternating voices per sentence.
  • The mixed voice mid-reply will sound odd, but it is strictly better than a silent hole; the spoken-notice option is a fine fallback if the Apple engine itself is unavailable.

Acceptance: with the cloud endpoint made to fail on sentence 2 of a 4-sentence reply, all four sentences are heard in order, sentence 2 in the Apple voice, nothing overlaps, and a barge-in during sentence 2 stops everything.

rayl15 avatar Oct 03 '26 03:10 rayl15