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 {
|
try {
|
||||||
const audio = new Audio(`data:audio/mp3;base64,${audioB64}`);
|
const audio = new Audio(`data:audio/mp3;base64,${audioB64}`);
|
||||||
currentAudioRef.current = audio;
|
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 = () => {
|
audio.onended = () => {
|
||||||
|
// #region agent log
|
||||||
|
(window as any).__dlog?.('TTS-ENDED', `dur=${audio.duration.toFixed(1)}`);
|
||||||
|
// #endregion
|
||||||
currentAudioRef.current = null;
|
currentAudioRef.current = null;
|
||||||
isTtsPlayingRef.current = false;
|
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 {
|
} catch {
|
||||||
isTtsPlayingRef.current = false;
|
isTtsPlayingRef.current = false;
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const stopTts = useCallback(() => {
|
const stopTts = useCallback(() => {
|
||||||
|
// #region agent log
|
||||||
|
(window as any).__dlog?.('STOP-TTS', `playing=${isTtsPlayingRef.current} hasAudio=${!!currentAudioRef.current}`);
|
||||||
|
// #endregion
|
||||||
if (currentAudioRef.current) {
|
if (currentAudioRef.current) {
|
||||||
currentAudioRef.current.pause();
|
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 ts = `${t.getMinutes()}:${String(t.getSeconds()).padStart(2,'0')}.${String(t.getMilliseconds()).padStart(3,'0')}`;
|
||||||
const entry = `[${ts}] ${tag}${info ? ' ' + info : ''}`;
|
const entry = `[${ts}] ${tag}${info ? ' ' + info : ''}`;
|
||||||
debugLogsRef.current.push(entry);
|
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
|
// #endregion
|
||||||
|
|
||||||
// Auto-select first context
|
// Auto-select first context
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue