qiuxiang / react-native-recording

React Native audio recording module used for DSP with Android + iOS
MIT License
110 stars 62 forks source link

One more listener runs and its callback returns always zeros #26

Closed nwatab closed 3 years ago

nwatab commented 3 years ago

I ran below code and set listener callback is called every 2.5 seconds. Strangely, two lister callbacks are called and one of which always returns zeros. Does anyone know this situation and solution? I ran android physical device connected to MacOS via USB cable.

import React, {useEffect} from 'react';
import {PermissionsAndroid, Text} from 'react-native';

import Recording from 'react-native-recording';

const App = () => {
  const requestPermission = async () => {
    await PermissionsAndroid.requestMultiple([
      PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
    ]);
  };
  requestPermission();

  Recording.init({
    bufferSize: 24000 * 2.5,
    sampleRate: 24000,
    bitsPerChannel: 16,
    channelsPerFrame: 1,
  });

  useEffect(() => {
    console.log('start effect');
    const listener = Recording.addRecordingEventListener((data: number[]) => {
      console.log(data.slice(0, 100));

    Recording.start();
    return () => {
      console.log('clean up');
      Recording.stop();
      listener.remove();
    };
  }, []);

  return (<Text>aaa</Text>)

Standard output from terminal

[Tue Oct 20 2020 17:32:37.599]  LOG      start effect
[Tue Oct 20 2020 17:32:39.439]  LOG      [17, 3, 11, 46, 3, -13, 9, -4, -9, -10, -19, -39, -22, -27, -48, -48, -57, -27, -14, -40, -14, 18, -9, 8, -5, -19, 6, -25, -9, 18, 22, 32, 75, 82, 46, 46, 17, 4, -26, -40, -41, -83, -60, -105, -119, -111, -127, -104, -145, -134, -101, -107, -128, -154, -175, -160, -140, -154, -121, -107, -141, -117, -99, -152, -142, -138, -160, -139, -144, -144, -126, -124, -138, -116, -134, -122, -93, -121, -102, -110, -123, -105, -133, -188, -141, -156, -189, -142, -158, -105, -93, -134, -118, -135, -152, -108, -95, -106, -72, -104]
[Tue Oct 20 2020 17:32:40.333]  LOG      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[Tue Oct 20 2020 17:32:41.936]  LOG      [47, 15, 29, 35, 4, 14, 35, 40, 34, 39, 35, 25, 59, 77, 57, 51, 54, 35, 34, 43, 21, 33, 47, 48, 50, 65, 86, 110, 134, 136, 136, 142, 164, 163, 141, 120, 91, 72, 74, 50, 37, 64, 58, 50, 71, 81, 72, 55, 43, 40, 18, -7, 1, -26, -48, -24, -60, -69, -62, -85, -80, -80, -93, -105, -108, -125, -126, -126, -124, -118, -146, -157, -134, -140, -117, -118, -124, -80, -117, -87, -83, -128, -101, -139, -142, -125, -138, -132, -140, -135, -129, -120, -97, -85, -80, -92, -88, -113, -129, -86]
[Tue Oct 20 2020 17:32:42.781]  LOG      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[Tue Oct 20 2020 17:32:44.407]  LOG      [35, 49, 49, 7, 15, 43, 23, 24, 47, 72, 103, 98, 91, 96, 72, 74, 102, 90, 84, 103, 95, 126, 136, 120, 144, 122, 107, 110, 96, 93, 100, 91, 76, 77, 71, 81, 76, 48, 37, 44, 48, 56, 56, 65, 66, 61, 81, 69, 66, 62, 34, 20, -6, -12, -6, 0, 7, 12, 50, 65, 93, 99, 127, 143, 115, 104, 77, 94, 73, 91, 101, 69, 114, 121, 113, 143, 165, 132, 166, 169, 115, 135, 111, 83, 70, 43, 4, 24, 44, 28, 44, 34, 35, 60, 48, 21, 25, 10, -17, 7]
[Tue Oct 20 2020 17:32:45.444]  LOG      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[Tue Oct 20 2020 17:32:46.957]  LOG      [-10, -6, -32, -37, -50, -48, -54, -69, -38, -35, -21, -15, -7, -6, 0, -8, -34, -13, -12, -10, -19, -36, -16, -10, -7, -1, -25, 1, 15, 23, 44, 20, 35, 34, 34, 13, -2, 36, 40, 69, 89, 77, 76, 93, 84, 58, 58, 40, 36, 44, 53, 87, 95, 109, 139, 140, 148, 139, 132, 121, 110, 110, 101, 106, 114, 148, 167, 176, 187, 199, 195, 166, 182, 174, 172, 191, 180, 202, 224, 209, 209, 197, 207, 214, 194, 232, 216, 204, 203, 172, 187, 211, 196, 206, 251, 235, 243, 260, 247, 249]
[Tue Oct 20 2020 17:32:47.837]  LOG      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[Tue Oct 20 2020 17:32:49.432]  LOG      [-197, -168, -208, -172, -179, -190, -146, -163, -143, -144, -189, -177, -163, -201, -184, -142, -125, -109, -95, -86, -108, -119, -141, -148, -131, -114, -95, -59, -32, -32, -27, -11, -24, -46, -29, -35, -20, -18, -21, 10, 15, 18, 44, 58, 40, 71, 73, 69, 87, 84, 101, 75, 88, 99, 85, 96, 87, 78, 82, 93, 70, 109, 124, 68, 78, 53, 34, 74, 51, 38, 71, 65, 47, 63, 35, 22, 46, 14, 17, 18, 28, 9, -12, 23, -11, -24, 26, 17, 11, 40, 28, 0, -3, -5, -42, -11, -13, -28, -7, -28]
[Tue Oct 20 2020 17:32:50.288]  LOG      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Dependency

"react": "16.13.1",
"react-native": "0.63.3",
"react-native-recording": "^0.5.1"
nwatab commented 3 years ago

I can't reproduce.