commcoach: add TTS audio lifecycle logging for mobile diagnosis

Made-with: Cursor
This commit is contained in:
ValueOn AG 2026-03-06 14:20:42 +01:00
parent e91eca025a
commit bbef615e0c
2 changed files with 21 additions and 2 deletions

View file

@ -124,17 +124,35 @@ export function useCommcoach(): CommcoachHookReturn {
try {
const audio = new Audio(`data:audio/mp3;base64,${audioB64}`);
currentAudioRef.current = audio;
// #region agent log
audio.onpause = () => { (window as any).__dlog?.('TTS-PAUSE', `t=${audio.currentTime.toFixed(1)} dur=${audio.duration.toFixed(1)}`); };
// #endregion
audio.onended = () => {
// #region agent log
(window as any).__dlog?.('TTS-ENDED', `dur=${audio.duration.toFixed(1)}`);
// #endregion
currentAudioRef.current = null;
isTtsPlayingRef.current = false;
};
audio.play().catch(() => { isTtsPlayingRef.current = false; });
audio.play().then(() => {
// #region agent log
(window as any).__dlog?.('TTS-PLAY', `dur=${audio.duration.toFixed(1)}`);
// #endregion
}).catch((e) => {
// #region agent log
(window as any).__dlog?.('TTS-PLAY-ERR', e?.message || 'unknown');
// #endregion
isTtsPlayingRef.current = false;
});
} catch {
isTtsPlayingRef.current = false;
}
}, []);
const stopTts = useCallback(() => {
// #region agent log
(window as any).__dlog?.('STOP-TTS', `playing=${isTtsPlayingRef.current} hasAudio=${!!currentAudioRef.current}`);
// #endregion
if (currentAudioRef.current) {
currentAudioRef.current.pause();
}

View file

@ -61,8 +61,9 @@ export const CommcoachDossierView: React.FC = () => {
const ts = `${t.getMinutes()}:${String(t.getSeconds()).padStart(2,'0')}.${String(t.getMilliseconds()).padStart(3,'0')}`;
const entry = `[${ts}] ${tag}${info ? ' ' + info : ''}`;
debugLogsRef.current.push(entry);
if (debugLogsRef.current.length > 60) debugLogsRef.current.shift();
if (debugLogsRef.current.length > 80) debugLogsRef.current.shift();
}, []);
useEffect(() => { (window as any).__dlog = _dlog; return () => { delete (window as any).__dlog; }; }, [_dlog]);
// #endregion
// Auto-select first context