Skip to content

Instantly share code, notes, and snippets.

@chetanraj
Created August 10, 2021 15:08
Show Gist options
  • Save chetanraj/62d8f78b1e601663325aea57917c1316 to your computer and use it in GitHub Desktop.
Save chetanraj/62d8f78b1e601663325aea57917c1316 to your computer and use it in GitHub Desktop.
useSpeechRecognition
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