voice icon indicating copy to clipboard operation
voice copied to clipboard

Remove Android BIP sound on start and stop recognizing

Open MacKentoch opened this issue 7 years ago • 24 comments

In Android SpeechRecognizer emits (horrible) BIP sound when starting and ending recognition.

This by design but it would be awesome to be able to remove / mute these bips.

MacKentoch avatar Nov 20 '17 11:11 MacKentoch

Any news on that @MacKentoch ?

I would also like to remove that sound.

xavicolomer avatar Jan 18 '18 14:01 xavicolomer

This would be a nice option.

Noitidart avatar Jan 18 '18 19:01 Noitidart

@ghsdh3409 Ping. Time to sync with upstream?

ohtangza avatar Jan 19 '18 01:01 ohtangza

have u been able to do that?

alinematic avatar Apr 28 '18 07:04 alinematic

I (big) while ago, I made a plugin for Cordova, and came up with a dirty hack to turn the volume off while recognizing and turn it back on when done. It's not the best solution but it works fine for now. I don't know exactly how to implement it now because it's been ages since I work with android, but just for the heck of it, here's the code of that class: https://github.com/dalvallana/ContinuousSpeechRecognizer/blob/master/src/android/ContinuousSpeechRecognizer.java. Look for the mStreamVolume variable.

dalvallana avatar Nov 22 '18 14:11 dalvallana

any update?

roysG avatar Feb 17 '19 23:02 roysG

I also need such a function

Saltan77 avatar Mar 03 '19 17:03 Saltan77

any update?

imyagnesh avatar Mar 05 '19 07:03 imyagnesh

Any update on this??

ReJaimes avatar Apr 25 '19 16:04 ReJaimes

any Updateee?

roysG avatar May 02 '19 07:05 roysG

Any update?

subhendukundu avatar Jun 04 '19 08:06 subhendukundu

+1

ducpt2 avatar Jun 14 '19 17:06 ducpt2

any update

vaibhgupta09 avatar Nov 24 '19 11:11 vaibhgupta09

@MacKentoch Did you solved your problem?

lfoliveir4 avatar Dec 16 '19 12:12 lfoliveir4

Hello Guyz i found a Hack to do this just simply set your phone volume to 0 before listening start. https://www.npmjs.com/package/react-native-system-setting check this out

vaibhgupta09 avatar Dec 16 '19 12:12 vaibhgupta09

@lfoliveir4 no but try @vaibhgupta09 hack.

This is by design in Android: recording audio triggers a BIP sound -system does it - (should be related to legal reasons I guess).

So hacking is the only way to bypass as far as I know

MacKentoch avatar Dec 16 '19 12:12 MacKentoch

I'm not sure it's good idea to avoid that sound. This makes user to know about listening and as far as this library can start listen without user action it's better to keep BIP sound turned on.

Doodidan avatar Jun 24 '20 16:06 Doodidan

But it would be good if I could change that sound. I've seen solution for Android API. Maybe I will try it later

zombie6888 avatar Jul 01 '20 01:07 zombie6888

bump

Jonjoe avatar Feb 23 '21 17:02 Jonjoe

wait this option

phongbksneep avatar Mar 29 '21 03:03 phongbksneep

any update?

Hirurgo avatar Mar 31 '21 22:03 Hirurgo

Any updates?

abhineetsharmathegreat avatar Apr 24 '21 14:04 abhineetsharmathegreat

Down vote I really don't want this option exist in any RN project. It's not intuitively way to interact with client.

Doodidan avatar Apr 24 '21 14:04 Doodidan

Navigate to this file in: node_modules/@react-native-voice/voice/android/src/main/java/com/wenkesj/voice/VoiceModule.java

And there you can use the AUDIO_SERVICE to manipulate the sound on the mobile on android so when the microphone is on silent the phone and when is done to return to the volume levels that the user has. here a sample that i have try and work.

The patch encompasses the implementation of an Android-based speech recognition feature in a React Native application. It allows the application to mute background sound or music while the Speech Recognizer is capturing user speech. This has been achieved by employing the AudioManager, a core Android service that handles audio management, including volume and mode.

At the start of the VoiceModule class, a private field for AudioManager and an integer field for StreamVolume is declared. The AudioManager is later used to manage audio properties when the microphone is active.

private AudioManager mAudioManager = null;
private int mStreamVolume = 0;

The application stores the current music stream volume in the mStreamVolume variable when the VoiceModule object is created. This original volume level is maintained for restoration once the speech recognition operation is completed.

AudioManager mAudioManager = (AudioManager) this.reactContext.getSystemService(Context.AUDIO_SERVICE);
mStreamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);

When speech recognition begins, the application mutes the music stream volume. This ensures that the recognition process is not affected by any background music that might be playing.

muteStreamVolume();
speech.startListening(intent);

After the startListening() function is called, the muteStreamVolume() function mutes the audio stream only if the original volume wasn't 0.

private void muteStreamVolume() {
    if(mStreamVolume == 0) {
      return;
    }
    AudioManager mAudioManager = (AudioManager) this.reactContext.getSystemService(Context.AUDIO_SERVICE);
    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
}

As soon as the recognition process is completed, the audio stream volume is restored to its original value. This is done in the onResults() method which is called when speech recognition results are ready.

setStreamVolumeBack();

The setStreamVolumeBack() function restores the original audio stream volume when called.

private void setStreamVolumeBack() {
    AudioManager mAudioManager = (AudioManager) this.reactContext.getSystemService(Context.AUDIO_SERVICE);
    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mStreamVolume, 0);
}

In conclusion, this patch significantly improves the user experience by ensuring that a user's voice command is not drowned out by background music during a voice-activated operation. This subtle yet essential modification enables users to interact more seamlessly with voice-activated applications and commands.

IMPORTANT After you edit the library you need to patch the use this tool:https://www.npmjs.com/package/patch-package search on the net to find out how is this done.

erevos-13 avatar Dec 20 '23 06:12 erevos-13