Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Make iOS Speech-To-Text Persistent

I am conducting initial research on a new potential product. Part of this product requires Speech-To-Text on both iPhones and iPads to remain on until the user turns it off. Upon using it myself, I noticed that it either automatically shuts off after 30 or so seconds, regardless of whether or not the user has stopped speaking, OR it shuts off after there have been a certain amount of questionable words from the speaker. In any case, this product requires it to remain on all of the time until explicitly told to stop. Has anybody worked with this before? And yes, I have tried a good search, I couldn't seem to find anything of substance, and especially anything written in the right language. Thanks friends!

like image 834
Ethan Avatar asked Aug 02 '16 19:08

Ethan


People also ask

How long can you dictate on an iPhone?

When you use Dictation on a device, you can dictate text of any length without a timeout. You can stop Dictation manually, or it stops automatically when you stop speaking for 30 seconds. Note: Dictation may not be available in all languages or in all countries or regions, and features may vary.

How do I make my iPhone speak instead of typing?

To enter text, tap the microphone button on your keyboard, then start speaking. As you speak, the text appears on the screen. To finish, stop speaking, then tap the keyboard button . If dictation isn't sure what word it heard, you'll see a blue line under the transcribed word so you can check it for accuracy.


2 Answers

import Speech

let recognizer = SFSpeechRecognizer()
let request = SFSpeechURLRecognitionRequest(url: audioFileURL)
#if targetEnvironment(simulator)
  request.requiresOnDeviceRecognition = /* only appears to work on device; not simulator */ false
#else
  request.requiresOnDeviceRecognition = /* only appears to work on device; not simulator */ true
#endif
recognizer?.recognitionTask(with: request, resultHandler: { (result, error) in
 print (result?.bestTranscription.formattedString)
})

The above code snippet, when run on a physical device will continuously ("persistently") transcribe audio using Apple's Speech Framework.

The magic line here is request.requiresOnDeviceRecognition = ...

If request.requiresOnDeviceRecognition is true and SFSpeechRecognizer#supportsOnDeviceRecognition is true, then the audio will continuously be transcribed until battery dies, user cancels transcription, or some other error/terminating condition occurs. This is at least true in my trials.

Docs:

https://developer.apple.com/documentation/speech/recognizing_speech_in_live_audio

like image 150
Ethan Avatar answered Oct 09 '22 22:10

Ethan


I found here a tutorial that show your speech. But see the notes:

Apple limits recognition per device. The limit is not known, but you can contact Apple for more information. Apple limits recognition per app.

If you routinely hit limits, make sure to contact Apple, they can probably resolve it.

Speech recognition uses a lot of power and data.

Speech recognition only lasts about a minute at a time.

EDIT

This answer was for iOS 10. I expect the release of iOS 12 at October 2018 but Apple still says:

Plan for a one-minute limit on audio duration. Speech recognition can place a relatively high burden on battery life and network usage. In iOS 10, utterance audio duration is limited to about one minute, which is similar to the limit for keyboard-related dictation.

See: https://developer.apple.com/documentation/speech

There are no API changes in the Speech Framework for iOS 11 and 12. See all API changes and especially for iOS 12 in detail by Paul Hudson: iOS 12 APIs Diffs

So my answer should still be valid.

like image 23
kuzdu Avatar answered Oct 09 '22 22:10

kuzdu