Created
March 7, 2023 08:14
-
-
Save tgfjt/1ff78e36e1c16e8d9dfaf0ba781ee85e to your computer and use it in GitHub Desktop.
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
type SpeechRecognitionListener = (e: SpeechRecognitionEvent) => void; | |
export function createSpeechRecognition( | |
onResult: SpeechRecognitionListener, | |
): SpeechRecognition | undefined { | |
if (typeof window !== 'object') return; | |
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; | |
if (typeof SpeechRecognition !== 'undefined') { | |
const recognition = new SpeechRecognition(); | |
recognition.continuous = true; | |
recognition.addEventListener('result', onResult); | |
return recognition; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment