Development of application similar to "Google now" - is it possible to use voice recognition without key input?
Asked Answered
W

3

17

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.

Wessex answered 14/3, 2014 at 9:9 Comment(8)
A good thought indeed but what I feel is writing a service which senses something like "OK Google" is also nothing but a speech recognition technique which you cannot keep running 24X7. Instead you can vouch for a home screen widget and on its tap you can launch this background service which will ultimately launch your application for you and yes you can start intent in a if block where your condition will be something like checking the speech input with your hardcoded value like "OK Google".Hominoid
Yes it's a good idea the widget. But, have you any idea how create this kind of service with code? i mean.. How the app can recognize that if i say "ok google" have to start that intent? This is my real problem.Wessex
when you create a widget you can map an activity to its launch. So you can write a code where on launch of widget "XYZ" activity is launched and that activity directly takes the voice input the same way you are taking the voice input in your application. Now after taking the voice input you convert it into text and check if it matches with the "OK GOOGLE" if yes then you simply create Intent of whatever activity you want in that if block.Hominoid
Even I have developed a speech to text application using which user can dial the call directly by saying a name from his contact list...application will dial the call for user by taking input as name of the person to call...I will try this thing there and let you know if it works...but i feel there is no issue and should surely work.Hominoid
I'll try something like that thanks. Well, if i can ask, how have you realized the application? i tried to read the contact list but i can't find a way to "tell to it" to recognize the name and call the right number..is it open source your app or not?Wessex
yes of course if you have a bit bucket account I can share the repo with you...?Hominoid
i can log in with github account :) you can find me under name: davidedellai Thank you ;)Wessex
#14941157Purchase
Q
2

(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.

Quenby answered 9/7, 2014 at 3:46 Comment(0)
B
0

It's not java, but have you seen Jasper? Looks promising: http://jasperproject.github.io

Bilander answered 25/7, 2014 at 23:19 Comment(0)
K
0

Well with Jform ,not android,and you create a button, you are able to call button.doClick(). So what i used was a Timer , Timer.scheduleAtFixedRate(new task(),int delay,int iterval); so that it would do it independantly and repeat. So what im trying to get at is ,im sure there's a way in android to do.action/button/key, and so on and you can use a timer to activate it independently. Seeing as though it is a void just try

listenToSpeech();

As for the timer;

Timer listenTimer = new Timer();
//listenTimer.schedualAtFixedRate(new listeningTask(),0,1);//place this where your program starts as this starts the timer
class listeningTask extends TimerTask{
  if(condition){
    listenToSpeech();
  }
}

sorry about the format or indentation, using a tablet.

Kopans answered 8/10, 2014 at 19:4 Comment(1)
If you use a Timer scheduleAtFixedRate,it can only run 1000 times a second and so it uses basically 0% cpu, but if you really want to, i can post a code that uses sockets and InputStream that blocks until an inptStream is available-I used sockets because it Enables you to create multiple "waitBlocks".thus using the waitBlock it allows you to use even less cpu.Kopans

© 2022 - 2024 — McMap. All rights reserved.