Mithronn / react-native-real-time-audio-stream

MIT License
3 stars 0 forks source link

[Help] Save opus_data and open in another machine #1

Open Artotim opened 9 months ago

Artotim commented 9 months ago

Hello, I'm trying to use this package to save audio in real time. What I'm trying to do is to save the opus_data from the data event and try to load it elsewhere. But I'm not being able to read it with any player, ffmpeg also throws an error.

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

So how can one save the contents from data in a file to be listened to later?

Mithronn commented 9 months ago

Hi, first of all, this package currently only works on Android. If you try to get voice data from IOS it only returns not opus converted data and you can save it to WAV format.

Artotim commented 9 months ago

Hello @Mithronn, thanks for the answer. About saving raw data I've been trying to append Wav headers to it and save, but without success. But for the opus converted data in android, can i save it and read it outside Android?

Mithronn commented 9 months ago

Base64 encoded raw_data needs to be decoded before appending WAV headers. The opus data can be used similarly to raw_data after decoding.

RNRealTimeAudioStream.on("data", data => {
    RNFS.writeFile(`${ExternalCachesDirectoryPath}/test-audio-opus-${new Date().getTime()}`, Buffer.from(data.opus_data, 'base64'))
          .then(() => console.log("wrote"))
          .catch(err => console.log(err));
});