Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reduce the size to 5.17 KiB/s? #29

Open
jasonrichdarmawan opened this issue Dec 22, 2020 · 0 comments
Open

How to reduce the size to 5.17 KiB/s? #29

jasonrichdarmawan opened this issue Dec 22, 2020 · 0 comments

Comments

@jasonrichdarmawan
Copy link

jasonrichdarmawan commented Dec 22, 2020

The issue

My goal is to send a data array with size 5.17 KiB/s to a WebSocket.

I have not tried it yet, currently I tried to save the audio to a file. I use RNSaveAudio to save the audio file. I also use react-native-fs to get the app's folder path.

My expected result is the file should be around 5 - 6 kB for 1 seconds of audio.

My actual result is: 8236 bytes for 93 milliseconds (roughly 0,093 seconds) of audio. I tried to change the sampleRate to 8000. I found the data size to be 2 - 3 times larger compared to Opus Voice with bit rate 5.17 KiB/s and sampling rate 8 kHz.

TL:DR

Steps to reproduce:

  1. Add listener
  let audioInt16: number[] = [];
  let listener;

  React.useEffect(() => {
    // eslint-disable-next-line react-hooks/exhaustive-deps
    listener = Recording.addRecordingEventListener((data: number[]) => {
      console.log('record', data.length);
      // eslint-disable-next-line react-hooks/exhaustive-deps
      audioInt16 = audioInt16.concat(data);
    });

    return () => {
      listener.remove();
    };
  });
  1. Record audio
  const startAsync = async () => {
    await PermissionsAndroid.requestMultiple([
      PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
    ]);

    Recording.init({
      bufferSize: 4096,
      sampleRate: 44100,
      bitsPerChannel: 16,
      channelsPerFrame: 1,
    });

    Recording.start();
  };
  1. Save audio
  const saveAudio = async () => {
    const promise = await RNSaveAudio.saveWav(path, audioInt16);
    console.log('save audio', promise, path);
  };
  1. Play audio
  const playAudio = () => {
    if (player.canPrepare || player.canPlay) {
      player.prepare((err) => {
        if (err) {
          console.log(err);
        }
        console.log('play audio', player.duration);
        player.play();
      });
    }
  };
@jasonrichdarmawan jasonrichdarmawan changed the title How to reduce the size to 8 bytes/s? How to reduce the size to 5.17 KiB/s? Dec 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant