AudioRecorder for Android powered by Kotlin.
- Easy to use API
- Record on various format
- core: pcm, wav
- ffmpeg-recorder: mp3, m4a, wma, flac, aac
- Pause & Resume recording
- Integrated timer is provide
maxAvailableTime
feature - Remove background noise using NoiseSuppressor API
- 100% write in Kotlin, but has Java Compatible
- Detect amount of time of Silent
It distributed on JCenter, but sometime it's not available.
repositories {
maven { url "https://dl.bintray.com/windsekirun/maven/" }
}
Core module will contain most feature and two format. 'pcm' and 'wav'
implementation 'com.github.WindSekirun.NaraeAudioRecorder:core:1.3.0'
FFmpeg-Recorder will contain five format, 'mp3', 'm4a', 'wma', 'flac', 'aac'
This module will increase Final APK Size about 20MB. You can reduce APK Size by this guide
implementation 'nl.bravobit:android-ffmpeg:1.1.5'
implementation 'com.github.WindSekirun.NaraeAudioRecorder:ffmpeg-recorder:1.3.0'
val audioRecorder = NaraeAudioRecorder()
val destFile = File(Environment.getExternalStorageDirectory(), "/NaraeAudioRecorder/$fileName$extensions")
audioRecorder.create() {
this.destFile = destFile
}
Define instance of 'NaraeAudioRecorder' and create file and provide with NaraeAudioRecorder.create
is fine.
If you want use NoiseSuppressor, define instance of NoiseAudioSource
and provide with NaraeAudioRecorder.create
.
val recordConfig = AudioRecordConfig.defaultConfig()
val audioSource = NoiseAudioSource(recordConfig)
audioRecorder.create() {
this.destFile = this.destFile
this.recordConfig = recordConfig
this.audioSource = audioSource
}
This is full sample of 'initialization in Java'. other feature is same.
File destFile = new File(getContext().getExternalFilesDir(null) + String.format("/recorder/%s.mp3", fileName));
destFile.getParentFile().mkdirs();
mAudioRecorder.checkPermission(getContext());
mAudioRecorder.create(FFmpegRecordFinder.class, config -> {
config.setDestFile(destFile);
config.setDebugMode(true);
config.setTimerCountListener((currentTime, maxTime) -> {
});
return null;
});
FFmpegAudioRecorder ffmpegAudioRecorder = (FFmpegAudioRecorder) mAudioRecorder.getAudioRecorder();
ffmpegAudioRecorder.setContext(getContext());
ffmpegAudioRecorder.setOnConvertStateChangeListener(state -> {
if (state == FFmpegConvertState.SUCCESS) {
mRecordedPath = destFile.getPath();
}
});
Starting from 1.2.0, if permission isn't granted, NaraeAudioRecorder will throw RuntimeException.
- RECORD_AUDIO
- WRITE_EXTERNAL_STORAGE
- READ_EXTERNAL_STORAGE
So make sure grant proper permissions before using startRecording
function.
audioRecorder.startRecording(Context)
audioRecorder.stopRecording()
audioRecorder.pauseRecording()
audioRecorder.resumeRecording()
You can custom config of AudioRecord
with AudioRecordConfig
fun defaultConfig() = AudioRecordConfig(MediaRecorder.AudioSource.MIC,
AudioFormat.ENCODING_PCM_16BIT,
AudioFormat.CHANNEL_IN_MONO,
AudioConstants.FREQUENCY_44100)
audioRecorder.setOnRecordStateChangeListener(OnRecordStateChangeListener)
audioRecorder.create(FFmpegRecordFinder::class.java) {
...
this.maxAvailableMillis = TimeUnit.SECONDS.toMillis(20)
this.timerCountListener = { currentTime, maxTime -> }
}
If you want use accuracy, define refreshTimerMillis
in create
section will be help for you. Default is 50
.
Using FFmpeg-recorder will need some additional info.
audioRecorder.create(FFmpegRecordFinder::class.java) {
this.destFile = this.destFile
this.recordConfig = recordConfig
this.audioSource = audioSource
}
val ffmpegAudioRecorder: FFmpegAudioRecorder = audioRecorder.getAudioRecorder() as? FFmpegAudioRecorder ?: return
ffmpegAudioRecorder.setContext(this)
In parameters of create
, use FFmpegRecordFinder::class.java
to determine proper recorder with destFile
.
FFmpeg-recorder uses WavAudioRecorder
internally, recording in wav and convert them to desire format using FFmpeg command.
You can custom config of FFmpeg using this options.
ffmpegAudioRecorder.setConvertConfig(FFmpegConvertConfig)
Default value is fun defaultConfig() = FFmpegConvertConfig(bitRate = FFmpegBitRate.def, samplingRate = FFmpegSamplingRate.ORIGINAL, mono = true)
.
ffmpegAudioRecorder.setOnConvertStateChangeListener(OnConvertStateChangeListener)
Copyright 2019, WindSekirun (DongGil, Seo)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.