1

I'm developing an Android Voice Assistant (Using Dialogflow), and I'm able to control when the user start the request.

@Override
public void onListeningStarted() {
    ImageView fab_img = (ImageView)findViewById(R.id.fab_img);
    fab_img.startAnimation(performAnimation);
}

And that start an animation for the mic icon. After that, when they finish the question or speech, I can use this to stop the animation.

@Override
public void onListeningFinished() {
    ImageView fab_img = (ImageView)findViewById(R.id.fab_img);
    fab_img.clearAnimation();
}

But if the user does not speak, and the mic just close after a period of time, I'm not able to detect that. I have tried with this:

@Override
public void onListeningCanceled() {

}

But it's not working, and with the result of the query, but no luck. Any ideas? Thanks.

EDIT------ The suggested solution of @sunil sunny looks fine

@Override
public void onAudioLevel(float level) {

}

Right now I'm working on the amount of time that the silence level needs to be produced.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
pasandor
  • 11
  • 2

1 Answers1

0

I have never used this API but from the documentation, I saw a method called void onAudioLevel(float level); // callback for sound level visualization which can be used for silence detection I guess. It's returning a float value so first, find out what is the normal value when a user speaks and also find out the value range when the user is in silence. Let's assume A is the value when a user speaks and B is the value when user not speaking. Then if you are getting B for say 5 secs then the user is in silence.

Sunil Sunny
  • 3,949
  • 4
  • 23
  • 53
  • One can keep an array of sound levels of last 3 seconds, at every instance check whether the median sound level in the array is below a certain threshold. This way one can better determine silence during speaking. – waterbyte Oct 04 '18 at 09:48
  • @Waterbyte I have just given a rough idea. Implementation he has to do it himself and I agree with your point. – Sunil Sunny Oct 04 '18 at 09:58
  • I may need a little more help. the `@Override public void onAudioLevel(float level { }` was good, but hard to catch an average of the sound and any variable created inside, will only exist while a sound is being captured. So the best way to go is `onListeningFinished ` the bad part is that is only called in random times. – pasandor Oct 08 '18 at 17:30
  • @pasandor Since I haven't tried the API I am quite not sure how 'onAudioLevel' works. However, I will try the API and update my answer with code if I am getting some free time. – Sunil Sunny Oct 09 '18 at 05:38