You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+126Lines changed: 126 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,127 @@
1
1
# @intentface/react-speech-recognition
2
2
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.
4
+
5
+
## Installation
6
+
7
+
You can install this package via npm:
8
+
9
+
```bash
10
+
npm install @intentface/react-speech-recognition
11
+
```
12
+
13
+
## Usage
14
+
15
+
Here’s a basic example of how to use the `useSpeechRecognition` hook in your React project:
The `useSpeechRecognition` hook returns an object containing the following properties:
69
+
70
+
#### Returned Values
71
+
72
+
-`transcript`: The final processed transcript of the recognized speech.
73
+
-`interimTranscript`: The current intermediate transcript while speech is being processed.
74
+
-`isListening`: A boolean indicating whether the recognition is currently active.
75
+
-`isFinal`: A boolean indicating whether the current session has ended and the transcript is finalized.
76
+
-`isSupported`: A boolean indicating whether the browser supports speech recognition.
77
+
-`start()`: A function to start speech recognition.
78
+
-`stop()`: A function to stop speech recognition.
79
+
-`error`: An object containing any speech recognition errors that occurred.
80
+
81
+
#### Options
82
+
83
+
The hook accepts an options object with the following fields:
84
+
85
+
-`lang`: The language for speech recognition (default is `"en-US"`).
86
+
-`continuous`: If `true`, the recognition will continue until stopped manually (default: `false`).
87
+
-`timeout`: Time in milliseconds to automatically stop recognition after no speech is detected (default: `undefined`). If left _undefined_, browsers default behaviour is respected.
88
+
-`onUpdate`: A callback function triggered when there is an update in the transcript. Receives an object with `{ transcript, interimTranscript, isFinal }`.
89
+
-`onError`: A callback function triggered when an error occurs. Receives an object with `{ error }`.
90
+
91
+
### Features
92
+
93
+
-**Customizable Language**: Set the language of recognition with the `lang` option.
94
+
-**Continuous Listening**: Option to listen continuously for speech input.
95
+
-**Timeout Control**: Automatically stop recognition after a set period of inactivity.
96
+
-**Error Handling**: Receive error information via the `onError` callback.
97
+
-**Interim and Final Transcripts**: Access both the interim (in-progress) and final transcripts.
98
+
99
+
### Browser Compatibility
100
+
101
+
This hook uses the native `SpeechRecognition` API (also known as `webkitSpeechRecognition` in some browsers). Below is a list of supported browsers:
102
+
103
+
| Browser | Supported Versions |
104
+
| ------- | ------------------ |
105
+
| Chrome | Version 33+ |
106
+
| Safari | Version 14+ |
107
+
| Edge | Version 79+ |
108
+
109
+
> Note: The `SpeechRecognition` API is not supported in Firefox or Internet Explorer. Please check for browser compatibility using the `isSupported` flag provided by the hook.
110
+
111
+
### Contributing
112
+
113
+
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.
114
+
115
+
Please remember to add the changes you are making by running
116
+
117
+
```bash
118
+
npm run add-change
119
+
```
120
+
121
+
### License
122
+
123
+
MIT
124
+
3
125
## Dev
4
126
5
127
### Doing a release
@@ -11,3 +133,7 @@ After finishing your feature normally, to automatically bump version number, upd
11
133
3. Commit the changeset file(s) to your feature branch and push to Github
12
134
4. Create a PR normally, including the changeset file(s)
13
135
5. Eventually accept the PR called "Version Packages" created by the changeset bot
136
+
137
+
## About us
138
+
139
+
For more details about who we are, visit our website: [Intentface](https://www.intentface.com/).
0 commit comments