-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate microphone and recognizer permissions (#55)
* skip permission if not needed * separate permissions * dev * Update App.tsx * Update Podfile.lock * Update App.tsx * moving permission check * deprecated * Update example/App.tsx Co-authored-by: jamsch <[email protected]> * return granted response on web * Update src/ExpoSpeechRecognitionModule.types.ts Co-authored-by: jamsch <[email protected]> * More docs update and removing deprecated * Adding Android permission functions --------- Co-authored-by: jamsch <[email protected]>
- Loading branch information
1 parent
601112b
commit d3d3d63
Showing
8 changed files
with
310 additions
and
21 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import ExpoModulesCore | ||
|
||
public class MicrophoneRequester: NSObject, EXPermissionsRequester { | ||
static public func permissionType() -> String { | ||
return "microphone" | ||
} | ||
|
||
public func requestPermissions( | ||
resolver resolve: @escaping EXPromiseResolveBlock, rejecter reject: EXPromiseRejectBlock | ||
) { | ||
AVAudioSession.sharedInstance().requestRecordPermission { authorized in | ||
resolve(self.getPermissions()) | ||
} | ||
} | ||
|
||
public func getPermissions() -> [AnyHashable: Any] { | ||
var status: EXPermissionStatus | ||
|
||
let recordPermission = AVAudioSession.sharedInstance().recordPermission | ||
|
||
if recordPermission == .granted { | ||
status = EXPermissionStatusGranted | ||
} else if recordPermission == .denied { | ||
status = EXPermissionStatusDenied | ||
} else { | ||
status = EXPermissionStatusUndetermined | ||
} | ||
|
||
return [ | ||
"status": status.rawValue | ||
] | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import ExpoModulesCore | ||
import Speech | ||
|
||
public class SpeechRecognizerRequester: NSObject, EXPermissionsRequester { | ||
static public func permissionType() -> String { | ||
return "speechRecognizer" | ||
} | ||
|
||
public func requestPermissions( | ||
resolver resolve: @escaping EXPromiseResolveBlock, rejecter reject: EXPromiseRejectBlock | ||
) { | ||
SFSpeechRecognizer.requestAuthorization { status in | ||
resolve(self.getPermissions()) | ||
} | ||
} | ||
|
||
public func getPermissions() -> [AnyHashable: Any] { | ||
var status: EXPermissionStatus | ||
|
||
let speechPermission = SFSpeechRecognizer.authorizationStatus() | ||
|
||
if speechPermission == .authorized { | ||
status = EXPermissionStatusGranted | ||
} else if speechPermission == .denied { | ||
status = EXPermissionStatusDenied | ||
} else { | ||
status = EXPermissionStatusUndetermined | ||
} | ||
|
||
return [ | ||
"status": status.rawValue | ||
] | ||
} | ||
} |
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
Oops, something went wrong.