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 = () => {
if (!isRecording) {
audioChunksRef.current = [];
mediaRecorderRef.current.start();
setIsRecording(true);
monitorSilence();
} else {
const startRecording = () => {
if (!isRecording && mediaRecorderRef.current) {
audioChunksRef.current = [];
mediaRecorderRef.current.start();
setIsRecording(true);
monitorSilence();
}
};
const stopRecording = () => {
if (isRecording && mediaRecorderRef.current) {
mediaRecorderRef.current.stop();
setIsRecording(false);
}
};
return (
<div className="app-container">
@ -299,10 +304,14 @@ Teacher: Good job! How about Magic something special and powerful.
<div className="button-container">
<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'}`}
>
{isRecording ? 'ฉันพูดเสร็จแล้ว' : 'พูด'}
{isRecording ? 'กำลังพูด...' : 'กดค้างเพื่อพูด'}
</button>
</div>
</div>