How to make SFSpeechRecognizer available on macOS?
Had similar problems with SFSpeechRecognizer... Perhaps you can set the delegate of SFSpeechRecognizer
before requesting for authorization, as shown here.
For example:
class ViewController: NSViewController {
var speechRecognizer: SFSpeechRecognizer!
override func viewDidLoad() {
super.viewDidLoad()
speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))
speechRecognizer.delegate = self
}
override func viewWillAppear() {
SFSpeechRecognizer.requestAuthorization { authStatus in
...
}
if !speechRecognizer.isAvailable {
print("Not available!")
}
let url = Bundle.main.url(forResource: "sample", withExtension: "mp3")!
let request = SFSpeechURLRecognitionRequest(url: url)
// will now ask for authorisation
speechRecognizer.recognitionTask(with: request) { (result, error) in
...
}
}
}
extension ViewController: SFSpeechRecognizerDelegate {
}
Then the authorisation dialog will be properly shown.
In addition, it seems that only when there is a call to recognitionTask
, that the user will be asked to give permission. Instead, calling requestAuthorization
alone will not have any effect.
SFSpeechRecognizer isn't working properly in IOS 13.2
I have been experiencing the same problem with iOS 13.2
Apple just released iOS 13.3, and fixed the bug you are experiencing with SFSpeechRecognizer.
The same bug in macOS Catalina 10.15.1 has been fixed with the just released macOS Catalina 10.15.2
speech to text macOS swift playground
It seems like the Speech library is only available on iOS, so you're out of luck with SFSpeechRecognizer. NSSpeechRecognizer
could be an alternative but requires you to give a list of words for it to recognize from (rather than recognizing from any arbitrary word).
Related Topics
Getting an Issue with Upgrade to Xcode 10.2
Nsposixerrordomain When Binding to Socket on MACos 10.12
Module Compiled with Swift 4.0 Cannot Be Imported in Swift 3.0.2
Ibdesignable and Uitableviewcell
Xcode UI Test:Accessibility Query Fail on Uitableviewcell
Nsurlsessiondatadelegate Method Didreceivedata and Others Are Not Called
Passing and Storing Closures/Callbacks in Swift
Swiftui Tabbar: Action for Tapping Tabitem of Currently Selected Tab to Reset View
Can Not Conform to Protocol by Creating Extension with Where Clauses
Swift; Delegate Embedded View Controller and Parent
How to Turn Off Color Literals in Xcode
Cannot Subscript a Value of Type '[String:String]' with an Index of Type 'String'
Prevent Error "Funk" Sound in Event Monitor Os X
Deleting a Camera Roll Asset Using Photos Framework
Create CSV File in Swift and Write to File
Realmswift + Multiple Predicate
How to Migrate Core Data's Data to App Group's Data
How to Create Project Without Story Board in Xcode 6 (Swift)