Nilsantos / react-native-screen-audio-recorder

MIT License
0 stars 1 forks source link

Tried the library but no device audio gets recorded #2

Open VincentLu91 opened 2 years ago

VincentLu91 commented 2 years ago

Tried:

I installed and imported the library in my InternalAudio component. However, I set up a ScreenAudioRecorder and it doesn't return any audio data from videos that I play on the device.

Code:

...
import ScreenAudioRecorder from 'react-native-screen-audio-recorder';
...
function InternalRecording(props) {
...
  const options = {
    sampleRate: 16000,
      channels: 1,
      bitsPerSample: 16,
      fileName: 'novo.wav',
      fromMic: false,
      saveFile: false,
      audioEmitInterval: 128000,
  };

...
  async function startTranscribing() {
    ScreenAudioRecorder.init(options);
    ....
   global.socket.onmessage = (message) => {
      console.log("Entering onmessage");
      console.log("onsocket message is: ", message);
      let msg = '';
      const res = JSON.parse(message.data);
      texts[res.audio_start] = res.text;
      const keys = Object.keys(texts);
      keys.sort((a, b) => a - b);
      for (const key of keys) {
        if (texts[key]) {
          msg += ` ${texts[key]}`;
        }
      }
      console.log("Leaving onmessage. msg is: ", msg);
      setTranscript(msg);
    };
   ...
    ScreenAudioRecorder.start();
    global.socket.onopen = () => {
      ScreenAudioRecorder.on('data', data => {
        if (global.socket) {
          global.socket.send(JSON.stringify({audio_data: data}));
        }
      })
    }
...
ScreenAudioRecorder.stop();
...

Android version is version 10 on my device.

React Native version is 0.63.

Nilsantos commented 2 years ago

ScreenAudioRecorder.on('data', data => {

Are you sure the global.socket is not null? Did you try putting a log right after "ScreenAudioRecorder.on('data', date => {" to see if something is returned?

VincentLu91 commented 2 years ago

nothing's returned. First I was prompted to allow casting/recording and I confirmed yes. But the console.log doesn't run.

Nilsantos commented 2 years ago

Try somenting like this:

...

ScreenAudioRecorder.on('data', data => {
    console.log(data);
    if (global.socket) {
        global.socket.send(JSON.stringify({audio_data: data}));
    }
})

global.socket.onopen = () => {
   console.log('start');
   ScreenAudioRecorder.start();
}

...

VincentLu91 commented 2 years ago

Still nothing

VincentLu91 commented 2 years ago

Hi @Nilsantos . Any other suggestions or ideas?

niembro64 commented 1 year ago

This library doesn't work? Been trying it for a few hours now.

(EDIT) I tried the demo and it works just fine! I just need to figure out how I'm using it wrong! 🍔

Nilsantos commented 1 year ago

@niembro64 yes, the library works. Could you share the error that appeared? I'm not updating this library anymore, but I'll try to fix the problems.

niembro64 commented 1 year ago

Hi @Nilsantos how exactly are you accomplishing this? Which android MediaRecorder.AudioSource are you using when it's not recording from the mic? REMOTE_SUBMIX seems to be what's needed but it seems to require special permissions?

https://developer.android.com/reference/android/media/MediaRecorder.AudioSource

I'm making an app that's heavily dependent on this stuff so any insight is helpful!

Nilsantos commented 1 year ago

@niembro64, you can see the android source code here https://github.com/Nilsantos/react-native-screen-audio-recorder/tree/master/android/src/main/java/com/reactnativescreenaudiorecorder.

But is an error appearing when you try to use the library in react native? If you can share what's going on maybe I can fix it

niembro64 commented 1 year ago

@Nilsantos I appreciate the responses.

To be clear, I have tried your demo app and it works as intended!

I am curious how this is getting accomplished i.e. which audio source number you are using in android for capturing audio output from the phone?

Here's a snapshot of your Java code: image

I see you are using VOICE_RECOGNITION (6) when fromMic but I can't understand what audio source is being used when not fromMic?

niembro64 commented 1 year ago

@Nilsantos I realized what my issue is -> I'm using two libraries that both us the same parent library / underlying java methods.

Some issues noticed when using together:

Appreciate any insight you might have! Eric