Created
August 10, 2021 15:08
-
-
Save chetanraj/62d8f78b1e601663325aea57917c1316 to your computer and use it in GitHub Desktop.
useSpeechRecognition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import SpeechRecognition, { useSpeechRecognition } from 'react-speech-recognition'; | |
const Dictaphone = () => { | |
const { | |
transcript, | |
listening, | |
resetTranscript, | |
browserSupportsSpeechRecognition | |
} = useSpeechRecognition(); | |
if (!browserSupportsSpeechRecognition) { | |
return <span>Browser doesn't support speech recognition.</span>; | |
} | |
return ( | |
<div> | |
<p>Microphone: {listening ? 'on' : 'off'}</p> | |
<button onClick={SpeechRecognition.startListening}>Start</button> | |
<button onClick={SpeechRecognition.stopListening}>Stop</button> | |
<button onClick={resetTranscript}>Reset</button> | |
<p>{transcript}</p> | |
</div> | |
); | |
}; | |
export default Dictaphone; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment