when the user clicks the button, The app should start listening the audio and stop the recording when the user is silent(say for 20 seconds after silence) , now store that audio file in a wave format(eg: test.wav) in react native ?
Asked
Active
Viewed 1.1k times
3
-
1The beauty of RN is that there are LOADS of packages made for it. This is one for audio recording and I'm sure there are more: https://github.com/jsierles/react-native-audio – scgough Nov 29 '19 at 11:13
-
react-native-audio record and react-native-audio , is there any other thing? – Ravikiran kallepally Nov 29 '19 at 13:20
2 Answers
1
As you already know that there is no inbuilt feature to record audio in React Native, However you can always use third part Library/package. There are number of them available on NPM. Here is one of them react native audio record
import AudioRecord from 'react-native-audio-record';
const options = {
sampleRate: 16000, // default 44100
channels: 1, // 1 or 2, default 1
bitsPerSample: 16, // 8 or 16, default 16
audioSource: 6, // android only
wavFile: 'test.wav' // default 'audio.wav'
};
AudioRecord.init(options);
//Start Recording
AudioRecord.start();
//Stop Recording
AudioRecord.stop();
Hope this help

Hadi Mir
- 4,497
- 2
- 29
- 31
1
If you are also interested in creating file from this recording in the user device, i recommend using react-native-audio i personally tried in android and it worked pretty smoothly, example of code:
/* on top of component:*/
import {AudioRecorder, AudioUtils} from 'react-native-audio';
/*all your other imports*/
class Example extends Component {
constructor(props) {
super(props);
this.AudioRecorder = AudioRecorder
}
startRecord(){
let folder = AudioUtils.DocumentDirectoryPath;
let audioPath = folder +'/myFile.wav';
let options= { SampleRate: 22050,
Channels: 1,
AudioQuality: "Low",
AudioEncoding: "wav",
MeteringEnabled: true,};
this.AudioRecorder.prepareRecordingAtPath(audioPath,options).then(
((success)=>{ this.AudioRecorder.startRecording((success)=>{
}).catch((err)=>{})
}).catch(err=>{})
}
stopRecord(){
this.audioRecorder.stop()
}
}
you will probably also need user permission to use the device microphone, for this i recommend react-native-permissions

user8376713
- 397
- 3
- 5
-
TypeError: undefined is not an object (evaluating 'this.AudioRecorder') – Narendra Singh Jul 24 '20 at 12:33
-
@NarendraSingh , maybe there is a problem with your import or npm installation of the package, i recreated this error when import undefined object from react-native audio. – user8376713 Jul 26 '20 at 07:08
-
1@NarendraSingh The library linked in this answer is no longer maintained. Has been updated in years. Probably not usable right now. – ahron Dec 09 '21 at 18:00