switch to push-to-talk
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Late Night Defender 2025-05-26 16:29:38 +07:00
parent 95318b86d4
commit 378b62a42c

View file

@ -254,18 +254,23 @@ Teacher: Good job! How about Magic something special and powerful.
}); });
}; };
const toggleRecording = () => { const startRecording = () => {
if (!isRecording) { if (!isRecording && mediaRecorderRef.current) {
audioChunksRef.current = []; audioChunksRef.current = [];
mediaRecorderRef.current.start(); mediaRecorderRef.current.start();
setIsRecording(true); setIsRecording(true);
monitorSilence(); monitorSilence();
} else { }
};
const stopRecording = () => {
if (isRecording && mediaRecorderRef.current) {
mediaRecorderRef.current.stop(); mediaRecorderRef.current.stop();
setIsRecording(false); setIsRecording(false);
} }
}; };
return ( return (
<div className="app-container"> <div className="app-container">
@ -299,10 +304,14 @@ Teacher: Good job! How about Magic something special and powerful.
<div className="button-container"> <div className="button-container">
<button <button
onClick={toggleRecording} onMouseDown={startRecording}
onMouseUp={stopRecording}
onMouseLeave={stopRecording} // Ensures it stops if mouse leaves the button
onTouchStart={startRecording}
onTouchEnd={stopRecording}
className={`control-button ${isRecording ? 'recording' : 'idle'}`} className={`control-button ${isRecording ? 'recording' : 'idle'}`}
> >
{isRecording ? 'ฉันพูดเสร็จแล้ว' : 'พูด'} {isRecording ? 'กำลังพูด...' : 'กดค้างเพื่อพูด'}
</button> </button>
</div> </div>
</div> </div>