Gathering detailed insights and metrics for @intentface/react-speech-recognition
Gathering detailed insights and metrics for @intentface/react-speech-recognition
Gathering detailed insights and metrics for @intentface/react-speech-recognition
Gathering detailed insights and metrics for @intentface/react-speech-recognition
npm install @intentface/react-speech-recognition
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
4 Stars
29 Commits
3 Watching
1 Branches
3 Contributors
Updated on 22 Oct 2024
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
100%
4
Compared to previous week
Last month
-63.3%
40
Compared to previous month
Last year
0%
577
Compared to previous year
3
@intentface/react-speech-recognition
is a custom React hook that provides an easy-to-use interface for integrating speech recognition capabilities into your React applications. It leverages the native browser SpeechRecognition
API, allowing you to capture and process voice inputs with customizable options.
You can install this package via npm:
1npm install @intentface/react-speech-recognition
Here’s a basic example of how to use the useSpeechRecognition
hook in your React project:
1import React from "react"; 2import { useSpeechRecognition } from "@intentface/react-speech-recognition"; 3 4const SpeechComponent = () => { 5 const { 6 transcript, 7 interimTranscript, 8 isListening, 9 isFinal, 10 isSupported, 11 start, 12 stop, 13 error, 14 } = useSpeechRecognition({ 15 lang: "en-US", // Language for speech recognition (default is "en-US") 16 continuous: false, // Whether to keep listening or stop after receiving input 17 timeout: 5000, // Automatically stop listening after 5 seconds 18 onUpdate: ({ transcript, interimTranscript, isFinal }) => { 19 console.log("Update:", { transcript, interimTranscript, isFinal }); 20 }, 21 onError: ({ error }) => { 22 console.error("Speech recognition error:", error); 23 }, 24 }); 25 26 if (!isSupported) { 27 return <p>Your browser does not support Speech Recognition.</p>; 28 } 29 30 return ( 31 <div> 32 <h1>Speech Recognition Example</h1> 33 <p>Transcript: {transcript}</p> 34 <p>Interim Transcript: {interimTranscript}</p> 35 <p> 36 Status:{" "} 37 {isListening ? "Listening..." : isFinal ? "Finalized" : "Stopped"} 38 </p> 39 {error && <p>Error: {error.message}</p>} 40 <button onClick={start}>Start Listening</button> 41 <button onClick={stop}>Stop Listening</button> 42 </div> 43 ); 44}; 45 46export default SpeechComponent;
The useSpeechRecognition
hook returns an object containing the following properties:
transcript
: The final processed transcript of the recognized speech.interimTranscript
: The current intermediate transcript while speech is being processed.isListening
: A boolean indicating whether the recognition is currently active.isFinal
: A boolean indicating whether the current session has ended and the transcript is finalized.isSupported
: A boolean indicating whether the browser supports speech recognition.start()
: A function to start speech recognition.stop()
: A function to stop speech recognition.error
: An object containing any speech recognition errors that occurred.The hook accepts an options object with the following fields:
lang
: The language for speech recognition (default is "en-US"
).continuous
: If true
, the recognition will continue until stopped manually (default: false
).timeout
: Time in milliseconds to automatically stop recognition after no speech is detected (default: undefined
). If left undefined, browsers default behaviour is respected.onUpdate
: A callback function triggered when there is an update in the transcript. Receives an object with { transcript, interimTranscript, isFinal }
.onError
: A callback function triggered when an error occurs. Receives an object with { error }
.lang
option.onError
callback.This hook uses the native SpeechRecognition
API (also known as webkitSpeechRecognition
in some browsers). Below is a list of supported browsers:
Browser | Supported Versions |
---|---|
Chrome | Version 33+ |
Safari | Version 14+ |
Edge | Version 79+ |
Note: The
SpeechRecognition
API is not supported in Firefox or Internet Explorer. Please check for browser compatibility using theisSupported
flag provided by the hook.
Contributions are welcome! If you encounter any issues or have suggestions for improvements, feel free to create a pull request or file an issue in the repository.
Please remember to add the changes you are making by running
1npm run add-change
MIT
After finishing your feature normally, to automatically bump version number, update changelog and do an npm release:
npm run add-change
For more details about who we are, visit our website: Intentface.
No vulnerabilities found.
No security vulnerabilities found.