react-native-live-audio-stream icon indicating copy to clipboard operation
react-native-live-audio-stream copied to clipboard

[help] How to play the received data on "data" emit?

Open theInfiTualEr opened this issue 1 year ago • 4 comments

LiveAudioStream.on("data", (data) => {
  // play the data as audio
});

I want to use this in socket, hence I don't want to export an audio file, and just want to play whatever I receive.

theInfiTualEr avatar Sep 20 '23 10:09 theInfiTualEr

I figured out I should play the data using AudioTrack from Android API, so I created a fork and added couple of functionalities. Check it out here: https://github.com/xiqi/react-native-live-audio-stream/pull/26

I still don't know (and don't need to) play the data on iOS.

theInfiTualEr avatar Sep 24 '23 10:09 theInfiTualEr

https://github.com/theInfiTualEr/react-native-live-audio-stream/ also addresses playing the audio recorded in Android on Web (It generates wav audio header). Still, no iOS support.

theInfiTualEr avatar Oct 04 '23 19:10 theInfiTualEr

Hello @theInfiTualEr, I'm using your version and it works fine, i can read the data with the header and play it using LiveAudioStream.addPlay. However I also would like to store this data to be read elsewhere, but when I do this I can't manage to open the stored file in any player, ffmpeg also gives an error.

This is how I store the data:

LiveAudioStream.on("data", data => {
    RNFS.writeFile(`${ExternalCachesDirectoryPath}/test-audio-{new Date().getDate()}.wav`, data)
        .then(() => console.log("wrote"))
        .catch(err => console.log(err));
});

Do you happen to have any idea how one could store the contents from data and play it in other machines?

Artotim avatar Feb 02 '24 03:02 Artotim

Do you happen to have any idea how one could store the contents from data and play it in other machines?

Checkout https://github.com/goodatlas/react-native-audio-record

theInfiTualEr avatar Feb 03 '24 07:02 theInfiTualEr