pbakondy / cordova-plugin-speechrecognition

:microphone: Cordova Plugin for Speech Recognition
MIT License
196 stars 116 forks source link

Disable "beep" sound on start and stop #39

Closed yasseralsamman closed 6 years ago

yasseralsamman commented 7 years ago

Hi is there any way to disable the beep sound on starting and stopping ? I'm using Ionic 2 and building for Android.

I tried Media Plugin but it does not seem to be able to affect system sounds.

Thanks in advance.

ragcsalo commented 7 years ago

You should mute the Multimedia (music) stream. Edit "SpeechRecognition.java" and add this to the startListening method to line 157 (before initiating the recognition):

AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, 0);

mano42023 commented 6 years ago

@ragcsalo Hi I did this but still getting beep sound.. :(

ghost commented 6 years ago

this one works for me AudioManager audioManager=(AudioManager)context.getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);

I advise first to get the current volume using: audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);

then set volume to 0 and after you are done with recording you can reset volume to the initial one

texano00 commented 6 years ago

Hi @JackJohnG , can you please provide a full working example? Where i have to put the reset volume to the initial one?

Thanks

ragcsalo commented 6 years ago

I mute the media volume in the onCreate function of my MainActivity, and restore the volume in the onDestroy function. I had to create the variable first (which stores the original volume level). My code is:

private Integer original_volume_level;
private AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

onCreate:
=========
original_volume_level = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, 0);
Toast.makeText(this, "Media volume muted.", Toast.LENGTH_SHORT).show();

onDestroy:
==========
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, original_volume_level, 0);
Toast.makeText(this, "Media volume restored.", Toast.LENGTH_SHORT).show();

I hope this helps. :-)

ghost commented 6 years ago

@texano00 I created a very small cordova plugin to control volume in android you can just download it as zip, unzip it into the folder of your project and then add it using command ionic cordova plugin add ./cordova-plugin-volumecontrol

Then you can use it in any place of the application like this: window.VolumeControl.setVolume(0);

So, you just need to call the above method just before you start speech recognition and after you are done you can call: window.VolumeControl.resetVolume();

In case you need to change some behaviour inside plugin, you can simply edit VolumeControl.java file inside plugin but then do not forget to remove old version of plugin and add the new one.

If you have any questions you can write me an email

yasseralsamman commented 6 years ago

@JackJohnG Nice one! I tried it and it's working fine. Thanks! this is how I used it: ionic cordova plugin add https://github.com/JackJohnG/cordova-plugin-volumecontrol --save then declare var VolumeControl : any; in my code.