React-Native | Home | Useful Links | Custom Module Tutorial
The purpose of this module is to take an array of int16 data from javascript, and create a .wav file from that data, on Android and iOS devices natively. This module is essentially suppose to provide a sink when working with the react-native-recording
module (https://www.npmjs.com/package/react-native-recording). More information can be found on the projects respective github homepage page -> https://github.com/qiuxiang/react-native-recording#readme...
- To install, run
npm install rnsaveaudio
- Edit
/android/settings.gradle
and add the following lines...
include ':rnsaveaudio'
project(':rnsaveaudio').projectDir = new File(rootProject.projectDir, '../node_modules/rnsaveaudio/android')
- Edit
/android/app/build.gradle
and add the following line inside ofdependencies
...
compile project(':rnsaveaudio')
- Edit
/android/app/src/main/java/.../MainApplication.java
with the follow lines...
- Import the module at the top of the file
import com.navraj.rnsaveaudio.RNSaveAudioPackage;
- Instantiate the package inside of the
getPackages()
method
new RNSaveAudioPackage()
- run the command
cd android && gradlew clean && cd ../
for windows, orcd android && ./gradlew clean && cd ../
for OSX, inside the root directory of your react-native project
- Open your xCode project and add the
RNSaveAudio.xcodeproj
file to your project - Go to your project's build phases, and add the
libRNSaveAudio.a
file to the list labeledLink Binary With Libraries
, using the+
under the list
- If you get an error saying xCode cannot find
<RCTEventEmitter.h>
, openRNSaveAudio.h
inside of theios
project folder, and change the the header to<React/RCTEventEmitter.h>
- For more information, look at https://github.com/maxs15/react-native-spinkit/wiki/Manual-linking---IOS
- Version 1.0.6 is current
- Works on Android and iOS (Tested)
- Sends a promise when complete
- Creates a .wav file based on an array of signed short (SInt16) values at a frequency of 44.1kHz (mono)
- Meant to work with react-native-recording node package and react-native-fs package
- Import the module using
import RNSaveAudio from 'rnsaveaudio';
- Export audio using
RNsaveAudio.saveWav(PATH+'/filename.wav',dataArray);
- Make sure to include the keywords
await
andasync
if used inside of a function, eg.async func(prop){ const variable = await RNsaveAudio.saveWav(PATH+'/filename.wav',dataArray); }
- My email is
nkambo1@my.bcit.ca
, use the module name in the subject line. - Submit an issue to the github page. http://github.com/navrajkambo/RNSaveAudio/issues
- If someone would like to add methods for exporting stereo wav files, or files of other formats and sampling frequencies from signed short arrays, feel free to create a PR, it would be useful to have
- If you feel like contributing, send me a message or open an issue! Any help is appreciated :)
- For more information on bridging native modules to react-native, have a look at https://gist.github.com/chourobin/f83f3b3a6fd2053fad29fff69524f91c, https://eastcodes.com/packaging-and-sharing-react-native-modules, and http://matthewsessions.com/2017/10/27/developing-rn-module.html. They are very informative!