Spaces:
Sleeping
Sleeping
reset transcript
Browse files
src/components/speech-prompt/speech-prompt.tsx
CHANGED
|
@@ -10,21 +10,28 @@ function SpeechPrompt({
|
|
| 10 |
}: {
|
| 11 |
setPrompt: React.Dispatch<React.SetStateAction<string>>;
|
| 12 |
}) {
|
| 13 |
-
const {
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
const startListening = () =>
|
| 17 |
SpeechRecognition.startListening({ continuous: true });
|
| 18 |
|
| 19 |
-
if (!browserSupportsSpeechRecognition) {
|
| 20 |
-
return null;
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
| 24 |
useUpdateEffect(() => {
|
| 25 |
if (transcript) setPrompt(transcript);
|
| 26 |
}, [transcript]);
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
return (
|
| 29 |
<button
|
| 30 |
className={classNames(
|
|
|
|
| 10 |
}: {
|
| 11 |
setPrompt: React.Dispatch<React.SetStateAction<string>>;
|
| 12 |
}) {
|
| 13 |
+
const {
|
| 14 |
+
transcript,
|
| 15 |
+
listening,
|
| 16 |
+
browserSupportsSpeechRecognition,
|
| 17 |
+
resetTranscript,
|
| 18 |
+
} = useSpeechRecognition();
|
| 19 |
|
| 20 |
const startListening = () =>
|
| 21 |
SpeechRecognition.startListening({ continuous: true });
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
useUpdateEffect(() => {
|
| 24 |
if (transcript) setPrompt(transcript);
|
| 25 |
}, [transcript]);
|
| 26 |
|
| 27 |
+
useUpdateEffect(() => {
|
| 28 |
+
if (!listening) resetTranscript();
|
| 29 |
+
}, [listening]);
|
| 30 |
+
|
| 31 |
+
if (!browserSupportsSpeechRecognition) {
|
| 32 |
+
return null;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
return (
|
| 36 |
<button
|
| 37 |
className={classNames(
|