xiqi / react-native-live-audio-stream

Get live audio stream data for React Native (works for iOS and Android)
MIT License
71 stars 29 forks source link

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

Open theInfiTualEr opened 9 months ago

theInfiTualEr commented 9 months ago
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 commented 9 months ago

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 commented 9 months ago

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.

Artotim commented 5 months ago

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?

theInfiTualEr commented 5 months ago

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