Here is a Speech Native Extension that takes advantage of the Android’s speech recognition APIs.
Here is what the ANE does,
- Provide an API to check if the feature is supported.
- Provide an API to launch the default speech recognition UI and capture voice input.
- Trigger events based on the success or failure of the above call.
- In case of success, the appropriate event has information of the best match !
- In case of failure, the appropriate event is fired.
Here are the steps required to include the ANE in your Android Project,
- Download the ANE from here
Flash Builder 4.6, open the Properties dialogue of the Project you want to include speech support in.
- Select Build Path > Native Extensions
- Add ANE – Select the location of the downloaded Speech.ane file
- Navigate to Flex Build Packaging > Google Android > Native Extensions
- Check the
Packagecheckbox next to Speech.ane (This ANE supports only the Android Platform at the moment)
- Apply and Close
- Open the <ProjectName>-app.xml file
- Scroll down until you find the Android manifest statements
- Add the below code just before
(i.e., inside the
<application> <activity android:name="com.inoel.ane.speech.extensions.SpeechHandler"> </activity> </application>
You will now be able to access the below APIs,
Initializing and specifying prompt text//Creating and initializing a Speech Object //Parameter - Prompt displayed on the Native Speech Recognition UI var speech:Speech = new Speech("Please speak something !");
Check if speech input is supported// Returns a Boolean value trace("Speech Supported: " + speech.isSupported);
Accept Speech Input//Calls the method which in turn fire's the Native Speech UI for accepting speech input speech.listen();
Listen for the following events
speechToTextEvent.VOICE_RECOGNIZED– Fired on successful voice recognition. Recognized String resides in the event.data attribute.
speechToTextEvent.VOICE_NOT_RECOGNIZED– Fired on unsuccessful attempt. A common cause for failure could be network (data) unavailability. I believe this is overcome in new Ice Cream Sandwich which does not require a network connection to recognize speech ! Includes the error string in the event.data attribute.
Download the sample project from here. Please ensure you manually add the ANE with the steps above, or you get a ‘Class not found Exception’.
If you are interested in understanding how ANEs are used in Flash Builder 4.6, have a look at the recording in my previous post, http://blog.immanuelnoel.com/2011/10/20/native-extensions-flash-builder-webinar/
I also plan to post the entire source for the ANE itself. Watch out for that !
—– UPDATE 19/02/2012 —-
Source for the ANE is posted below,