Android Wave Recorder

A powerful and efficient library to record WAVE form audio files (WAV) in Android.

Android Wave Recorder is a lightweight library written in Kotlin to record audio files with WAVE (WAV due to its filename extension) format in Android. It's very memory efficient and easy to use library with recording customizations.

Download

Step 1. Add this in your root (Project) build.gradle at the end of repositories:

allprojects {
        repositories {
            ...
            maven { url "https://jitpack.io" }
        }
    }

Step 2. Add the dependency

dependencies{
    implementation 'com.github.squti:Android-Wave-Recorder:1.2.0'
}

Permission

Add these permissions into your AndroidManifest.xml and request for them in Android 6.0+

<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Usage

Pass in the path of the output file to WaveRecorder class and call startRecording() like this:

/**
 * This path points to application cache directory.
 * you could change it based on your usage
 */
val filePath:String = externalCacheDir?.absolutePath + "/audioFile.wav"

val waveRecorder = WaveRecorder(filePath)
waveRecorder.startRecording()

To stop recording call stopRecording() function:

waveRecorder.stopRecording()

To listen to audio amplitude during recording you need to register a listener to onAmplitudeListener:

waveRecorder.onAmplitudeListener = {
    Log.i(TAG, "Amplitude : $it")
}

Configuration

The default configuration for recording audio is like so:

Property Value
sampleRate 16000
channels AudioFormat.CHANNEL_IN_MONO
audioEncoding AudioFormat.ENCODING_PCM_16BIT

But you could change it using waveConfig property in WaveRecorder class based on your usage. This is an example:

val waveRecorder = WaveRecorder(filePath)
waveRecorder.waveConfig.sampleRate = 44100
waveRecorder.waveConfig.channels = AudioFormat.CHANNEL_IN_STEREO
waveRecorder.waveConfig.audioEncoding = AudioFormat.ENCODING_PCM_8BIT
waveRecorder.startRecording()

Note: Wrong configuration may impacts output quality

GitHub