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
{{ message }}
This repository was archived by the owner on Jul 14, 2024. It is now read-only.
-[Installing the library](#installing-the-library)
15
+
-[Linking the library](#linking-the-library)
16
+
-[Auto link](#auto-link)
17
+
-[Link manually](#link-manually)
18
+
-[Prebuild Plugin](#prebuild-plugin)
19
+
-[How to use](#how-to-use)
20
+
-[Voice API](#voice-api)
21
+
-[Static](#static)
22
+
-[Events](#events)
23
+
-[Permissions](#permissions)
24
+
-[Contributors](#contributors)
15
25
16
-
npm i @pedrol2b/react-native-voice --save
17
-
```
26
+
### Getting Started
18
27
19
-
Link the iOS package
28
+
#### Installing the library
20
29
21
30
```sh
22
-
npx pod-install
31
+
yarn add @pedrol2b/react-native-voice
32
+
cd ios && pod install
23
33
```
24
34
25
-
## Table of contents
35
+
or
26
36
27
-
-[Table of contents](#table-of-contents)
28
-
-[Manually Link Android](#manually-link-android)
29
-
-[Manually Link iOS](#manually-link-ios)
30
-
-[Props](#props)
31
-
-[Example](#example)
32
-
-[Example](#example-1)
33
-
-[Android](#android)
34
-
-[iOS](#ios)
37
+
```sh
38
+
npm i @pedrol2b/react-native-voice
39
+
cd ios && pod install
40
+
```
35
41
36
-
<h2align="center">Linking</h2>
42
+
#### Linking the library
37
43
38
-
<palign="center">Manually or automatically link the NativeModule</p>
44
+
##### Auto link
39
45
40
46
```sh
41
47
react-native link @pedrol2b/react-native-voice
42
48
```
43
49
44
-
### Manually Link Android
50
+
##### Link manually
51
+
52
+
:apple:**iOS**
45
53
46
-
- In `android/setting.gradle`
54
+
How to link the library manually on iOS.
55
+
56
+
- Drag the `Voice.xcodeproj` from the `@pedrol2b/react-native-voice/ios` folder to the Libraries group on Xcode in your project. [Manual linking](https://reactnative.dev/docs/linking-libraries-ios.html)
57
+
58
+
- Click on your main project file (the one that represents the `.xcodeproj`) select Build Phases and drag the static library, `lib.Voice.a`, from the `Libraries/Voice.xcodeproj/Products` folder to Link Binary With Libraries
59
+
60
+
:robot:**android**
61
+
62
+
How to link the library manually on Android.
63
+
64
+
-`android/setting.gradle`
47
65
48
66
```gradle
49
67
...
50
68
include ':@react-native-voice_voice', ':app'
51
69
project(':@react-native-voice_voice').projectDir = new File(rootProject.projectDir, '../node_modules/@pedrol2b/react-native-voice/android')
52
70
```
53
71
54
-
-In `android/app/build.gradle`
72
+
-`android/app/build.gradle`
55
73
56
74
```gradle
57
75
...
@@ -61,7 +79,7 @@ dependencies {
61
79
}
62
80
```
63
81
64
-
-In `MainApplication.java`
82
+
-`MainApplication.java`
65
83
66
84
```java
67
85
@@ -84,17 +102,11 @@ public class MainActivity extends Activity implements ReactApplication {
84
102
}
85
103
```
86
104
87
-
### Manually Link iOS
88
-
89
-
- Drag the Voice.xcodeproj from the @pedrol2b/react-native-voice/ios folder to the Libraries group on Xcode in your poject. [Manual linking](https://reactnative.dev/docs/linking-libraries-ios.html)
90
-
91
-
- Click on your main project file (the one that represents the .xcodeproj) select Build Phases and drag the static library, lib.Voice.a, from the Libraries/Voice.xcodeproj/Products folder to Link Binary With Libraries
105
+
##### Prebuild Plugin
92
106
93
-
<h2align="center">Prebuild Plugin</h2>
107
+
> :warning: This package cannot be used in the "Expo Go" app because [it requires custom native code](https://docs.expo.io/workflow/customizing/).
94
108
95
-
> This package cannot be used in the "Expo Go" app because [it requires custom native code](https://docs.expo.io/workflow/customizing/).
96
-
97
-
After installing this npm package, add the [config plugin](https://docs.expo.io/guides/config-plugins/) to the [`plugins`](https://docs.expo.io/versions/latest/config/app/#plugins) array of your `app.json` or `app.config.js`:
109
+
After installing this package, add the [config plugin](https://docs.expo.io/guides/config-plugins/) to the [`plugins`](https://docs.expo.io/versions/latest/config/app/#plugins) array of your `app.json` or `app.config.js`:
98
110
99
111
```json
100
112
{
@@ -104,16 +116,13 @@ After installing this npm package, add the [config plugin](https://docs.expo.io/
104
116
}
105
117
```
106
118
107
-
Next, rebuild your app as described in the ["Adding custom native code"](https://docs.expo.io/workflow/customizing/) guide.
108
-
109
-
### Props
110
-
111
119
The plugin provides props for extra customization. Every time you change the props or plugins, you'll need to rebuild (and `prebuild`) the native app. If no extra properties are added, defaults will be used.
112
120
113
121
-`speechRecognition` (_string | false_): Sets the message for the `NSSpeechRecognitionUsageDescription` key in the `Info.plist` message. When undefined, a default permission message will be used. When `false`, the permission will be skipped.
122
+
114
123
-`microphone` (_string | false_): Sets the message for the `NSMicrophoneUsageDescription` key in the `Info.plist`. When undefined, a default permission message will be used. When `false`, the `android.permission.RECORD_AUDIO` will not be added to the `AndroidManifest.xml` and the iOS permission will be skipped.
115
124
116
-
### Example
125
+
Example
117
126
118
127
```json
119
128
{
@@ -129,11 +138,11 @@ The plugin provides props for extra customization. Every time you change the pro
129
138
}
130
139
```
131
140
132
-
<h2align="center">Usage</h2>
141
+
Next, rebuild your app as described in the ["Adding custom native code"](https://docs.expo.io/workflow/customizing/) guide.
133
142
134
-
<palign="center"><ahref="https://github.com/react-native-voice/voice/blob/master/example/src/VoiceTest.tsx">Full example for Android and iOS.</a></p>
143
+
### How to use
135
144
136
-
### Example
145
+
Example
137
146
138
147
```javascript
139
148
importVoicefrom'@pedrol2b/react-native-voice';
@@ -152,9 +161,9 @@ class VoiceTest extends Component {
152
161
}
153
162
```
154
163
155
-
<h2align="center">API</h2>
164
+
### Voice API
156
165
157
-
<palign="center">Static access to the Voice API.</p>
166
+
#### Static
158
167
159
168
**All methods _now_ return a `new Promise` for `async/await` compatibility.**
160
169
@@ -169,9 +178,9 @@ class VoiceTest extends Component {
169
178
| Voice.isRecognizing() | Return if the SpeechRecognizer is recognizing. | Android, iOS |
170
179
| Voice.getSpeechRecognitionServices() | Returns a list of the speech recognition engines available on the device. (Example: `['com.google.android.googlequicksearchbox']` if Google is the only one available.) | Android |
171
180
172
-
<h2align="center">Events</h2>
181
+
#### Events
173
182
174
-
<palign="center">Callbacks that are invoked when a native event emitted.</p>
183
+
Callbacks that are invoked when a native event emitted.
@@ -183,17 +192,32 @@ class VoiceTest extends Component {
183
192
| Voice.onSpeechPartialResults(event) | Invoked when any results are computed. |`{ value: [..., 'Partial speech recognized'] }`| Android, iOS |
184
193
| Voice.onSpeechVolumeChanged(event) | Invoked when pitch that is recognized changed. |`{ value: pitch in dB }`| Android |
185
194
186
-
<h2align="center">Permissions</h2>
195
+
#### Permissions
196
+
197
+
:apple:**iOS**
198
+
199
+
Need to include permissions for `NSMicrophoneUsageDescription` and `NSSpeechRecognitionUsageDescription` inside Info.plist for iOS. See the included `VoiceTest` for how to handle these cases.
200
+
201
+
```xml
202
+
<dict>
203
+
...
204
+
<key>NSMicrophoneUsageDescription</key>
205
+
<string>Description of why you require the use of the microphone</string>
206
+
<key>NSSpeechRecognitionUsageDescription</key>
207
+
<string>Description of why you require the use of the speech recognition</string>
208
+
...
209
+
</dict>
210
+
```
187
211
188
-
<palign="center">Arguably the most important part.</p>
212
+
Please see the documentation provided by ReactNative for this: [PermissionsAndroid](https://reactnative.dev/docs/permissionsandroid.html)
189
213
190
-
### Android
214
+
:robot:**android**
191
215
192
216
While the included `VoiceTest` app works without explicit permissions checks and requests, it may be necessary to add a permission request for `RECORD_AUDIO` for some configurations.
193
217
Since Android M (6.0), [user need to grant permission at runtime (and not during app installation)](https://developer.android.com/training/permissions/requesting.html).
194
218
By default, calling the `startSpeech` method will invoke `RECORD AUDIO` permission popup to the user. This can be disabled by passing `REQUEST_PERMISSIONS_AUTO: true` in the options argument.
195
219
196
-
If you're running an ejected expo/expokit app, you may run into issues with permissions on Android and get the following error `host.exp.exponent.MainActivity cannot be cast to com.facebook.react.ReactActivity startSpeech`. This can be resolved by prompting for permssion using the `expo-permission` package before starting recognition.
220
+
If you're running an ejected expo/expokit app, you may run into issues with permissions on Android and get the following error `host.exp.exponent.MainActivity cannot be cast to com.facebook.react.ReactActivity startSpeech`. This can be resolved by prompting for permission using the `expo-permission` package before starting recognition.
197
221
198
222
```js
199
223
import { Permissions } from"expo";
@@ -212,7 +236,7 @@ async componentDidMount() {
212
236
213
237
**Notes on Android**
214
238
215
-
Even after all the permissions are correct in Android, there is one last thing to make sure this libray is working fine on Android. Please make sure the device has Google Speech Recognizing Engine such as `com.google.android.googlequicksearchbox` by calling `Voice.getSpeechRecognitionServices()`. Since Android phones can be configured with so many options, even if a device has googlequicksearchbox engine, it could be configured to use other services. You can check which serivce is used for Voice Assistive App in following steps for most Android phones:
239
+
Even after all the permissions are correct in Android, there is one last thing to make sure this library is working fine on Android. Please make sure the device has Google Speech Recognizing Engine such as `com.google.android.googlequicksearchbox` by calling `Voice.getSpeechRecognitionServices()`. Since Android phones can be configured with so many options, even if a device has googlequicksearchbox engine, it could be configured to use other services. You can check which service is used for Voice Assistive App in following steps for most Android phones:
@@ -222,28 +246,7 @@ Above flow can vary depending on the Android models and manufactures. For Huawei
222
246
223
247
Please ask users to install [Google Search App](https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox&hl=en).
224
248
225
-
### iOS
226
-
227
-
Need to include permissions for `NSMicrophoneUsageDescription` and `NSSpeechRecognitionUsageDescription` inside Info.plist for iOS. See the included `VoiceTest` for how to handle these cases.
228
-
229
-
```xml
230
-
<dict>
231
-
...
232
-
<key>NSMicrophoneUsageDescription</key>
233
-
<string>Description of why you require the use of the microphone</string>
234
-
<key>NSSpeechRecognitionUsageDescription</key>
235
-
<string>Description of why you require the use of the speech recognition</string>
236
-
...
237
-
</dict>
238
-
```
239
-
240
-
Please see the documentation provided by ReactNative for this: [PermissionsAndroid](https://reactnative.dev/docs/permissionsandroid.html)
0 commit comments