Keep voice mode listening after empty sends and transcription errors, and let failed sends be resent

This commit is contained in:
Chris Scott committed 2026-11-27 22:49:47 -05:00
1 parent 6904cfbc58
commit 99b8d854d4
5 files changed
+522 -40

No files matched your search

+34 -6
View File
@@ -18,7 +18,7 @@ export type VoicePhase =
export type VoicePauseReason = 'user' | 'background' | 'no-speech' | 'error'
export type VoiceFailureSource = 'capture' | 'send' | 'playback'
export type VoiceFailureSource = 'capture' | 'send' | 'playback' | 'transcription'
export type VoiceSessionStatus = SessionStatus['type']
@@ -46,6 +46,7 @@ export type VoiceConversationEvent =
| { type: 'turn-sent'; baselineId: string | null }
| { type: 'turn-started'; baselineId: string | null }
| { type: 'send-failed'; message: string }
| { type: 'resend'; busy: boolean; baselineId: string | null }
| { type: 'status'; busy: boolean }
| { type: 'speak-start' }
| { type: 'speech-ended' }
@@ -83,6 +84,7 @@ export interface VoiceConversationLabelInput {
error?: string | null
failureSource?: VoiceFailureSource | null
isStartingCapture?: boolean
canResend?: boolean
}
export function reduceVoiceConversation(
@@ -129,6 +131,25 @@ export function reduceVoiceConversation(
error: event.message,
failureSource: 'send',
}
case 'resend':
if (state.phase !== 'paused') return state
return event.busy
? {
...state,
phase: 'working',
sawBusy: true,
baselineId: event.baselineId,
pauseReason: null,
error: null,
failureSource: null,
}
: {
...state,
phase: 'sending',
pauseReason: null,
error: null,
failureSource: null,
}
case 'status':
if (state.phase !== 'working') return state
if (!event.busy || state.sawBusy) return state
@@ -267,7 +288,7 @@ export function isVoiceTurnComplete(input: VoiceTurnCompletionInput): boolean {
}
export function voiceConversationLabel(input: VoiceConversationLabelInput): string {
const { phase, pauseReason, pendingApproval, error, isStartingCapture } = input
const { phase, pauseReason, pendingApproval, error, failureSource, isStartingCapture } = input
switch (phase) {
case 'listening':
@@ -282,7 +303,13 @@ export function voiceConversationLabel(input: VoiceConversationLabelInput): stri
return isStartingCapture ? 'Starting…' : 'Adding to queue'
case 'paused':
if (pauseReason === 'no-speech') return "Didn't catch that"
if (pauseReason === 'error') return error?.trim() || 'Something went wrong'
if (pauseReason === 'error') {
if (failureSource === 'send') return "Couldn't send your message"
if (failureSource === 'capture') return 'Microphone problem'
if (failureSource === 'playback') return "Couldn't read the reply"
if (failureSource === 'transcription') return "Transcription isn't working"
return error?.trim() || 'Something went wrong'
}
return 'Paused'
case 'off':
return ''
@@ -318,9 +345,10 @@ export function voiceConversationHint(input: VoiceConversationLabelInput): strin
case 'paused':
if (pauseReason === 'no-speech') return 'Tap to talk'
if (pauseReason === 'error') {
return failureSource === 'capture'
? 'Allow microphone access, then tap to retry'
: 'Tap to retry'
if (failureSource === 'capture') return 'Allow microphone access, then tap to retry'
if (failureSource === 'send') return input.canResend ? 'Tap to resend' : 'Tap to retry'
if (failureSource === 'transcription') return 'Tap to try again'
return 'Tap to retry'
}
return isPlaybackPaused ? 'Tap to continue' : 'Tap to talk'
case 'off':