commcoach: suspend speech recognition during TTS playback on mobile
Made-with: Cursor
This commit is contained in:
parent
bbef615e0c
commit
a5be7df834
1 changed files with 19 additions and 1 deletions
|
|
@ -227,9 +227,10 @@ export const CommcoachDossierView: React.FC = () => {
|
|||
|
||||
recognition.onend = () => {
|
||||
// #region agent log
|
||||
_dlog('REC-END', `cancelled=${cancelled} sameRef=${speechRecognitionRef.current===recognition}`);
|
||||
_dlog('REC-END', `cancelled=${cancelled} sameRef=${speechRecognitionRef.current===recognition} tts=${coach.isTtsPlayingRef.current}`);
|
||||
// #endregion
|
||||
if (cancelled) return;
|
||||
if (coach.isTtsPlayingRef.current) return;
|
||||
if (speechRecognitionRef.current === recognition) {
|
||||
try { recognition.start(); } catch { speechRecognitionRef.current = null; }
|
||||
}
|
||||
|
|
@ -269,6 +270,23 @@ export const CommcoachDossierView: React.FC = () => {
|
|||
};
|
||||
}, [activeTab, coach.session?.id, coach.isMuted]);
|
||||
|
||||
// On mobile, SpeechRecognition and Audio output conflict for the audio session.
|
||||
// Pause recognition while TTS plays, resume when it stops.
|
||||
useEffect(() => {
|
||||
if (!speechRecognitionRef.current) return;
|
||||
if (isTtsPlaying) {
|
||||
// #region agent log
|
||||
_dlog('REC-SUSPEND', 'tts started, stopping recognition');
|
||||
// #endregion
|
||||
try { speechRecognitionRef.current.stop(); } catch { /* ignore */ }
|
||||
} else {
|
||||
// #region agent log
|
||||
_dlog('REC-RESUME', 'tts ended, restarting recognition');
|
||||
// #endregion
|
||||
try { speechRecognitionRef.current.start(); } catch { /* ignore */ }
|
||||
}
|
||||
}, [isTtsPlaying, _dlog]);
|
||||
|
||||
// Reset mute when session ends
|
||||
useEffect(() => {
|
||||
if (!coach.session) coach.setMuted(false);
|
||||
|
|
|
|||
Loading…
Reference in a new issue