Search code examples
react-nativemicrophonevoice

React Native - Microphone voice waves


I am currently implementing an audio recorder in the app I am working on. Everything works great, but I cannot find a way to capture the sound waves of the microphone, which would make the app look even better. Do any one of you guys know a library that I could use, or a Native solution to find these values? I can make the animations myself.


Solution

  • The solution is very easy, there is a library called hark which can help you to listen to audio streams and emit events (speaking / not speaking)

    Here is the library link with NPM: https://www.npmjs.com/package/hark

    Example:

    import hark from 'hark';
    
    var speech = hark(stream, options); // stream is the sound coming from user's mic
    speech.on('speaking', function() {
       setSpeaking(true);
    });
    
    speechEvents.on('stopped_speaking', function() {
      setSpeaking(false);
    });