I want to do speech recognition in my Objective-C app using the iOS Speech framework.
I found some Swift examples but haven't been able to find anything in Objective-C.
Is it possible to access this framework from Objective-C? If so, how?
I want to do speech recognition in my Objective-C app using the iOS Speech framework.
I found some Swift examples but haven't been able to find anything in Objective-C.
Is it possible to access this framework from Objective-C? If so, how?
After spending enough time looking for Objective-C samples -even in the Apple documentation- I couldn't find anything decent, so I figured it out myself.
Header file (.h)
Methods file (.m)
Now, add the delegate the
SFSpeechRecognizerDelegate
to check if the speech recognizer is available.Instructions & Notes
Remember to modify the .plist file to get user's authorization for Speech Recognition and using the microphone, of course the
<String>
value must be customized to your needs, you can do this by creating and modifying the values in theProperty List
or right-click on the.plist
file andOpen As
->Source Code
and paste the following lines before the</dict>
tag.Also remember that in order to be able to import the Speech framework into the project you need to have iOS 10.0+.
To get this running and test it you just need a very basic UI, just create an UIButton and assign the
microPhoneTapped
action to it, when pressed the app should start listening and logging everything that it hears through the microphone to the console (in the sample codeNSLog
is the only thing receiving the text). It should stop the recording when pressed again.I created a Github repo with a sample project, enjoy!