Ask the user’s permission to perform speech recognition using Apple’s servers.
- Bundle Resources
The speech recognition process involves capturing audio of the user’s voice and sending that data to Apple’s servers for processing. The audio you capture constitutes sensitive user data, and you must make every effort to protect it. You must also obtain the user’s permission before sending that data across the network to Apple’s servers. You request authorization using the APIs of the Speech framework.
Add the Privacy Key to Your Info.plist File
In Xcode, add the
“Privacy - Speech Recognition Usage Description” key to your app’s
Info file. The raw name of this key is
NSSpeech. Set the value of this key to a string that explains how you plan to use any recognized speech. When your app request authorization later, the system displays the value of this key to the user as part of the system prompt.
"The app uses speech recognition for dictating notes."
"Lets you mark an item as finished by saying Done."
"The app listens for specific verbal commands, such as "Start", "Stop", and "Pause". For a complete list of commands, see http://myapp.example.com".
Request Authorization at First Use
Before using the APIs of the Speech framework, you must call
request on the
SFSpeech object. The method executes asynchronously and delivers the results to a block you provide. Use that block to determine whether the user granted or rejected your request.
The first time your app requests authorization to use speech recognition, the system prompts the user to accept or deny that request. The system records the user’s selection so that subsequent requests do not prompt the user again. Instead, subsequent requests return almost immediately with the previously recorded results.
Listing 1 shows the authorization request for an app that transcribes spoken phrases and displays them onscreen. Because the app’s interface is dependent on speech recognition, it requests authorization as soon as that interface is visible. In addition, the app disables portions of the interface if the user or system prevents access to speech recognition.