Skip to content

Commit

Permalink
fix: toc link
Browse files Browse the repository at this point in the history
  • Loading branch information
jamsch committed Nov 19, 2024
1 parent c0bcd84 commit 8d40629
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Patch Changes

- e4c54f1: Fixed handling of interim and final results on web
- d3d3d63: Separate microphone and recognizer permissions

## 1.0.0

Expand Down
88 changes: 81 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ expo-speech-recognition implements the iOS [`SFSpeechRecognizer`](https://develo
- [start()](#startoptions-speechrecognitionoptions-void)
- [stop()](#stop-void)
- [abort()](#abort-void)
- [requestPermissionsAsync()](#requestpermissionsasync-promisepermissionresponse)
- [getPermissionsAsync()](#getpermissionsasync-promisepermissionresponse)
- [requestPermissionsAsync()](#requestpermissionsasync)
- [requestMicrophonePermissionsAsync()](#requestmicrophonepermissionsasync)
- [requestSpeechRecognizerPermissionsAsync()](#requestspeechrecognizerpermissionsasync)
- [getPermissionsAsync()](#getpermissionsasync)
- [getMicrophonePermissionsAsync()](#getmicrophonepermissionsasync)
- [getSpeechRecognizerPermissionsAsync()](#getspeechrecognizerpermissionsasync)
- [getStateAsync()](#getstateasync-promisespeechrecognitionstate)
- [getSupportedLocales()](#getsupportedlocales)
- [getSpeechRecognitionServices()](#getspeechrecognitionservices-string-android-only)
Expand All @@ -60,7 +64,6 @@ npm install expo-speech-recognition@sdk-51
npm install expo-speech-recognition@sdk-50
```


2. Configure the config plugin.

> The config plugin updates the Android App Manifest to include package visibility filtering for `com.google.android.googlequicksearchbox` (Google's Speech Recognition) along with the required permissions for Android and iOS.
Expand Down Expand Up @@ -837,11 +840,16 @@ ExpoSpeechRecognitionModule.abort();
// Expect an "error" event to be emitted with the code "aborted"
```

### `requestPermissionsAsync(): Promise<PermissionResponse>`
### `requestPermissionsAsync()`

Presents a dialog to the user to request the necessary permissions.

For iOS, this requests two permissions: record permissions (to access the microphone), and speech recognition permissions. Once a user has granted (or denied) permissions by responding to the original permission request dialog, the only way that the permissions can be changed is by the user themselves using the device settings app.
- On Android, this requests [`RECORD_AUDIO`](https://developer.android.com/reference/android/Manifest.permission#RECORD_AUDIO) permissions.
- On iOS, this requests two permissions: [`AVAudioSession.RecordPermission`](https://developer.apple.com/documentation/avfaudio/avaudiosession/recordpermission) and [`SFSpeechRecognizer.requestAuthorization()`](https://developer.apple.com/documentation/speech/sfspeechrecognizer/1649892-requestauthorization).

If you're using on-device recognition on iOS, you just need to request microphone permissions, which can be called with [`requestMicrophonePermissionsAsync()`](#requestmicrophonepermissionsasync).

Once a user has granted (or denied) permissions by responding to the original permission request dialog, the only way that the permissions can be changed is by the user themselves using the device settings app.

```ts
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";
Expand All @@ -854,9 +862,55 @@ ExpoSpeechRecognitionModule.requestPermissionsAsync().then((result) => {
});
```

### `getPermissionsAsync(): Promise<PermissionResponse>`
### `requestMicrophonePermissionsAsync()`

Requests permissions to use the microphone.

- On iOS, this requests [`AVAudioSession.RecordPermission`](https://developer.apple.com/documentation/avfaudio/avaudiosession/recordpermission) permissions.
- On Android, this requests [`RECORD_AUDIO`](https://developer.android.com/reference/android/Manifest.permission#RECORD_AUDIO) permissions.

```ts
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";

ExpoSpeechRecognitionModule.requestMicrophonePermissionsAsync().then(
(result) => {
console.log("Status:", result.status); // "granted" | "denied" | "not-determined"
console.log("Granted:", result.granted); // true | false
console.log("Can ask again:", result.canAskAgain); // true | false
console.log("Expires:", result.expires); // "never" | number
},
);
```

### `requestSpeechRecognizerPermissionsAsync()`

> [!NOTE]
> This is only supported on iOS. Request this permission only if you aren't using on-device recognition.
Returns the current permission status for the microphone and speech recognition.
Requests [`SFSpeechRecognizer.requestAuthorization()`](https://developer.apple.com/documentation/speech/sfspeechrecognizer/1649892-requestauthorization) permissions before sending voice data across the network to Apple's servers for transcription.

```ts
import { Platform } from "react-native";
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";

const requiresOnDeviceRecognition = false;

// We only need this permission when network-based recognition is used on iOS
if (!requiresOnDeviceRecognition && Platform.OS === "ios") {
ExpoSpeechRecognitionModule.requestSpeechRecognizerPermissionsAsync().then(
(result) => {
console.log("Status:", result.status); // "granted" | "denied" | "not-determined"
console.log("Granted:", result.granted); // true | false
console.log("Can ask again:", result.canAskAgain); // true | false
console.log("Expires:", result.expires); // "never" | number
},
);
}
```

### `getPermissionsAsync()`

Returns the current permission status for both microphone and iOS speech recognizer.

```ts
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";
Expand All @@ -869,6 +923,26 @@ ExpoSpeechRecognitionModule.getPermissionsAsync().then((result) => {
});
```

### `getMicrophonePermissionsAsync()`

Returns the current permission status for the microphone. On Android, this checks the [`RECORD_AUDIO`](https://developer.android.com/reference/android/Manifest.permission#RECORD_AUDIO) permissions. On iOS this checks the [`AVAudioSession.RecordPermission`](https://developer.apple.com/documentation/avfaudio/avaudiosession/recordpermission) permissions.

```ts
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";

ExpoSpeechRecognitionModule.getMicrophonePermissionsAsync().then((result) => {
console.log("Status:", result.status); // "granted" | "denied" | "not-determined"
console.log("Granted:", result.granted); // true | false
console.log("Can ask again:", result.canAskAgain); // true | false
console.log("Expires:", result.expires); // "never" | number
});
```

### `getSpeechRecognizerPermissionsAsync()`

> [!NOTE]
> This is only supported on iOS.
### `getStateAsync(): Promise<SpeechRecognitionState>`

Returns the current internal state of the speech recognizer.
Expand Down

0 comments on commit 8d40629

Please sign in to comment.