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 = () => {
|
recognition.onend = () => {
|
||||||
// #region agent log
|
// #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
|
// #endregion
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
|
if (coach.isTtsPlayingRef.current) return;
|
||||||
if (speechRecognitionRef.current === recognition) {
|
if (speechRecognitionRef.current === recognition) {
|
||||||
try { recognition.start(); } catch { speechRecognitionRef.current = null; }
|
try { recognition.start(); } catch { speechRecognitionRef.current = null; }
|
||||||
}
|
}
|
||||||
|
|
@ -269,6 +270,23 @@ export const CommcoachDossierView: React.FC = () => {
|
||||||
};
|
};
|
||||||
}, [activeTab, coach.session?.id, coach.isMuted]);
|
}, [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
|
// Reset mute when session ends
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!coach.session) coach.setMuted(false);
|
if (!coach.session) coach.setMuted(false);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue