I'm trying to develop a cool application that uses the TTS
engine and speech recognition. So far it's ok but I want more. I would like to create a service (I think a service is the right way), that is always "listening" and when someone says "ok google"
or something else , the speech recognition starts, like google now. For example, if you say "ok google"
google now starts. I don't know where to start so I'm asking directly here if it's possible. I tried looking at this thread [here] (Listening for keywords at all times, like "Ok google" on 4.4) and the last answer talked about a service, as I thought. Can someone help me with my code?
For example this is the code to start speech recognition by tapping a button:
/**
* Instruct the app to listen for user speech input
*/
private void listenToSpeech() {
//start the speech recognition intent passing required data
Intent listenIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
//indicate package
listenIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
//message to display while listening
listenIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say a word!");
//set speech model
listenIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
//specify number of results to retrieve
listenIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 10);
//start listening
startActivityForResult(listenIntent, VR_REQUEST);
}
Do you think it's possible to start that listenIntent
only with voice and without pressing any button? This is what i mean.
(Updated 06.01.2018: added some bits to previous answer)
you can have reference with Saiy, previously Utter
this app uses hot word detection as "Google Now".
and there is no such API provided by Android to perform such operation.
Saiy app is now opensource with repository here. From what little I saw in the code, it seems to have implemented the functionality using CMU Pocketshinx.
Don't forget to post your findings.
Note- its very CPU-intensive and battery consuming to listen all the time in background.