commcoach: add TTS audio lifecycle logging for mobile diagnosis
Made-with: Cursor
This commit is contained in:
parent
e91eca025a
commit
bbef615e0c
2 changed files with 21 additions and 2 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue