kevinresol / react-native-sound-recorder

Simplest Sound Recorder for React Native
MIT License
119 stars 36 forks source link

options being ignored #25

Closed alehel closed 4 years ago

alehel commented 5 years ago

I have an app which records environmental sounds and uploads them to an S3 bucket on AWS. I'm trying to set the options for the sound recording, but the options object seems to have no affect on the output file. The code I have for performing the recording is as follow.

function recordSound(time = 10) {
    const timeToRecord = time * 1000;

    const options = {
        channels: 1,
        sampleRate: 16000,
        bitRate: 128
    }

    return new Promise(function(resolve) {
        SoundRecorder.start(SoundRecorder.PATH_CACHE + '/environmental_audio.mp4', options).then(function() {
            if(__DEV__) console.log("AUDIO RECORDING: STARTED");
        })

        setTimeout(function() {
            SoundRecorder.stop().then(function(result) {
                if(__DEV__) console.log("AUDIO RECORDING: COMPLETE");
                resolve(result);
            })
        }, timeToRecord)
    });
}

The result is an AAC file at 8000 Hz with, according to QuickTime, a bitrate of 12,8 kbps. Am I defining the options object incorrectly? Am I applying it to the wrong function?

kevinresol commented 5 years ago

This library simply forwards the options to the MediaRecorder:

https://github.com/kevinresol/react-native-sound-recorder/blob/904356096ef1620e2b43ffa0fe65973ef05ebe4c/android/src/main/java/com/kevinresol/react_native_sound_recorder/RNSoundRecorderModule.java#L81-L114

alehel commented 5 years ago

Hmm, strange. Even when I don't supply an options object, I still don't get the "default" values from the Android code you posted. It states a bitrate of 64000 (64 kbs), but I'm getting much lower than that. More like 5kbs according to the program MediaInfo. I'll try a different phone and see if it affects anything. For some reason selecting 4 for format which according to googles docs is AAC_HE (https://developer.android.com/reference/kotlin/android/media/MediaRecorder.AudioEncoder#AAC:kotlin.Int) causes the app to crash, despite that 4 is supposed to be supported since API 16. So perhaps this is an issue with my phone specifically rather than the code.

By the way. The readme specifies that the option property for bitrate is called bitRate, but based on the Java code on line 27 in the file RNSoundRecorderModule.java it seems like it is supposed to be encodingBitRate. Is this an error in the Readme?

kevinresol commented 5 years ago

it seems like it is supposed to be encodingBitRate. Is this an error in the Readme?

yeah looks like an oversight

alehel commented 5 years ago

Ok, thanks. I'll update here if I figure out what the issue is.

Nice work on the package by the way, its made my life easier 👍

cark1 commented 4 years ago

Probably we can close this issue. We have 2 ways: