mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
fix(tts): let voice mode read replies aloud on iOS
iOS rejects play() outside a user gesture unless the same media element was already played inside one. Each chunk used a new Audio element, so replies in voice mode failed with "Reading the reply failed". - reuse one audio element for all external TTS playback - add tts.unlock(), which plays a short silent clip on that element, and call it from the voice mode start and orb taps - route every playback failure through failPlayback(message) and pass the message to onEnd so voice mode shows the underlying reason - report a blocked play() as "Audio playback was blocked by the browser"
This commit is contained in:
1 parent
10190940bd
commit
67cfd862b1
8 files changed
+354
-190
No files matched your search
@@ -543,12 +543,16 @@ export function useVoiceConversation(
|
||||
speakingIdRef.current = message.id
|
||||
spokenIdsRef.current.add(message.id)
|
||||
void latestRef.current.tts.speakMessage(message.id, message.text, {
|
||||
onEnd: (reason) => {
|
||||
onEnd: (reason, error) => {
|
||||
if (speakTokenRef.current !== token) return
|
||||
if (reason === 'error') {
|
||||
speakTokenRef.current += 1
|
||||
speakingIdRef.current = null
|
||||
dispatch({ type: 'error', message: REPLY_READ_FAILED_MESSAGE, source: 'playback' })
|
||||
dispatch({
|
||||
type: 'error',
|
||||
message: error ? `${REPLY_READ_FAILED_MESSAGE}: ${error}` : REPLY_READ_FAILED_MESSAGE,
|
||||
source: 'playback',
|
||||
})
|
||||
return
|
||||
}
|
||||
speakingIdRef.current = null
|
||||
@@ -706,6 +710,7 @@ export function useVoiceConversation(
|
||||
}
|
||||
const latest = latestRef.current
|
||||
if (latest.tts.isPlaying) latest.tts.stop()
|
||||
latest.tts.unlock()
|
||||
fireImpactHaptic()
|
||||
invalidateTurn()
|
||||
instructionEpochRef.current += 1
|
||||
@@ -851,6 +856,7 @@ export function useVoiceConversation(
|
||||
const tapOrb = useCallback(() => {
|
||||
const phase = phaseRef.current
|
||||
const latest = latestRef.current
|
||||
latest.tts.unlock()
|
||||
switch (phase) {
|
||||
case 'listening':
|
||||
void endTurnRef.current?.()
|
||||
|
||||
Reference in new issue
Block a user