Android Speech Recognition Continuous Service

Android Speech Recognition Continuous Service

Class members in MainActivity

private int mBindFlag;
private Messenger mServiceMessenger;

Start service in onCreate()

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

Intent service = new Intent(activityContext, VoiceCommandService.class);
activityContext.startService(service);
mBindFlag = Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH ? 0 : Context.BIND_ABOVE_CLIENT;

}

Bind service in onStart()

@Override
protected void onStart()
{
super.onStart();

bindService(new Intent(this, VoiceCommandService.class), mServiceConnection, mBindFlag);
}

@Override
protected void onStop()
{
super.onStop();

if (mServiceMessenger != null)
{
unbindService(mServiceConnection);
mServiceMessenger = null;
}
}

mServiceConnection member

private final ServiceConnection mServiceConnection = new ServiceConnection()
{
@Override
public void onServiceConnected(ComponentName name, IBinder service)
{
if (DEBUG) {Log.d(TAG, "onServiceConnected");} //$NON-NLS-1$

mServiceMessenger = new Messenger(service);
Message msg = new Message();
msg.what = VoiceCommandService.MSG_RECOGNIZER_START_LISTENING;

try
{
mServiceMessenger.send(msg);
}
catch (RemoteException e)
{
e.printStackTrace();
}
}

@Override
public void onServiceDisconnected(ComponentName name)
{
if (DEBUG) {Log.d(TAG, "onServiceDisconnected");} //$NON-NLS-1$
mServiceMessenger = null;
}

}; // mServiceConnection

In the service

@Override
public IBinder onBind(Intent intent)
{
Log.d(TAG, "onBind"); //$NON-NLS-1$

return mServerMessenger.getBinder();
}

Continuous Speech Recognition Android - Without Gaps

try looking at a couple other api's....

speech demo : has source here and is discussed here and operated on CLI here

you could use the full duplex google api ( its rate capped at 50 per day )

Or if you like that general idea check ibm's watson discussed here

IMO - its more complex but not capped .

Android Continuous Speech Recognition

You can try the Oxford API of Mircosoft

This can give you continuous real time speech recognition, and then you can look for special keywords. Maybe it's an overkill in your case so be sure to check more options !

Continuous speech recognition in android app without google popup

You should try Droid Speech it supports continuous voice recognition and also will work offline if the speech package for the required language is installed in the device.

Setting the library in your project is very simple and with a few lines of code you can easily start using speech recognition.

An example,

Add the below in your Gradle file,

compile 'com.github.vikramezhil:DroidSpeech:v2.0.3’

In your Activity,

DroidSpeech droidSpeech = new DroidSpeech(this, null);
droidSpeech.setOnDroidSpeechListener(this);

To start droid speech to listen to user voice call the method,

droidSpeech.startDroidSpeechRecognition();

The speech result will be triggered at,

@Override
public void onDroidSpeechFinalResult(String finalSpeechResult)
{
// Do whatever you want with the speech result
}


Related Topics



Leave a reply



Submit