Home

Awesome

Speech API ANE V6.0 (Android+iOS)

The Speech API extension lets you convert Strings to voice files and vice versa without any annoying mic activities. the extension will work fully in the background. if you have downloaded language packages from Google, the extension will work with no internet connection required and if offline packages are not available, it will automatically load the voice file from internet.

Google has stopped TTS service for iOS so, you won't be able to use TTS on iOS side anymore. unless we find a new alternative, this is how it goes.

checkout here for the commercial version: http://myappsnippet.com/google-speech-api-air-native-extension/

Speech ANE

you may like to see the ANE in action? check this out: https://github.com/myflashlab/speech-ANE/tree/master/FD/dist

NOTICE: the demo ANE works only after you hit the "OK" button in the dialog which opens. in your tests make sure that you are NOT calling other ANE methods prior to hitting the "OK" button.

AS3 API:

import com.doitflash.air.extensions.speech.Speech;
import com.doitflash.air.extensions.speech.SpeechEvent;

var _ex:Speech = new Speech();
_ex.addEventListener(SpeechEvent.INITIALIZATION, onInitialization);
_ex.addEventListener(SpeechEvent.TTS_SUPPORTED_LANGS, onTTS_langs); // will never be called on the iOS side
_ex.addEventListener(SpeechEvent.STT_SUPPORTED_LANGS, onSTT_langs);
_ex.addEventListener(SpeechEvent.SPEECH_FILE_SAVED, onFileSaved);
_ex.addEventListener(SpeechEvent.ERROR, onError);
_ex.addEventListener(SpeechEvent.SPEECH_STATE, onSpeechState);
_ex.addEventListener(SpeechEvent.RECOGNITION_RESULTS, onSpeechResult);
    
// check if the extension is supported on this device
if (!_ex.isSupported)
{
    trace("Speech API is not supported! there must be something wrong in your .ane implimentation or your air manifest setup!")
    return;
}
else
{
    trace("SpeechAPI V"+Speech.VERSION+" is supported");
    trace("now, waiting for the extension initialization...");
}

function onInitialization(e:SpeechEvent):void
{
    trace("initialaztion was successful: " + e.param);
}

function onTTS_langs(e:SpeechEvent):void
{
    trace("number of supported langs for TTS = " + e.param.length);
}

function onSTT_langs(e:SpeechEvent):void
{
    trace("number of supported langs for STT = " + e.param.length);
}

function onError(e:SpeechEvent):void
{
	trace("ERROR: " + e.param.msg);
}

function onSpeechState(e:SpeechEvent):void
{
	trace("SpeechState= " + e.param.state + " (" + e.param.msg + ")");
}
		
function onSpeechResult(e:SpeechEvent):void
{
	var result:Array = e.param;
	trace("Speech to Text results are:");
	for each (var item:String in result) 
	{
		trace(item);
	}
	trace("-------------");
}

function onFileSaved(e:SpeechEvent):void
{
	var file:File = new File(e.param);
	trace(file.nativePath)
}

function onFileSaved(e:SpeechEvent):void
{
	var file:File = new File(e.param);
	trace(file.nativePath)
}

// the following will run TTS and you can hear the words. (TTS is not supported on iOS)
_ex.tts("hello world!", "en", 1, 1, Speech.QUEUE_ADD/*, "tts/"*/);

// this will run TTS but you won't hear anything. instead, .wav files will be saved in your chosen folder
_ex.tts("hello world!", "en", 1, 1, Speech.QUEUE_ADD, "tts/");

// call this to stop TTS playback if _ex.isSpeaking is true
_ex.stopTTS();

// call the folloiwng to run and stop STT
_ex.startListening("en-US");
_ex.stopListening();

Don't forget to include the necessary permissions and services in the air manifest file application.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application>
    <service android:name="com.doitflash.speech.speechToText.SpeechRecognitionService">
..
..

NOTICE: if you are trying to run the extension on an iOS device, you will need a Google Browser API key enabled for the Speech API for the STT to work. if you are running on an Android device, you won�t need this set at all. do the following to obtain your key: http://myappsnippet.com/DOC/com/doitflash/air/extensions/speech/Speech.html#googleApiKey (TTS won't work on iOS anymore. Google has stopped the service!)

Changelog