B4i Library iSpeechRecognition - Voice to Text

SS-2016-11-10_15.33.26.png


Apple has opened the speech recognition feature in iOS 10. With this library it is quite simple to capture audio and convert it to text.

It requires iOS 10+ and the voice recognition itself requires an internet connection.
See Apple's best practices recommendation: https://developer.apple.com/reference/speech

Using this library:
1. Add these attributes and explain the usages:
B4X:
#MinVersion: 10
#PlistExtra:<key>NSSpeechRecognitionUsageDescription</key><string>More information here...</string>
#PlistExtra:<key>NSMicrophoneUsageDescription</key><string>Speech recognition</string>
2. Initialize the SpeechRecognition and handle the AuthorizationStatusChanged event. It will always be called.

3. Once authorized we need to call SpeechRecognition.SetLanguage. The example code checks whether the current language is supported and if not it uses English (en).
SetLanguage will return False if the speech engine is not available. This will happen if there is no Internet connection.

4. Call StartRecording to start capturing audio and call StopRecording when done.
The Result event will be raised with a list of captured text. The list is ordered based on the confidence level. First item is the best match.
Set the ReportPartialResults parameter to True if you want the Result event to be raised during the audio capture.

Tips:

- If you are using a local Mac builder then it needs to run Xcode 8+. The hosted builders were updated to Xcode 8.
- Dictation must be enabled for this feature to work. You can enable it by clicking on the microphone button in the keyboard or under Settings - Keyboards.
 

Attachments

  • SpeechRecognition.zip
    67.2 KB · Views: 136
  • SpeechRecognitionExample.zip
    2.9 KB · Views: 169

manolitoGnet

Member
Licensed User
Longtime User
Hi Erel thanks for the library!

Will it be possible to have MinVersión <10 and check on the fly if we are on 10+ and turn the library on?

Tx
 

Ju Yang

Active Member
Licensed User
Longtime User
When I use this library,the app builds failure.Not sure where I'm going wrong but it shows a failures.
B4X:
The following build commands failed:
    CompileC build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_main.o B4iProject/b4i_main.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
 

Samuel Ramirez

Member
Licensed User
Longtime User
Thanks for the library Erel, it will be very useful. I tested the example and it works fine so I will add the voice recognition feature to my apps.
 
Top