Coder Social home page Coder Social logo

Comments (24)

vaibhgupta09 avatar vaibhgupta09 commented on May 23, 2024 3

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

from voice.

Doodidan avatar Doodidan commented on May 23, 2024 3

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

from voice.

imyagnesh avatar imyagnesh commented on May 23, 2024 1

any update?

from voice.

ReJaimes avatar ReJaimes commented on May 23, 2024 1

Any update on this??

from voice.

subhendukundu avatar subhendukundu commented on May 23, 2024 1

Any update?

from voice.

ducpt2 avatar ducpt2 commented on May 23, 2024 1

+1

from voice.

vaibhgupta09 avatar vaibhgupta09 commented on May 23, 2024 1

any update

from voice.

lfoliveir4 avatar lfoliveir4 commented on May 23, 2024 1

@MacKentoch Did you solved your problem?

from voice.

MacKentoch avatar MacKentoch commented on May 23, 2024 1

@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

from voice.

Doodidan avatar Doodidan commented on May 23, 2024 1

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.

from voice.

xavicolomer avatar xavicolomer commented on May 23, 2024

Any news on that @MacKentoch ?

I would also like to remove that sound.

from voice.

Noitidart avatar Noitidart commented on May 23, 2024

This would be a nice option.

from voice.

ohtangza avatar ohtangza commented on May 23, 2024

@ghsdh3409 Ping. Time to sync with upstream?

from voice.

alinematic avatar alinematic commented on May 23, 2024

have u been able to do that?

from voice.

dalvallana avatar dalvallana commented on May 23, 2024

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.

from voice.

roysG avatar roysG commented on May 23, 2024

any update?

from voice.

Saltan77 avatar Saltan77 commented on May 23, 2024

I also need such a function

from voice.

roysG avatar roysG commented on May 23, 2024

any Updateee?

from voice.

zombie6888 avatar zombie6888 commented on May 23, 2024

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

from voice.

Jonjoe avatar Jonjoe commented on May 23, 2024

bump

from voice.

phongbksneep avatar phongbksneep commented on May 23, 2024

wait this option

from voice.

Hirurgo avatar Hirurgo commented on May 23, 2024

any update?

from voice.

abhineetsharmathegreat avatar abhineetsharmathegreat commented on May 23, 2024

Any updates?

from voice.

erevos-13 avatar erevos-13 commented on May 23, 2024

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.

from voice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.