Calling the voice-input feature - CodenameOne app (iOS port)

Viewed 70

My Android app features a text input box that has a button on the right of the EditText to call the voice-input feature.

I am porting the app with Codename One. At present time the iOS port is the goal.

The button has a suitable icon. This is the code:

voiceInputButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
            try {
                activity.startActivityForResult(voiceIntent, RESULT_SPEECH_REQUEST_CODE);
            } catch (ActivityNotFoundException ex) {

            }
        }
    });

It works very well, the voice-input screen is called and then the result is passed back to the app as a string.

The string is what the user said (for example, a single word).

I need to have this functionality in the CodenameOne app for iOS.

What should be the equivalent? Is it necessary to call native iOS functions, through the native interface?

1 Answers

You can implement speech-to-text via Speech framework, to perform speech recognition on live or prerecorded audio. More info: https://developer.apple.com/documentation/speech

About Codename One, you can create a native interface using Objective-C code.

To use the Speech framework with Objective-C, see this answer: https://stackoverflow.com/a/43834120

The answer says so: «[...] 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 code NSLog is the only thing receiving the text). It should stop the recording when pressed again. [...]». This seems very close to what you asked.

Obviously the creation of the native interface takes time. For further help, you can ask more specific questions, I hope I have given you a useful indication.


Lastly, there are also alternative solutions, again in Objective-C, such as: https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/quickstart/objectivec/ios/from-microphone

You can search on the web for: objective-c speech-to-text

Related