Skip to content

A lightweight audio recording library which records in .wav format

License

Notifications You must be signed in to change notification settings

thedroiddiv/RawAudioRecorder

 
 

Repository files navigation

RawAudioRecorder


API Kotlin

A lightweight audio recording library that records in .wav format

Gradle

Kotlin: build.gradle.kts

dependencies {
  implementation("com.github.karya-inc:rawaudiorecorder:<latest_release>")
}

Groovy: build.gradle

dependencies {
  implementation 'com.github.karya-inc:rawaudiorecorder:<latest_release>'
}

Usage

Create an instance of RecorderEventListener

private val listener = object : RecorderEventListener {
        override fun onPause() {}
        override fun onResume() {}

        override fun onPrepared() {
           
        }

        // maxAmplitude: Maximum amplitude in current chunk, duration: Time elapses in seconds
        override fun onProgressUpdate(maxAmplitude: Int, duration: Long) {
            
        }

        override fun onStart() {
           
        }

        // durationMs: duration of the recorded file in milliseconds
        override fun onStop(durationMs: Long) {
           
        }
    }

Create an instance of RawAudioRecorder. RawAudioRecoder needs a CoroutineScope, which can be lifecyclsScope if you're creating it inside Activity or preferably viewModelScope when using in an MVVM project.

val recorder = RawAudioRecorder(listener, viewModelScope)

Prepare the recorder

 recorder.prepare(filePath = audioFilepath, config = RecorderConfig(), suppressNoise = true)

Start the recording

recorder.startRecording()

Available interactions

// Pause
recorder.pauseRecording()
// Resume
recorder.resumeRecording()
// Stop
recorder.stopRecording()

Available Configurations

data class RecorderConfig(
    var sampleRate: SampleRate = SampleRate._16_K,
    var channels: Int = AudioFormat.CHANNEL_IN_MONO,
    var audioEncoding: AudioEncoding = AudioEncoding.PCM_16BIT
)
Configuration Available values
sampleRate SampleRate._8_K (8Khz)
SampleRate._16_K (16Khz)
SampleRate._44_K (44.1Khz)
audioEncoding AudioEncoding.PCM_8BIT
AudioEncoding.PCM_16BIT
AudioEncoding.PCM_32BIT, required 'sdk >= Build.VERSION_CODES.S'
channels AudioFormat.CHANNEL_IN_MONO, other configurations from android.media.AudioFormat

Sample App

Checkout the sample App for reference

sample2 sample1

About

A lightweight audio recording library which records in .wav format

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 100.0%